mirror of https://github.com/AxioDL/metaforce.git
CScriptPickupGenerator: Brace conditionals where applicable
This commit is contained in:
parent
8698cc3cd5
commit
c3f723007e
|
@ -17,10 +17,11 @@ CScriptPickupGenerator::CScriptPickupGenerator(TUniqueId uid, std::string_view n
|
||||||
void CScriptPickupGenerator::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
void CScriptPickupGenerator::Accept(IVisitor& visitor) { visitor.Visit(this); }
|
||||||
|
|
||||||
void CScriptPickupGenerator::ResetDelayTimer() {
|
void CScriptPickupGenerator::ResetDelayTimer() {
|
||||||
if (x40_frequency > 0.f)
|
if (x40_frequency > 0.f) {
|
||||||
x44_delayTimer += 100.f / x40_frequency;
|
x44_delayTimer += 100.f / x40_frequency;
|
||||||
else
|
} else {
|
||||||
x44_delayTimer = FLT_MAX;
|
x44_delayTimer = FLT_MAX;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptPickupGenerator::GetGeneratorIds(CStateManager& mgr, TUniqueId sender,
|
void CScriptPickupGenerator::GetGeneratorIds(CStateManager& mgr, TUniqueId sender,
|
||||||
|
@ -28,17 +29,19 @@ void CScriptPickupGenerator::GetGeneratorIds(CStateManager& mgr, TUniqueId sende
|
||||||
idsOut.reserve(std::max(size_t(1), GetConnectionList().size()));
|
idsOut.reserve(std::max(size_t(1), GetConnectionList().size()));
|
||||||
for (const auto& conn : GetConnectionList()) {
|
for (const auto& conn : GetConnectionList()) {
|
||||||
if (conn.x0_state == EScriptObjectState::Zero && conn.x4_msg == EScriptObjectMessage::Follow) {
|
if (conn.x0_state == EScriptObjectState::Zero && conn.x4_msg == EScriptObjectMessage::Follow) {
|
||||||
TUniqueId id = mgr.GetIdForScript(conn.x8_objId);
|
const TUniqueId id = mgr.GetIdForScript(conn.x8_objId);
|
||||||
if (id != kInvalidUniqueId) {
|
if (id != kInvalidUniqueId) {
|
||||||
if (const CEntity* ent = mgr.GetObjectById(id)) {
|
if (const CEntity* ent = mgr.GetObjectById(id)) {
|
||||||
if (ent->GetActive())
|
if (ent->GetActive()) {
|
||||||
idsOut.push_back(id);
|
idsOut.push_back(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (idsOut.empty())
|
if (idsOut.empty()) {
|
||||||
idsOut.push_back(sender);
|
idsOut.push_back(sender);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
|
float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
|
||||||
|
@ -48,10 +51,10 @@ float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
|
||||||
idsOut.reserve(GetConnectionList().size());
|
idsOut.reserve(GetConnectionList().size());
|
||||||
for (const auto& conn : GetConnectionList()) {
|
for (const auto& conn : GetConnectionList()) {
|
||||||
if (conn.x0_state == EScriptObjectState::Zero && conn.x4_msg == EScriptObjectMessage::Activate) {
|
if (conn.x0_state == EScriptObjectState::Zero && conn.x4_msg == EScriptObjectMessage::Activate) {
|
||||||
TUniqueId id = mgr.GetIdForScript(conn.x8_objId);
|
const TUniqueId id = mgr.GetIdForScript(conn.x8_objId);
|
||||||
if (id != kInvalidUniqueId) {
|
if (id != kInvalidUniqueId) {
|
||||||
if (TCastToConstPtr<CScriptPickup> pickup = mgr.GetObjectById(id)) {
|
if (const TCastToConstPtr<CScriptPickup> pickup = mgr.GetObjectById(id)) {
|
||||||
CPlayerState::EItemType item = pickup->GetItem();
|
const CPlayerState::EItemType item = pickup->GetItem();
|
||||||
float possibility = pickup->GetPossibility();
|
float possibility = pickup->GetPossibility();
|
||||||
float multiplier = 1.f;
|
float multiplier = 1.f;
|
||||||
bool doAlways = false;
|
bool doAlways = false;
|
||||||
|
@ -60,10 +63,11 @@ float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
|
||||||
case CPlayerState::EItemType::Missiles:
|
case CPlayerState::EItemType::Missiles:
|
||||||
if (pState.HasPowerUp(CPlayerState::EItemType::Missiles)) {
|
if (pState.HasPowerUp(CPlayerState::EItemType::Missiles)) {
|
||||||
if (pState.GetItemAmount(CPlayerState::EItemType::Missiles) <
|
if (pState.GetItemAmount(CPlayerState::EItemType::Missiles) <
|
||||||
pState.GetItemCapacity(CPlayerState::EItemType::Missiles))
|
pState.GetItemCapacity(CPlayerState::EItemType::Missiles)) {
|
||||||
doAlways = true;
|
doAlways = true;
|
||||||
else
|
} else {
|
||||||
doThirtyPerc = true;
|
doThirtyPerc = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CPlayerState::EItemType::PowerBombs:
|
case CPlayerState::EItemType::PowerBombs:
|
||||||
|
@ -71,19 +75,21 @@ float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
|
||||||
if (pState.GetItemAmount(CPlayerState::EItemType::PowerBombs) <
|
if (pState.GetItemAmount(CPlayerState::EItemType::PowerBombs) <
|
||||||
pState.GetItemCapacity(CPlayerState::EItemType::PowerBombs)) {
|
pState.GetItemCapacity(CPlayerState::EItemType::PowerBombs)) {
|
||||||
doAlways = true;
|
doAlways = true;
|
||||||
if (pState.GetItemAmount(CPlayerState::EItemType::PowerBombs) < 2 &&
|
if (pState.GetItemAmount(CPlayerState::EItemType::PowerBombs) < 2 && possibility >= 10.f &&
|
||||||
possibility >= 10.f && possibility < 25.f)
|
possibility < 25.f) {
|
||||||
multiplier = 2.f;
|
multiplier = 2.f;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
doThirtyPerc = true;
|
doThirtyPerc = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case CPlayerState::EItemType::HealthRefill:
|
case CPlayerState::EItemType::HealthRefill:
|
||||||
if (pState.GetHealthInfo().GetHP() < pState.CalculateHealth())
|
if (pState.GetHealthInfo().GetHP() < pState.CalculateHealth()) {
|
||||||
doAlways = true;
|
doAlways = true;
|
||||||
else
|
} else {
|
||||||
doThirtyPerc = true;
|
doThirtyPerc = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
doAlways = true;
|
doAlways = true;
|
||||||
|
@ -104,26 +110,37 @@ float CScriptPickupGenerator::GetPickupTemplates(CStateManager& mgr,
|
||||||
void CScriptPickupGenerator::GeneratePickup(CStateManager& mgr, TEditorId templateId, TUniqueId generatorId) const {
|
void CScriptPickupGenerator::GeneratePickup(CStateManager& mgr, TEditorId templateId, TUniqueId generatorId) const {
|
||||||
CEntity* pickupTempl = mgr.ObjectById(mgr.GetIdForScript(templateId));
|
CEntity* pickupTempl = mgr.ObjectById(mgr.GetIdForScript(templateId));
|
||||||
CEntity* generator = mgr.ObjectById(generatorId);
|
CEntity* generator = mgr.ObjectById(generatorId);
|
||||||
if (pickupTempl && generator) {
|
|
||||||
bool oldGeneratingObject = mgr.GetIsGeneratingObject();
|
if (pickupTempl == nullptr || generator == nullptr) {
|
||||||
mgr.SetIsGeneratingObject(true);
|
return;
|
||||||
auto p = mgr.GenerateObject(templateId);
|
|
||||||
mgr.SetIsGeneratingObject(oldGeneratingObject);
|
|
||||||
if (p.second != kInvalidUniqueId) {
|
|
||||||
CEntity* newObj = mgr.ObjectById(p.second);
|
|
||||||
CActor* newAct = TCastToPtr<CActor>(newObj).GetPtr();
|
|
||||||
CScriptPickup* newPickup = TCastToPtr<CScriptPickup>(newObj).GetPtr();
|
|
||||||
CActor* generatorAct = TCastToPtr<CActor>(generator).GetPtr();
|
|
||||||
CWallCrawlerSwarm* swarmAct = TCastToPtr<CWallCrawlerSwarm>(generator).GetPtr();
|
|
||||||
if (newAct && swarmAct)
|
|
||||||
newAct->SetTranslation(swarmAct->GetLastKilledOffset() + x34_position);
|
|
||||||
else if (newAct && generatorAct)
|
|
||||||
newAct->SetTranslation(generatorAct->GetTranslation() + x34_position);
|
|
||||||
if (newPickup)
|
|
||||||
newPickup->SetGenerated();
|
|
||||||
mgr.SendScriptMsg(newObj, GetUniqueId(), EScriptObjectMessage::Activate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool oldGeneratingObject = mgr.GetIsGeneratingObject();
|
||||||
|
mgr.SetIsGeneratingObject(true);
|
||||||
|
const auto p = mgr.GenerateObject(templateId);
|
||||||
|
mgr.SetIsGeneratingObject(oldGeneratingObject);
|
||||||
|
|
||||||
|
if (p.second == kInvalidUniqueId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CEntity* newObj = mgr.ObjectById(p.second);
|
||||||
|
CActor* newAct = TCastToPtr<CActor>(newObj).GetPtr();
|
||||||
|
CScriptPickup* newPickup = TCastToPtr<CScriptPickup>(newObj).GetPtr();
|
||||||
|
const CActor* generatorAct = TCastToConstPtr<CActor>(generator).GetPtr();
|
||||||
|
const CWallCrawlerSwarm* swarmAct = TCastToConstPtr<CWallCrawlerSwarm>(generator).GetPtr();
|
||||||
|
|
||||||
|
if (newAct && swarmAct) {
|
||||||
|
newAct->SetTranslation(swarmAct->GetLastKilledOffset() + x34_position);
|
||||||
|
} else if (newAct && generatorAct) {
|
||||||
|
newAct->SetTranslation(generatorAct->GetTranslation() + x34_position);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newPickup) {
|
||||||
|
newPickup->SetGenerated();
|
||||||
|
}
|
||||||
|
|
||||||
|
mgr.SendScriptMsg(newObj, GetUniqueId(), EScriptObjectMessage::Activate);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CScriptPickupGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& stateMgr) {
|
void CScriptPickupGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId sender, CStateManager& stateMgr) {
|
||||||
|
@ -135,19 +152,20 @@ void CScriptPickupGenerator::AcceptScriptMsg(EScriptObjectMessage msg, TUniqueId
|
||||||
std::vector<TUniqueId> generatorIds;
|
std::vector<TUniqueId> generatorIds;
|
||||||
GetGeneratorIds(stateMgr, sender, generatorIds);
|
GetGeneratorIds(stateMgr, sender, generatorIds);
|
||||||
std::vector<std::pair<float, TEditorId>> pickupTemplates;
|
std::vector<std::pair<float, TEditorId>> pickupTemplates;
|
||||||
float totalProb = GetPickupTemplates(stateMgr, pickupTemplates);
|
const float totalProb = GetPickupTemplates(stateMgr, pickupTemplates);
|
||||||
if (!pickupTemplates.empty()) {
|
if (!pickupTemplates.empty()) {
|
||||||
float r = stateMgr.GetActiveRandom()->Range(0.f, totalProb);
|
const float r = stateMgr.GetActiveRandom()->Range(0.f, totalProb);
|
||||||
float f2 = 0.f;
|
float f2 = 0.f;
|
||||||
size_t count = 0;
|
size_t count = 0;
|
||||||
for (const auto& id : pickupTemplates) {
|
for (const auto& id : pickupTemplates) {
|
||||||
if (r >= f2 && r <= f2 + id.first)
|
if (r >= f2 && r <= f2 + id.first) {
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
f2 += id.first;
|
f2 += id.first;
|
||||||
++count;
|
++count;
|
||||||
}
|
}
|
||||||
if (count != pickupTemplates.size()) {
|
if (count != pickupTemplates.size()) {
|
||||||
TEditorId templateId = pickupTemplates[count].second;
|
const TEditorId templateId = pickupTemplates[count].second;
|
||||||
GeneratePickup(stateMgr, templateId,
|
GeneratePickup(stateMgr, templateId,
|
||||||
generatorIds[stateMgr.GetActiveRandom()->Float() * generatorIds.size() * 0.99f]);
|
generatorIds[stateMgr.GetActiveRandom()->Float() * generatorIds.size() * 0.99f]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue