2016-04-25 05:46:28 +00:00
|
|
|
#include "CStateMachine.hpp"
|
|
|
|
#include "CAi.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
CStateMachine::CStateMachine(CInputStream& in)
|
|
|
|
{
|
2016-08-15 20:43:04 +00:00
|
|
|
#if 0
|
|
|
|
u32 stateCount = in.readUint32Big();
|
|
|
|
|
|
|
|
x0_states.reserve(stateCount);
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
for (u32 i = 0; i < stateCount; ++i)
|
2016-08-15 20:43:04 +00:00
|
|
|
{
|
|
|
|
std::string name = in.readString(31);
|
|
|
|
CAiStateFunc func = CAi::GetStateFunc(name.c_str());
|
|
|
|
x0_states.emplace_back(func, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
x10_triggers.reserve(in.readUint32Big());
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
for (u32 i = 0; i < stateCount; ++i)
|
2016-08-15 20:43:04 +00:00
|
|
|
{
|
|
|
|
x0_states[i].SetNumTriggers(in.readUint32Big());
|
|
|
|
if (x0_states[i].GetNumTriggers() == 0)
|
|
|
|
continue;
|
2017-01-04 04:08:30 +00:00
|
|
|
for (u32 j = 0; j < x0_states[i].GetNumTriggers(); ++j)
|
2016-08-15 20:43:04 +00:00
|
|
|
x10_triggers.emplace_back();
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
for (u32 j = 0; j < x0_states[i].GetNumTriggers(); ++j)
|
2016-08-15 20:43:04 +00:00
|
|
|
{
|
|
|
|
u32 triggerCount = in.readUint32Big();
|
|
|
|
u32 r19 = triggerCount - 1;
|
2017-01-04 04:08:30 +00:00
|
|
|
for (u32 k = 0; k < triggerCount; ++k)
|
2016-08-15 20:43:04 +00:00
|
|
|
{
|
|
|
|
std::string name = in.readString(31);
|
|
|
|
CAiTriggerFunc func = CAi::GetTrigerFunc(name.c_str());
|
|
|
|
float f31 = in.readFloatBig();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|
2016-05-13 03:13:34 +00:00
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
s32 CStateMachine::GetStateIndex(const std::string& state) const
|
2016-05-13 03:13:34 +00:00
|
|
|
{
|
|
|
|
auto it = std::find_if(x0_states.begin(), x0_states.end(), [&state](const CAiState& st) -> bool {
|
|
|
|
return (strncmp(st.GetName(), state.c_str(), 31) == 0);
|
|
|
|
});
|
|
|
|
if (it == x0_states.end())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return it - x0_states.begin();
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
const std::vector<CAiState>& CStateMachine::GetStateVector() const { return x0_states; }
|
|
|
|
|
|
|
|
float CStateMachineState::GetTime() const { return 0.f; }
|
|
|
|
|
|
|
|
void CStateMachineState::SetState(CStateManager &, CAi &, s32 idx)
|
2016-05-13 03:13:34 +00:00
|
|
|
{
|
|
|
|
}
|
2016-08-15 20:43:04 +00:00
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
void CStateMachineState::SetState(CStateManager& mgr, CAi& ai, const CStateMachine* machine, const std::string& state)
|
2016-08-15 20:43:04 +00:00
|
|
|
{
|
2017-01-04 04:08:30 +00:00
|
|
|
if (!machine)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!x0_machine)
|
|
|
|
x0_machine = machine;
|
|
|
|
|
|
|
|
s32 idx = machine->GetStateIndex(state);
|
|
|
|
SetState(mgr, ai, idx);
|
2016-08-15 20:43:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector<CAiState>* CStateMachineState::GetStateVector() const
|
|
|
|
{
|
|
|
|
if (!x0_machine)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return &x0_machine->GetStateVector();
|
|
|
|
}
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
void CStateMachineState::Setup(const CStateMachine* machine)
|
2016-08-15 20:43:04 +00:00
|
|
|
{
|
|
|
|
x0_machine = machine;
|
|
|
|
x4_state = nullptr;
|
2017-01-04 04:08:30 +00:00
|
|
|
x8_time = 0.f;
|
2016-08-15 20:43:04 +00:00
|
|
|
xc_ = 0.f;
|
2017-01-04 04:08:30 +00:00
|
|
|
x10_ = 0.f;
|
2016-08-15 20:43:04 +00:00
|
|
|
}
|
|
|
|
|
2017-01-04 04:08:30 +00:00
|
|
|
std::string CStateMachineState::GetName() const { return {}; }
|
2016-04-25 05:46:28 +00:00
|
|
|
}
|