mirror of https://github.com/AxioDL/metaforce.git
CScriptGenerator: Brace conditionals where applicable
This commit is contained in:
parent
bea6709cc4
commit
51ffc0ef26
|
@ -23,98 +23,114 @@ void CScriptGenerator::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
||||||
void CScriptGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& stateMgr) {
|
void CScriptGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& stateMgr) {
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
case EScriptObjectMessage::SetToZero: {
|
case EScriptObjectMessage::SetToZero: {
|
||||||
if (!GetActive())
|
if (!GetActive()) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<TUniqueId> follows;
|
std::vector<TUniqueId> follows;
|
||||||
follows.reserve(x20_conns.size());
|
follows.reserve(x20_conns.size());
|
||||||
for (const SConnection& conn : x20_conns) {
|
for (const SConnection& conn : x20_conns) {
|
||||||
if (conn.x0_state != EScriptObjectState::Zero || conn.x4_msg != EScriptObjectMessage::Follow)
|
if (conn.x0_state != EScriptObjectState::Zero || conn.x4_msg != EScriptObjectMessage::Follow) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
TUniqueId uid = stateMgr.GetIdForScript(conn.x8_objId);
|
|
||||||
if (stateMgr.GetObjectById(uid) != nullptr)
|
|
||||||
follows.push_back(uid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (follows.empty())
|
const TUniqueId uid = stateMgr.GetIdForScript(conn.x8_objId);
|
||||||
|
if (stateMgr.GetObjectById(uid) != nullptr) {
|
||||||
|
follows.push_back(uid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (follows.empty()) {
|
||||||
follows.push_back(sender);
|
follows.push_back(sender);
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::pair<TUniqueId, TEditorId>> activates;
|
std::vector<std::pair<TUniqueId, TEditorId>> activates;
|
||||||
activates.reserve(x20_conns.size());
|
activates.reserve(x20_conns.size());
|
||||||
|
|
||||||
for (const SConnection& conn : x20_conns) {
|
for (const SConnection& conn : x20_conns) {
|
||||||
if (conn.x0_state != EScriptObjectState::Zero)
|
if (conn.x0_state != EScriptObjectState::Zero) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
TUniqueId uid = stateMgr.GetIdForScript(conn.x8_objId);
|
TUniqueId uid = stateMgr.GetIdForScript(conn.x8_objId);
|
||||||
if (uid == kInvalidUniqueId)
|
if (uid == kInvalidUniqueId) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if (conn.x4_msg == EScriptObjectMessage::Activate) {
|
if (conn.x4_msg == EScriptObjectMessage::Activate) {
|
||||||
if (!stateMgr.GetObjectById(uid))
|
if (!stateMgr.GetObjectById(uid)) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
activates.emplace_back(uid, conn.x8_objId);
|
activates.emplace_back(uid, conn.x8_objId);
|
||||||
} else {
|
} else {
|
||||||
stateMgr.SendScriptMsgAlways(uid, GetUniqueId(), conn.x4_msg);
|
stateMgr.SendScriptMsgAlways(uid, GetUniqueId(), conn.x4_msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (activates.empty())
|
if (activates.empty()) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
for (u32 i = 0; i < x34_spawnCount; ++i) {
|
for (u32 i = 0; i < x34_spawnCount; ++i) {
|
||||||
if (activates.size() == 0 || follows.size() == 0)
|
if (activates.size() == 0 || follows.size() == 0) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
u32 activatesRand = 0.99f * (stateMgr.GetActiveRandom()->Float() * activates.size());
|
u32 activatesRand = 0.99f * (stateMgr.GetActiveRandom()->Float() * activates.size());
|
||||||
u32 followsRand = 0.99f * (stateMgr.GetActiveRandom()->Float() * follows.size());
|
const u32 followsRand = 0.99f * (stateMgr.GetActiveRandom()->Float() * follows.size());
|
||||||
|
|
||||||
for (u32 j = 0; j < activates.size(); ++j)
|
for (u32 j = 0; j < activates.size(); ++j) {
|
||||||
if (TCastToConstPtr<CScriptSound>(stateMgr.GetObjectById(activates[j].first)))
|
if (TCastToConstPtr<CScriptSound>(stateMgr.GetObjectById(activates[j].first))) {
|
||||||
activatesRand = j;
|
activatesRand = j;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::pair<TUniqueId, TEditorId> idPair = activates[activatesRand];
|
const std::pair<TUniqueId, TEditorId> idPair = activates[activatesRand];
|
||||||
CEntity* activate = stateMgr.ObjectById(idPair.first);
|
CEntity* activate = stateMgr.ObjectById(idPair.first);
|
||||||
CEntity* follow = stateMgr.ObjectById(follows[followsRand]);
|
CEntity* follow = stateMgr.ObjectById(follows[followsRand]);
|
||||||
|
|
||||||
if (!activate || !follow)
|
if (!activate || !follow) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
bool oldGeneratingObject = stateMgr.GetIsGeneratingObject();
|
const bool oldGeneratingObject = stateMgr.GetIsGeneratingObject();
|
||||||
stateMgr.SetIsGeneratingObject(true);
|
stateMgr.SetIsGeneratingObject(true);
|
||||||
std::pair<TEditorId, TUniqueId> objId = stateMgr.GenerateObject(idPair.second);
|
const std::pair<TEditorId, TUniqueId> objId = stateMgr.GenerateObject(idPair.second);
|
||||||
stateMgr.SetIsGeneratingObject(oldGeneratingObject);
|
stateMgr.SetIsGeneratingObject(oldGeneratingObject);
|
||||||
|
|
||||||
if (objId.second != kInvalidUniqueId) {
|
if (objId.second != kInvalidUniqueId) {
|
||||||
if (CEntity* genObj = stateMgr.ObjectById(objId.second)) {
|
if (CEntity* genObj = stateMgr.ObjectById(objId.second)) {
|
||||||
TCastToPtr<CActor> activateActor(genObj);
|
const TCastToPtr<CActor> activateActor(genObj);
|
||||||
TCastToPtr<CActor> followActor(follow);
|
const TCastToConstPtr<CActor> followActor(follow);
|
||||||
TCastToPtr<CWallCrawlerSwarm> wallCrawlerSwarm(follow);
|
const TCastToConstPtr<CWallCrawlerSwarm> wallCrawlerSwarm(follow);
|
||||||
|
|
||||||
if (activateActor && wallCrawlerSwarm) {
|
if (activateActor && wallCrawlerSwarm) {
|
||||||
if (!x38_25_noInheritTransform)
|
if (!x38_25_noInheritTransform) {
|
||||||
activateActor->SetTransform(wallCrawlerSwarm->GetTransform());
|
activateActor->SetTransform(wallCrawlerSwarm->GetTransform());
|
||||||
|
}
|
||||||
activateActor->SetTranslation(wallCrawlerSwarm->GetLastKilledOffset() + x3c_offset);
|
activateActor->SetTranslation(wallCrawlerSwarm->GetLastKilledOffset() + x3c_offset);
|
||||||
} else if (activateActor && followActor) {
|
} else if (activateActor && followActor) {
|
||||||
if (!x38_25_noInheritTransform)
|
if (!x38_25_noInheritTransform) {
|
||||||
activateActor->SetTransform(followActor->GetTransform());
|
activateActor->SetTransform(followActor->GetTransform());
|
||||||
|
}
|
||||||
activateActor->SetTranslation(followActor->GetTranslation() + x3c_offset);
|
activateActor->SetTranslation(followActor->GetTranslation() + x3c_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
float rnd = stateMgr.GetActiveRandom()->Range(x48_minScale, x4c_maxScale);
|
const float rnd = stateMgr.GetActiveRandom()->Range(x48_minScale, x4c_maxScale);
|
||||||
CModelData* mData = activateActor->GetModelData();
|
CModelData* mData = activateActor->GetModelData();
|
||||||
if (mData && !mData->IsNull())
|
if (mData && !mData->IsNull()) {
|
||||||
mData->SetScale(rnd * mData->GetScale());
|
mData->SetScale(rnd * mData->GetScale());
|
||||||
|
}
|
||||||
|
|
||||||
stateMgr.SendScriptMsg(genObj, GetUniqueId(), EScriptObjectMessage::Activate);
|
stateMgr.SendScriptMsg(genObj, GetUniqueId(), EScriptObjectMessage::Activate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
activates.erase(std::find(activates.begin(), activates.end(), idPair));
|
activates.erase(std::find(activates.begin(), activates.end(), idPair));
|
||||||
if (x38_24_noReuseFollowers)
|
if (x38_24_noReuseFollowers) {
|
||||||
follows.erase(std::find(follows.begin(), follows.end(), follows[followsRand]));
|
follows.erase(std::find(follows.begin(), follows.end(), follows[followsRand]));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue