| 159 | } |
| 160 | |
| 161 | bool NpcScriptState::doAIState(float deltaTime) |
| 162 | { |
| 163 | VobTypes::NpcVobInformation vob = VobTypes::asNpcVob(m_World, m_HostVob); |
| 164 | ScriptEngine& s = m_World.getScriptEngine(); |
| 165 | Daedalus::DATFile& dat = s.getVM().getDATFile(); |
| 166 | |
| 167 | // Increase time this state is already running |
| 168 | if (m_CurrentState.valid && m_CurrentState.phase == NpcAIState::EPhase::Loop) |
| 169 | m_CurrentState.stateTime += deltaTime; |
| 170 | |
| 171 | std::string name = vob.playerController->getScriptInstance().name[0]; |
| 172 | |
| 173 | if (m_Routine.hasRoutine && isInRoutine()) |
| 174 | { |
| 175 | int h, m; |
| 176 | m_World.getEngine()->getGameClock().getTimeOfDay(h, m); |
| 177 | |
| 178 | if (!m_Routine.routine[m_Routine.routineActiveIdx].timeInRange(h, m)) |
| 179 | { |
| 180 | // Find next |
| 181 | size_t i = 0; |
| 182 | for (RoutineEntry& e : m_Routine.routine) |
| 183 | { |
| 184 | if (e.timeInRange(h, m) && i != m_Routine.routineActiveIdx) |
| 185 | { |
| 186 | m_Routine.routineActiveIdx = i; |
| 187 | m_Routine.startNewRoutine = true; |
| 188 | break; |
| 189 | } |
| 190 | |
| 191 | i++; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // Only do states if we do not have messages pending |
| 197 | if (vob.playerController->getEM().isEmpty()) |
| 198 | { |
| 199 | // Check for routine first |
| 200 | if (m_Routine.startNewRoutine && m_Routine.hasRoutine && isInRoutine() && !vob.playerController->isPlayerControlled()) |
| 201 | startRoutineState(); |
| 202 | |
| 203 | if (!m_CurrentState.valid) |
| 204 | { |
| 205 | // Can we move to the next state? |
| 206 | if (m_NextState.valid) |
| 207 | { |
| 208 | // Remember the last state we were in |
| 209 | m_LastStateSymIndex = m_CurrentState.symIndex; |
| 210 | |
| 211 | // Move to next state |
| 212 | m_CurrentState = m_NextState; |
| 213 | m_CurrentState.stateTime = 0.0f; |
| 214 | |
| 215 | m_NextState.valid = false; |
| 216 | } |
| 217 | else |
| 218 | { |
no test coverage detected