DarkflameServer/dScripts/02_server/Map/NS/NsConcertChoiceBuildManager.cpp
David Markowitz fc75d6048f
dGame Precompiled header improvements (#876)
* moving branch

* Add deleteinven slash command

* Change name of BRICKS_IN_BBB

* Use string_view instead of strcmp

* Clean up include tree

* Remove unneeded headers from PCH files

Removes unneeded headers from pre-compiled headers.  This increases compile time, however reduces development time for most files.

* Update Entity.h

* Update EntityManager.h

* Update GameMessages.cpp

* There it compiles now

Co-authored-by: Aaron Kimbrell <aronwk.aaron@gmail.com>
2023-01-06 23:17:05 -06:00

66 lines
2.2 KiB
C++

#include "NsConcertChoiceBuildManager.h"
#include "EntityInfo.h"
#include "EntityManager.h"
const std::vector<Crate> NsConcertChoiceBuildManager::crates{
{ "laser", 11203, 5.0, "Concert_Laser_QB_" },
{ "rocket", 11204, 3.0, "Concert_Rocket_QB_" },
{ "speaker", 11205, 5.0, "Concert_Speaker_QB_" },
{ "spotlight", 11206, 5.0, "Concert_Spotlight_QB_" }
};
void NsConcertChoiceBuildManager::OnStartup(Entity* self) {
NsConcertChoiceBuildManager::SpawnCrate(self);
}
void NsConcertChoiceBuildManager::SpawnCrate(Entity* self) {
const auto spawnNumber = self->GetVar<uint32_t>(u"spawnNumber") % crates.size();
const auto crate = crates[spawnNumber];
const auto groups = self->GetGroups();
if (groups.empty())
return;
// Groups are of the form CB_1, CB_2, etc.
auto group = groups.at(0);
const auto splitGroup = GeneralUtils::SplitString(group, '_');
if (splitGroup.size() < 2)
return;
const auto groupNumber = std::stoi(splitGroup.at(1));
EntityInfo info{};
info.lot = crate.lot;
info.pos = self->GetPosition();
info.rot = self->GetRotation();
info.spawnerID = self->GetObjectID();
info.settings = {
new LDFData<bool>(u"startsQBActivator", true),
new LDFData<std::string>(u"grpNameQBShowBricks", crate.group + std::to_string(groupNumber)),
new LDFData<std::u16string>(u"groupID", GeneralUtils::ASCIIToUTF16("Crate_" + group)),
new LDFData<float>(u"crateTime", crate.time),
};
auto* spawnedCrate = EntityManager::Instance()->CreateEntity(info);
EntityManager::Instance()->ConstructEntity(spawnedCrate);
spawnedCrate->AddDieCallback([self]() {
self->CancelAllTimers(); // Don't switch if the crate was smashed
self->SetVar<LWOOBJID>(u"currentCrate", LWOOBJID_EMPTY);
});
self->SetVar<uint32_t>(u"spawnNumber", spawnNumber + 1);
self->SetVar<float>(u"currentTimer", crate.time);
self->SetVar<LWOOBJID>(u"currentCrate", spawnedCrate->GetObjectID());
// Timer that rotates the crates
self->AddCallbackTimer(crate.time, [self]() {
auto crateID = self->GetVar<LWOOBJID>(u"currentCrate");
if (crateID != LWOOBJID_EMPTY) {
EntityManager::Instance()->DestroyEntity(crateID);
self->SetVar<LWOOBJID>(u"currentCrate", LWOOBJID_EMPTY);
}
SpawnCrate(self);
});
}