| 47 | } |
| 48 | |
| 49 | bool Logic::NpcScriptState::startAIState(size_t symIdx, bool endOldState, bool isRoutineState, bool isPrgState) |
| 50 | { |
| 51 | VobTypes::NpcVobInformation vob = VobTypes::asNpcVob(m_World, m_HostVob); |
| 52 | ScriptEngine& s = m_World.getScriptEngine(); |
| 53 | Daedalus::DATFile& dat = s.getVM().getDATFile(); |
| 54 | |
| 55 | // Save script variables |
| 56 | m_StateOther = s.getNPCFromSymbol("other"); |
| 57 | m_StateVictim = s.getNPCFromSymbol("victim"); |
| 58 | m_StateItem = s.getItemFromSymbol("item"); |
| 59 | |
| 60 | if (!isPrgState) |
| 61 | { |
| 62 | // Usual script-state. Find the symbols |
| 63 | m_NextState.name = dat.getSymbolByIndex(symIdx).name; |
| 64 | m_NextState.prgState = NPC_PRGAISTATE_INVALID; |
| 65 | } |
| 66 | else |
| 67 | { |
| 68 | assert(symIdx < NUM_PRGNPC_AISTATE); |
| 69 | |
| 70 | // State whose loops are managed by engine-code |
| 71 | m_NextState.name = s_PRGStates[symIdx]; |
| 72 | m_NextState.prgState = (EPrgStates)symIdx; |
| 73 | |
| 74 | symIdx = dat.getSymbolIndexByName(s_PRGStates[symIdx]); |
| 75 | } |
| 76 | |
| 77 | LogInfo() << "AISTATE-START: " << m_NextState.name << " on NPC: " << VobTypes::getScriptObject(vob).name[0] << " (WP: " << VobTypes::getScriptObject(vob).wp << ")"; |
| 78 | |
| 79 | // Check if this is just a usual action (ZS = German "Zustand" = State, B = German "Befehl" = Instruction) |
| 80 | if (m_NextState.name.substr(0, 3) != "ZS_") |
| 81 | { |
| 82 | // Disable routine-flag for this, since scripts could let the npc assess something |
| 83 | bool oldIsRoutineState = m_CurrentState.isRoutineState; |
| 84 | m_CurrentState.isRoutineState = isRoutineState; |
| 85 | |
| 86 | // Just call the function |
| 87 | s.prepareRunFunction(); |
| 88 | s.setInstance("self", VobTypes::getScriptObject(vob).instanceSymbol); |
| 89 | s.runFunctionBySymIndex(symIdx); |
| 90 | |
| 91 | m_CurrentState.isRoutineState = oldIsRoutineState; |
| 92 | return true; |
| 93 | } |
| 94 | |
| 95 | m_NextState.isRoutineState = isRoutineState; |
| 96 | |
| 97 | m_NextState.symIndex = symIdx; |
| 98 | m_NextState.symEnd = 0; |
| 99 | m_NextState.symLoop = 0; |
| 100 | |
| 101 | if (dat.hasSymbolName(m_NextState.name + "_END")) |
| 102 | m_NextState.symEnd = dat.getSymbolIndexByName(m_NextState.name + "_END"); |
| 103 | |
| 104 | if (dat.hasSymbolName(m_NextState.name + "_LOOP")) |
| 105 | m_NextState.symLoop = dat.getSymbolIndexByName(m_NextState.name + "_LOOP"); |
| 106 |
no test coverage detected