| 1 | #include "MapObj/CitySignal.h" |
| 2 | |
| 3 | #include "Library/Base/StringUtil.h" |
| 4 | #include "Library/LiveActor/ActorActionFunction.h" |
| 5 | #include "Library/LiveActor/ActorInitUtil.h" |
| 6 | #include "Library/LiveActor/ActorModelFunction.h" |
| 7 | #include "Library/LiveActor/ActorSensorUtil.h" |
| 8 | #include "Library/Nerve/NerveSetupUtil.h" |
| 9 | #include "Library/Nerve/NerveUtil.h" |
| 10 | |
| 11 | #include "System/GameDataFunction.h" |
| 12 | |
| 13 | namespace { |
| 14 | NERVE_IMPL(CitySignal, WaitRed); |
| 15 | NERVE_IMPL(CitySignal, WaitBlue); |
| 16 | NERVE_IMPL(CitySignal, WaitOff); |
| 17 | |
| 18 | NERVES_MAKE_STRUCT(CitySignal, WaitRed, WaitBlue, WaitOff); |
| 19 | } // namespace |
| 20 | |
| 21 | CitySignal::CitySignal(const char* name) : al::LiveActor(name) {} |
| 22 | |
| 23 | void CitySignal::init(const al::ActorInitInfo& info) { |
| 24 | al::initActor(actor: this, initInfo: info); |
| 25 | |
| 26 | s32 scenarioNo = GameDataFunction::getScenarioNo(actor: this); |
| 27 | al::tryStartAction(actor: this, actionName: al::StringTmp<64>("Scenario%d" , scenarioNo).cstr()); |
| 28 | |
| 29 | if (scenarioNo == 1) |
| 30 | al::initNerve(actor: this, nerve: &NrvCitySignal.WaitRed, maxStates: 0); |
| 31 | else |
| 32 | al::initNerve(actor: this, nerve: &NrvCitySignal.WaitBlue, maxStates: 0); |
| 33 | |
| 34 | al::trySyncStageSwitchAppearAndKill(actor: this); |
| 35 | } |
| 36 | |
| 37 | void CitySignal::movement() { |
| 38 | // this being empty results in the animation not playing (blinking for Red) |
| 39 | // and the signal not turning off when hit by an explosion |
| 40 | } |
| 41 | |
| 42 | void CitySignal::calcAnim() { |
| 43 | if (al::isNerve(user: this, nerve: &NrvCitySignal.WaitRed) || al::isNerve(user: this, nerve: &NrvCitySignal.WaitOff)) |
| 44 | al::LiveActor::calcAnim(); |
| 45 | else |
| 46 | al::calcViewModel(actor: this); |
| 47 | } |
| 48 | |
| 49 | bool CitySignal::receiveMsg(const al::SensorMsg* message, al::HitSensor* other, |
| 50 | al::HitSensor* self) { |
| 51 | if (al::isMsgExplosion(msg: message) && al::isSensorMapObj(self) && |
| 52 | (al::isNerve(user: this, nerve: &NrvCitySignal.WaitRed) || al::isNerve(user: this, nerve: &NrvCitySignal.WaitBlue))) { |
| 53 | al::setNerve(user: this, nerve: &NrvCitySignal.WaitOff); |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | return false; |
| 58 | } |
| 59 | |
| 60 | void CitySignal::exeWaitRed() {} |
| 61 | |
| 62 | void CitySignal::exeWaitBlue() {} |
| 63 | |
| 64 | void CitySignal::exeWaitOff() { |
| 65 | if (al::isFirstStep(user: this)) |
| 66 | al::startAction(actor: this, actionName: "LightOff" ); |
| 67 | } |
| 68 | |