2019-12-22 20:04:07 +00:00
|
|
|
#include "Runtime/World/CScriptGenerator.hpp"
|
|
|
|
|
|
|
|
#include "Runtime/CStateManager.hpp"
|
|
|
|
#include "Runtime/World/CWallCrawlerSwarm.hpp"
|
|
|
|
|
2019-09-21 13:07:13 +00:00
|
|
|
#include "TCastTo.hpp" // Generated file, do not modify include path
|
2016-04-20 21:44:18 +00:00
|
|
|
|
2021-04-10 08:42:06 +00:00
|
|
|
namespace metaforce {
|
2016-04-20 21:44:18 +00:00
|
|
|
|
2017-11-13 06:19:18 +00:00
|
|
|
CScriptGenerator::CScriptGenerator(TUniqueId uid, std::string_view name, const CEntityInfo& info, u32 spawnCount,
|
2018-05-16 04:07:38 +00:00
|
|
|
bool noReuseFollowers, const zeus::CVector3f& vec1, bool noInheritXf, bool active,
|
2017-01-24 17:47:11 +00:00
|
|
|
float minScale, float maxScale)
|
2017-01-24 17:23:10 +00:00
|
|
|
: CEntity(uid, info, active, name)
|
2017-01-24 17:47:11 +00:00
|
|
|
, x34_spawnCount(spawnCount)
|
2018-05-16 04:07:38 +00:00
|
|
|
, x38_24_noReuseFollowers(noReuseFollowers)
|
|
|
|
, x38_25_noInheritTransform(noInheritXf)
|
2017-01-24 17:23:10 +00:00
|
|
|
, x3c_offset(vec1)
|
|
|
|
, x48_minScale(minScale)
|
2018-12-08 05:30:43 +00:00
|
|
|
, x4c_maxScale(maxScale) {}
|
2016-05-03 08:27:28 +00:00
|
|
|
|
2017-01-24 17:23:10 +00:00
|
|
|
void CScriptGenerator::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
2017-01-15 03:07:01 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
void CScriptGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& stateMgr) {
|
|
|
|
switch (msg) {
|
|
|
|
case EScriptObjectMessage::SetToZero: {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (!GetActive()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
std::vector<TUniqueId> follows;
|
|
|
|
follows.reserve(x20_conns.size());
|
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::Zero || conn.x4_msg != EScriptObjectMessage::Follow) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
const TUniqueId uid = stateMgr.GetIdForScript(conn.x8_objId);
|
2022-11-30 21:28:00 +00:00
|
|
|
if (uid != kInvalidUniqueId) {
|
|
|
|
const CEntity* ent = stateMgr.GetObjectById(uid);
|
|
|
|
if (ent && ent->GetActive()) {
|
|
|
|
follows.push_back(uid);
|
|
|
|
}
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
2017-01-24 17:23:10 +00:00
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
if (follows.empty()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
follows.push_back(sender);
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-05-16 04:07:38 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
std::vector<std::pair<TUniqueId, TEditorId>> activates;
|
|
|
|
activates.reserve(x20_conns.size());
|
2017-01-24 17:23:10 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
for (const SConnection& conn : x20_conns) {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (conn.x0_state != EScriptObjectState::Zero) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2017-01-24 17:23:10 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
TUniqueId uid = stateMgr.GetIdForScript(conn.x8_objId);
|
2020-05-07 17:28:30 +00:00
|
|
|
if (uid == kInvalidUniqueId) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2017-01-24 17:23:10 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
if (conn.x4_msg == EScriptObjectMessage::Activate) {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (!stateMgr.GetObjectById(uid)) {
|
2018-12-08 05:30:43 +00:00
|
|
|
continue;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
activates.emplace_back(uid, conn.x8_objId);
|
2019-01-30 08:38:16 +00:00
|
|
|
} else {
|
|
|
|
stateMgr.SendScriptMsgAlways(uid, GetUniqueId(), conn.x4_msg);
|
2018-12-08 05:30:43 +00:00
|
|
|
}
|
|
|
|
}
|
2017-01-31 11:21:45 +00:00
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
if (activates.empty()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
for (u32 i = 0; i < x34_spawnCount; ++i) {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (activates.size() == 0 || follows.size() == 0) {
|
2018-05-16 04:07:38 +00:00
|
|
|
break;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
u32 activatesRand = 0.99f * (stateMgr.GetActiveRandom()->Float() * activates.size());
|
2020-05-07 17:28:30 +00:00
|
|
|
const u32 followsRand = 0.99f * (stateMgr.GetActiveRandom()->Float() * follows.size());
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
for (u32 j = 0; j < activates.size(); ++j) {
|
|
|
|
if (TCastToConstPtr<CScriptSound>(stateMgr.GetObjectById(activates[j].first))) {
|
2018-12-08 05:30:43 +00:00
|
|
|
activatesRand = j;
|
2022-11-30 21:28:00 +00:00
|
|
|
break;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
const std::pair<TUniqueId, TEditorId> idPair = activates[activatesRand];
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity* activate = stateMgr.ObjectById(idPair.first);
|
|
|
|
CEntity* follow = stateMgr.ObjectById(follows[followsRand]);
|
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
if (!activate || !follow) {
|
2018-05-16 04:07:38 +00:00
|
|
|
break;
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
const bool oldGeneratingObject = stateMgr.GetIsGeneratingObject();
|
2018-12-08 05:30:43 +00:00
|
|
|
stateMgr.SetIsGeneratingObject(true);
|
2020-05-07 17:28:30 +00:00
|
|
|
const std::pair<TEditorId, TUniqueId> objId = stateMgr.GenerateObject(idPair.second);
|
2018-12-08 05:30:43 +00:00
|
|
|
stateMgr.SetIsGeneratingObject(oldGeneratingObject);
|
|
|
|
|
|
|
|
if (objId.second != kInvalidUniqueId) {
|
|
|
|
if (CEntity* genObj = stateMgr.ObjectById(objId.second)) {
|
2020-05-07 17:28:30 +00:00
|
|
|
const TCastToPtr<CActor> activateActor(genObj);
|
|
|
|
const TCastToConstPtr<CActor> followActor(follow);
|
|
|
|
const TCastToConstPtr<CWallCrawlerSwarm> wallCrawlerSwarm(follow);
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
if (activateActor && wallCrawlerSwarm) {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (!x38_25_noInheritTransform) {
|
2018-12-08 05:30:43 +00:00
|
|
|
activateActor->SetTransform(wallCrawlerSwarm->GetTransform());
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
activateActor->SetTranslation(wallCrawlerSwarm->GetLastKilledOffset() + x3c_offset);
|
|
|
|
} else if (activateActor && followActor) {
|
2020-05-07 17:28:30 +00:00
|
|
|
if (!x38_25_noInheritTransform) {
|
2018-12-08 05:30:43 +00:00
|
|
|
activateActor->SetTransform(followActor->GetTransform());
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
activateActor->SetTranslation(followActor->GetTranslation() + x3c_offset);
|
|
|
|
}
|
|
|
|
|
2020-05-07 17:28:30 +00:00
|
|
|
const float rnd = stateMgr.GetActiveRandom()->Range(x48_minScale, x4c_maxScale);
|
2019-08-14 14:58:54 +00:00
|
|
|
CModelData* mData = activateActor->GetModelData();
|
2020-05-07 17:28:30 +00:00
|
|
|
if (mData && !mData->IsNull()) {
|
2018-12-08 05:30:43 +00:00
|
|
|
mData->SetScale(rnd * mData->GetScale());
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
|
|
|
|
stateMgr.SendScriptMsg(genObj, GetUniqueId(), EScriptObjectMessage::Activate);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
activates.erase(std::find(activates.begin(), activates.end(), idPair));
|
2020-05-07 17:28:30 +00:00
|
|
|
if (x38_24_noReuseFollowers) {
|
2018-12-08 05:30:43 +00:00
|
|
|
follows.erase(std::find(follows.begin(), follows.end(), follows[followsRand]));
|
2020-05-07 17:28:30 +00:00
|
|
|
}
|
2016-05-03 08:27:28 +00:00
|
|
|
}
|
2018-12-08 05:30:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-05-03 08:27:28 +00:00
|
|
|
|
2018-12-08 05:30:43 +00:00
|
|
|
CEntity::AcceptScriptMsg(msg, sender, stateMgr);
|
2016-05-03 08:27:28 +00:00
|
|
|
}
|
2021-04-10 08:42:06 +00:00
|
|
|
} // namespace metaforce
|