1332
|
1
|
|
2 #include "MM7.h"
|
|
3 #include "mm7_data.h"
|
|
4 #include "Actor.h"
|
|
5 #include "Player.h"
|
|
6 #include "Party.h"
|
|
7 #include "AudioPlayer.h"
|
|
8 #include "SpriteObject.h"
|
2044
|
9 #include "Timer.h"
|
1332
|
10 #include "stru298.h"
|
|
11 #include "IconFrameTable.h"
|
|
12 #include "Viewport.h"
|
|
13 #include "FactionTable.h"
|
|
14
|
|
15 #include "TurnEngine.h"
|
|
16
|
|
17
|
|
18 #include "TurnEngine.h"
|
|
19 struct stru262_TurnBased *pTurnEngine = new stru262_TurnBased;
|
|
20
|
|
21
|
|
22 //----- (00404544) --------------------------------------------------------
|
|
23 void stru262_TurnBased::SortTurnQueue()
|
2242
|
24 {
|
|
25 int active_actors;
|
|
26 TurnBased_QueueElem *current_top; // eax@16
|
|
27 TurnBased_QueueElem *test_element; // ecx@18
|
|
28 TurnBased_QueueElem temp_elem;
|
|
29 int i,j;
|
|
30 unsigned int p_type;
|
|
31 unsigned int p_id;
|
1332
|
32
|
2242
|
33 active_actors = this->uActorQueueSize;
|
|
34 //set non active actors in queue initiative that not allow them to paticipate
|
|
35 for( i = 0; i < uActorQueueSize; ++i)
|
|
36 {
|
|
37 p_type = PID_TYPE(pQueue[i].uPackedID);
|
|
38 p_id = PID_ID(pQueue[i].uPackedID);
|
|
39
|
|
40 if ( p_type == OBJECT_Actor )
|
|
41 {
|
|
42 pActors[p_id].uAttributes |= 0x80;
|
|
43 if ( !pActors[p_id].CanAct() )
|
|
44 {
|
|
45 --active_actors;
|
|
46 pQueue[i].actor_initiative = 1001;
|
|
47 pActors[p_id].uAttributes &= ~0x80;
|
|
48 }
|
|
49 }
|
|
50 else if ( p_type == OBJECT_Player)
|
1332
|
51 {
|
2242
|
52 if ( !pParty->pPlayers[p_id].CanAct() )
|
|
53 {
|
|
54 --active_actors;
|
|
55 pQueue[i].actor_initiative = 1001;
|
|
56 }
|
|
57 }
|
|
58 }
|
|
59 //sort
|
|
60 if (uActorQueueSize > 0)
|
|
61 {
|
|
62 for( i = 0; i < uActorQueueSize-1; ++i)
|
|
63 {
|
|
64 current_top=&pQueue[i];
|
|
65 for ( j = i+1; j < uActorQueueSize; ++j )
|
|
66 {
|
|
67 test_element=&pQueue[j];
|
|
68 if ( test_element->actor_initiative < current_top->actor_initiative || // if less initiative -> top
|
|
69 ((test_element->actor_initiative == current_top->actor_initiative) &&
|
|
70 (((PID_TYPE(test_element->uPackedID) == OBJECT_Player) && (PID_TYPE(current_top->uPackedID) == OBJECT_Actor)) || //player preferable
|
|
71 ((PID_TYPE(test_element->uPackedID) == PID_TYPE(current_top->uPackedID)) && (PID_ID(test_element->uPackedID) < PID_ID(current_top->uPackedID)))))) //less id preferable
|
|
72 { //swap
|
|
73 memcpy(&temp_elem,current_top,sizeof(TurnBased_QueueElem));
|
|
74 memcpy(current_top,test_element, sizeof(TurnBased_QueueElem));
|
|
75 memcpy(test_element, &temp_elem, sizeof(TurnBased_QueueElem));
|
1332
|
76 }
|
2242
|
77 }
|
1332
|
78 }
|
2242
|
79 }
|
|
80 uActorQueueSize = active_actors;
|
|
81 if ( PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player) //we have player at queue top
|
|
82 {
|
|
83 uActiveCharacter = PID_ID(pQueue[0].uPackedID)+1;
|
|
84 field_18 |= TE_PLAYER_TURN;
|
|
85 }
|
|
86 else
|
|
87 {
|
|
88 uActiveCharacter = 0;
|
|
89 field_18 &= ~TE_PLAYER_TURN;
|
|
90 }
|
|
91 for ( i = 0; i < uActorQueueSize; ++i)
|
|
92 {
|
|
93 if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) //set recovery times
|
|
94 pParty->pPlayers[PID_ID(pQueue[i].uPackedID)].uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 0.46875);
|
|
95 }
|
|
96 }
|
1332
|
97 //----- (0040471C) --------------------------------------------------------
|
1448
|
98 void stru262_TurnBased::ApplyPlayerAction()
|
2242
|
99 {
|
|
100 if ( pParty->bTurnBasedModeOn == 1 )
|
|
101 {
|
|
102 if ( pTurnEngine->turn_stage == TE_ATTACK )
|
|
103 _406457(0);
|
|
104 }
|
|
105 }
|
1332
|
106
|
|
107 //----- (004059DB) --------------------------------------------------------
|
|
108 void stru262_TurnBased::Start()
|
2242
|
109 {
|
|
110 int v17; // edx@22
|
|
111 AIDirection v30; // [sp+Ch] [bp-68h]@10
|
|
112 AIDirection v31; // [sp+28h] [bp-4Ch]@10
|
|
113 AIDirection a3; // [sp+44h] [bp-30h]@10
|
|
114 int activ_players[4];
|
|
115 int players_recovery_time[4];
|
|
116 int a_players_count;
|
|
117 int i,j;
|
|
118 int temp;
|
1342
|
119
|
2242
|
120 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
|
|
121 pEventTimer->TrackGameTime();
|
|
122 pAudioPlayer->StopChannels(-1, -1);
|
|
123 pAudioPlayer->PlaySound(SOUND_207, 0, 0, -1, 0, 0, 0, 0);
|
|
124 //pPlayer = pParty->pPlayers.data();
|
|
125 dword_50C998_turnbased_icon_1A = 8 * pIconsFrameTable->pIcons[uIconID_TurnStart].uAnimLength;
|
|
126 dword_50C994 = 0;
|
1332
|
127
|
2242
|
128 this->turn_initiative = 100;
|
|
129 this->turns_count = 0;
|
|
130 this->ai_turn_timer = 64;
|
|
131 this->turn_stage = TE_WAIT;
|
|
132 this->uActorQueueSize = 0;
|
1332
|
133
|
2242
|
134 for ( uint pl_id = 0; pl_id < 4 ; ++pl_id )
|
|
135 {
|
|
136 if ( pParty->pPlayers[pl_id].CanAct() )
|
|
137 {
|
|
138 this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Player,pl_id);
|
|
139 this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
|
|
140 this->pQueue[this->uActorQueueSize].uActionLength = 0;
|
|
141 pParty->pTurnBasedPlayerRecoveryTimes[this->uActorQueueSize] = 0;
|
|
142 ++this->uActorQueueSize;
|
|
143 }
|
|
144 }
|
1332
|
145
|
2242
|
146 for ( int i = 0; i < ai_arrays_size ; ++i )
|
|
147 {
|
|
148 if (ai_near_actors_ids[i] == 10)
|
|
149 continue;
|
|
150 if ( pActors[ai_near_actors_ids[i]].CanAct() )
|
|
151 {
|
|
152 if ( pActors[ai_near_actors_ids[i]].uAttributes & 0x8000 )
|
|
153 {
|
|
154 pActors[ai_near_actors_ids[i]].uAttributes |= 0x80;
|
|
155 Actor::GetDirectionInfo(PID(OBJECT_Actor,ai_near_actors_ids[i]), ai_near_actors_targets_pid[ai_near_actors_ids[i]], &v31, 0);
|
|
156 memcpy(&v30, &v31, sizeof(AIDirection));
|
|
157 Actor::AI_StandOrBored(ai_near_actors_ids[i], 4, 32, &v30);
|
|
158 this->pQueue[this->uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[i]);
|
|
159 this->pQueue[this->uActorQueueSize].AI_action_type = TE_AI_PURSUE;
|
|
160 this->pQueue[this->uActorQueueSize].uActionLength = 0;
|
|
161 ++this->uActorQueueSize;
|
|
162 }
|
|
163 }
|
|
164 }
|
1332
|
165
|
2242
|
166 a_players_count = 0;
|
|
167 for ( int k = 0; k < this->uActorQueueSize; ++k )
|
|
168 {
|
|
169 //set initial initiative for turn actors
|
|
170 if ( PID_TYPE(this->pQueue[k].uPackedID) == OBJECT_Player )
|
|
171 {
|
|
172 if ( pPlayers[PID_ID(this->pQueue[k].uPackedID) + 1]->uTimeToRecovery != 0 )
|
|
173 this->pQueue[k].actor_initiative = (signed int)((double)pPlayers[PID_ID(this->pQueue[k].uPackedID) + 1]->uTimeToRecovery * 0.46875);
|
|
174 else
|
|
175 {
|
|
176 activ_players[a_players_count] = k;
|
|
177 ++a_players_count;
|
|
178 }
|
|
179 }
|
|
180 else if ( PID_TYPE(this->pQueue[k].uPackedID) == OBJECT_Actor )
|
|
181 {
|
|
182 v17 = rand() % 99;
|
|
183 if ( v17 < 33 )
|
|
184 this->pQueue[k].actor_initiative = 1;
|
|
185 else
|
|
186 this->pQueue[k].actor_initiative= (v17 >= 66)? 5 : 3;
|
|
187 }
|
|
188 else //fot non player and actor
|
|
189 this->pQueue[k].actor_initiative = 666;
|
|
190 this->pQueue[k].actor_initiative += 16;
|
|
191 }
|
|
192
|
|
193 if ( a_players_count > 0 )
|
|
194 {
|
|
195 for ( i = 0; i < a_players_count; ++i)
|
|
196 players_recovery_time[i] = pParty->pPlayers[PID_ID(this->pQueue[activ_players[i]].uPackedID)].GetAttackRecoveryTime(0);
|
|
197 //sort players by recovery time
|
|
198 for ( i = 0; i < a_players_count-1; ++i)
|
|
199 {
|
|
200 for ( j = i + 1; j < a_players_count; ++j )
|
|
201 {
|
|
202 if (players_recovery_time[j] < players_recovery_time[i]) //swap values
|
|
203 {
|
|
204 temp = players_recovery_time[i];
|
|
205 players_recovery_time[i] = players_recovery_time[j];
|
|
206 players_recovery_time[j] = temp;
|
|
207 temp = activ_players[i];
|
|
208 activ_players[i] = activ_players[j];
|
|
209 activ_players[j] = temp;
|
1332
|
210 }
|
2242
|
211 }
|
1332
|
212 }
|
2242
|
213 for ( i = 0; i < a_players_count; ++i)
|
|
214 this->pQueue[activ_players[i]].actor_initiative = i + 2;
|
|
215 }
|
|
216 this->SortTurnQueue();
|
|
217 }
|
1332
|
218
|
|
219 //----- (00405CFF) --------------------------------------------------------
|
|
220 void stru262_TurnBased::End(bool bPlaySound)
|
2242
|
221 {
|
|
222 ObjectType objType; // eax@13
|
|
223 int objID; // esi@13
|
|
224 int i;
|
1332
|
225
|
2242
|
226 this->turn_stage = TE_NONE;
|
|
227 for( i = 0; i < uActorQueueSize; ++i)
|
|
228 {
|
|
229 if ( PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor )
|
|
230 pActors[PID_ID(pQueue[i].uPackedID)].uAttributes &= ~0x80;
|
|
231 }
|
1332
|
232
|
2242
|
233 for( i = 0; i < uNumSpriteObjects; ++i)
|
|
234 {
|
|
235 if (pSpriteObjects[i].uAttributes & 4)
|
|
236 pSpriteObjects[i].uAttributes &= ~0x04;
|
|
237 }
|
1332
|
238
|
2242
|
239 for( i = 0; i < uActorQueueSize; ++i)
|
|
240 {
|
|
241 objType = (ObjectType)PID_TYPE(pQueue[i].uPackedID);
|
|
242 objID = PID_ID(pQueue[i].uPackedID);
|
|
243 if ( objType == OBJECT_Player )
|
|
244 pPlayers[objID + 1]->uTimeToRecovery = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
|
|
245 else if ( objType == OBJECT_Actor )
|
|
246 pActors[objID].pMonsterInfo.uRecoveryTime = (unsigned __int16)((double)pQueue[i].actor_initiative * 2.133333333333333);
|
|
247 }
|
|
248 pAudioPlayer->StopChannels(-1, -1);
|
|
249 if ( bPlaySound != 0 )
|
|
250 pAudioPlayer->PlaySound(SOUND_206, 0, 0, -1, 0, 0, 0, 0);
|
|
251 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
|
|
252 pEventTimer->StopGameTime();
|
|
253 dword_50C994 = 0;
|
|
254 dword_50C998_turnbased_icon_1A = 0;
|
|
255 }
|
1332
|
256 // 50C994: using guessed type int dword_50C994;
|
|
257 // 50C998: using guessed type int dword_50C998_turnbased_icon_1A;
|
|
258
|
|
259 //----- (00405E14) --------------------------------------------------------
|
1448
|
260 void stru262_TurnBased::AITurnBasedAction()
|
2242
|
261 {
|
|
262 AIDirection v6; // esi@21
|
|
263 AIDirection a3; // [sp+4h] [bp-68h]@21
|
|
264 AIDirection v14; // [sp+20h] [bp-4Ch]@21
|
|
265 AIDirection v15; // [sp+3Ch] [bp-30h]@21
|
|
266 Actor *curr_actor; // [sp+58h] [bp-14h]@2
|
|
267 int target_pid; // [sp+5Ch] [bp-10h]@6
|
|
268 int shrinked;
|
|
269 int i, j;
|
|
270
|
|
271 for (i = 0; i < uNumActors; ++i )
|
|
272 {
|
|
273 curr_actor=&pActors[i];
|
|
274 shrinked=pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime > 0;
|
|
275 for (j = 0; j < 22; ++j) //check expired spell Buffs
|
1332
|
276 {
|
2242
|
277 if (j != 10)
|
|
278 pActors[i].pActorBuffs[j].IsBuffExpiredToTime(pParty->uTimePlayed);
|
|
279 }
|
|
280 if (shrinked && pActors[i].pActorBuffs[ACTOR_BUFF_SHRINK].uExpireTime <= 0) //buff 3 expired
|
|
281 pActors[i].uActorHeight = pMonsterList->pMonsters[pActors[i].pMonsterInfo.uID - 1].uMonsterHeight;
|
|
282 if (!(curr_actor->uAttributes & 0x80) && (!curr_actor->pActorBuffs[ACTOR_BUFF_STONED].uExpireTime) &&
|
|
283 (!curr_actor->pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime))
|
|
284 {
|
|
285 curr_actor->uCurrentActionTime += pMiscTimer->uTimeElapsed;
|
|
286 if (curr_actor->uCurrentActionTime>=curr_actor->uCurrentActionLength)
|
|
287 {
|
|
288 target_pid = ai_near_actors_targets_pid[i];
|
|
289 Actor::GetDirectionInfo(PID(OBJECT_Actor,i), target_pid, &v6, 0);
|
|
290 memcpy(&v15, &v6, sizeof(AIDirection));
|
|
291 memcpy(&v14, &v15, sizeof(AIDirection));
|
|
292 if ( curr_actor->uAIState == Dying )
|
1332
|
293 {
|
2242
|
294 curr_actor->uCurrentActionTime = 0;
|
|
295 curr_actor->uCurrentActionLength = 0;
|
|
296 curr_actor->uAIState = Dead;
|
|
297 curr_actor->UpdateAnimation();
|
1340
|
298 }
|
2242
|
299 else if ( (curr_actor->uAIState > AIState::Removed) && (curr_actor->uAIState < AIState::Disabled))
|
|
300 Actor::AI_StandOrBored(i, target_pid, 32, &v14);
|
|
301 }
|
|
302 }
|
|
303 }
|
|
304 if ( turn_stage == TE_WAIT )
|
|
305 {
|
|
306 if ( ai_turn_timer == 64 )
|
|
307 ActorAISetMovementDecision();
|
|
308 else if ( ai_turn_timer > 0 )
|
|
309 ActorAIDoAdditionalMove();
|
|
310 else
|
|
311 {
|
|
312 ActorAIStopMovement();
|
|
313 turn_initiative = 100;
|
1332
|
314 }
|
2242
|
315 ai_turn_timer -= pEventTimer->uTimeElapsed;
|
|
316 }
|
|
317 else if ( turn_stage == TE_ATTACK )
|
|
318 {
|
|
319 if ( !(field_18 &TE_FLAG_1))
|
|
320 {
|
|
321 if ( turn_initiative == 100 )
|
|
322 {
|
|
323 StartTurn();
|
|
324 SetAIRecoveryTimes();
|
|
325 return;
|
|
326 }
|
|
327 if ( turn_initiative > 0 || pQueue[0].actor_initiative <= 0 )
|
|
328 {
|
|
329 _4065B0();
|
|
330 SetAIRecoveryTimes();
|
|
331 return;
|
|
332 }
|
|
333 }
|
|
334 NextTurn();
|
|
335 }
|
|
336 else if ( turn_stage == TE_MOVEMENT )
|
|
337 {
|
|
338 if ( (uActionPointsLeft > 0) && (!(field_18 & TE_FLAG_8)) )
|
|
339 ActorAIChooseNewTargets();
|
|
340 else
|
|
341 {
|
|
342 field_18 &= ~TE_FLAG_8;
|
|
343 turn_stage = TE_WAIT;
|
|
344 ai_turn_timer = 64;
|
|
345 }
|
|
346 }
|
|
347 }
|
1332
|
348
|
|
349
|
|
350 //----- (00406051) --------------------------------------------------------
|
2242
|
351 void stru262_TurnBased::StartTurn()
|
|
352 {
|
|
353 int player_num, actor_num, i, j;
|
1332
|
354
|
2242
|
355 pending_actions = 0;
|
|
356 //add player to queue if he can act
|
|
357 for ( player_num = 0; player_num < 4; ++player_num)
|
|
358 {
|
|
359 for ( j = 0; j < uActorQueueSize; ++j )
|
|
360 {
|
|
361 if (PID_TYPE(pQueue[j].uPackedID) == OBJECT_Player)
|
|
362 {
|
|
363 if (pPlayers[PID_ID(pQueue[j].uPackedID) + 1]->CanAct() && (player_num != PID_ID(pQueue[j].uPackedID)) )
|
|
364 break;
|
|
365 }
|
|
366 }
|
|
367 if ( j == uActorQueueSize )
|
|
368 {
|
|
369 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Player,player_num);
|
|
370 pQueue[uActorQueueSize].actor_initiative = 100;
|
|
371 pQueue[uActorQueueSize].uActionLength = 0;
|
|
372 pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
|
|
373 ++uActorQueueSize;
|
1332
|
374 }
|
2242
|
375 }
|
|
376 //add new arrived actors
|
|
377 for ( actor_num = 0; actor_num < ai_arrays_size; ++actor_num )
|
|
378 {
|
|
379 for ( j = 0; j < uActorQueueSize; ++j )
|
|
380 {
|
|
381 if ((PID_TYPE(pQueue[j].uPackedID)== OBJECT_Actor)&&
|
|
382 ai_near_actors_ids[actor_num] == PID_ID(pQueue[j].uPackedID))
|
|
383 break;
|
|
384 }
|
|
385 if ( j == uActorQueueSize )
|
|
386 {
|
|
387 pQueue[uActorQueueSize].uPackedID = PID(OBJECT_Actor,ai_near_actors_ids[actor_num]);
|
|
388 pQueue[uActorQueueSize].actor_initiative = 1;
|
|
389 pQueue[uActorQueueSize].uActionLength = 0;
|
|
390 pQueue[uActorQueueSize].AI_action_type = TE_AI_STAND;
|
|
391 ++uActorQueueSize;
|
|
392 }
|
|
393 }
|
|
394 ++turns_count;
|
|
395 turn_initiative = 100;
|
|
396 for ( i = 0; i < uActorQueueSize; ++i )
|
|
397 {
|
|
398 if (pQueue[i].actor_initiative == 0 )
|
|
399 pQueue[i].actor_initiative = 100;
|
|
400 }
|
|
401 StepTurnQueue();
|
|
402 for ( i = 0; i < uActorQueueSize; ++i )
|
|
403 {
|
|
404 if ((PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player) || (pQueue[i].actor_initiative > 0))
|
|
405 break;
|
|
406 AI_Action_(i);
|
|
407 }
|
|
408 }
|
1332
|
409 // 4F75D8: using guessed type int ai_arrays_size;
|
|
410
|
1341
|
411 //----- (004061CA) --------------------------------------------------------
|
|
412 void stru262_TurnBased::NextTurn()
|
2242
|
413 {
|
|
414 int v13; // [sp+10h] [bp-4h]@7
|
|
415 int monster_id; // eax@5
|
1341
|
416
|
2242
|
417 SortTurnQueue();
|
|
418 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
|
|
419 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
|
|
420 else
|
|
421 uActiveCharacter = 0;
|
|
422 viewparams->bRedrawGameUI = true;
|
1341
|
423
|
2242
|
424 if ( pending_actions )
|
|
425 {
|
|
426 pTurnEngine->field_18 |= TE_HAVE_PENDING_ACTIONS;
|
|
427 return;
|
|
428 }
|
|
429 pTurnEngine->field_18 &= ~TE_HAVE_PENDING_ACTIONS;
|
|
430 if ( pQueue[0].actor_initiative <= 0 )
|
|
431 return;
|
1332
|
432
|
2242
|
433 v13 = 0;
|
|
434 if (uActorQueueSize > 0 )
|
|
435 {
|
|
436 for ( int i = 0; i < uActorQueueSize; ++i )
|
|
437 {
|
|
438 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
|
|
439 {
|
|
440 monster_id = PID_ID(pQueue[i].uPackedID);
|
|
441 if ( (pActors[monster_id].uAIState == AIState::Dying) || (pActors[monster_id].uAIState == AIState::Stunned)
|
|
442 || (pActors[monster_id].uAIState == AIState::AttackingMelee) || (pActors[monster_id].uAIState == AIState::AttackingRanged1)
|
|
443 || (pActors[monster_id].uAIState == AIState::AttackingRanged2) || (pActors[monster_id].uAIState == AIState::AttackingRanged3)
|
|
444 || (pActors[monster_id].uAIState == AIState::AttackingRanged4) || (pActors[monster_id].uAIState ==AIState::Summoned))
|
|
445 {
|
|
446 pActors[monster_id].uCurrentActionTime += pEventTimer->uTimeElapsed;
|
|
447 if ( pActors[monster_id].uCurrentActionTime < pActors[monster_id].uCurrentActionLength )
|
|
448 v13 = 1;
|
|
449 else if ( pActors[monster_id].uAIState == AIState::Dying )// Dying
|
|
450 {
|
|
451 pActors[monster_id].uAIState = AIState::Dead;
|
|
452 pActors[monster_id].uCurrentActionTime = 0;
|
|
453 pActors[monster_id].uCurrentActionLength = 0;
|
|
454 pActors[monster_id].UpdateAnimation();
|
|
455 }
|
|
456 else
|
|
457 {
|
|
458 if ( pActors[monster_id].uAIState == AIState::Stunned ) //Stunned
|
|
459 Actor::AI_StandOrBored(monster_id, ai_near_actors_targets_pid[monster_id], 32, 0);
|
|
460 }
|
|
461 }
|
|
462 }
|
|
463 }
|
|
464 if ( v13 != 0 )
|
|
465 {
|
|
466 field_18 |= TE_FLAG_1;
|
|
467 return;
|
|
468 }
|
|
469 }
|
1332
|
470
|
2242
|
471 field_18 &= ~TE_FLAG_1;
|
|
472 //set all actors to stay
|
|
473 for ( int i = 0; i < uActorQueueSize; ++i )
|
|
474 {
|
|
475 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
|
|
476 {
|
|
477 monster_id = PID_ID(pQueue[i].uPackedID);
|
|
478 if ((pActors[monster_id].uAIState != AIState::Dead) && (pActors[monster_id].uAIState != AIState::Dying) &&
|
|
479 (pActors[monster_id].uAIState != AIState::Removed) && (pActors[monster_id].uAIState != AIState::Summoned) &&
|
|
480 (pActors[monster_id].uAIState != AIState::Disabled))
|
|
481 {
|
|
482 pQueue[i].uActionLength = 0;
|
|
483 Actor::AI_StandOrBored(monster_id, ai_near_actors_targets_pid[monster_id], 32, nullptr);
|
|
484 }
|
|
485 }
|
|
486 }
|
|
487 // turn tick
|
|
488 turn_stage = TE_MOVEMENT;
|
|
489 pParty->uTimePlayed += 213i64;
|
|
490 _494035_timed_effects__water_walking_damage__etc();
|
|
491 uActionPointsLeft = 130;
|
|
492 }
|
1332
|
493
|
2242
|
494 //----- (004063A1) --------------------------------------------------------
|
|
495 bool stru262_TurnBased::StepTurnQueue()
|
|
496 {
|
|
497 int v9; // dx@12
|
|
498 int j;
|
1332
|
499
|
2242
|
500 SortTurnQueue();
|
|
501 viewparams->bRedrawGameUI = 1;
|
|
502 if ( pQueue[0].actor_initiative != 0 )
|
|
503 {
|
|
504 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
|
|
505 {
|
|
506 do
|
|
507 {
|
|
508 for (j = 0; j < uActorQueueSize; ++j )
|
|
509 --pQueue[j].actor_initiative;
|
|
510 --turn_initiative;
|
|
511 if (turn_initiative == 0)
|
|
512 return true;
|
|
513 }
|
|
514 while (pQueue[0].actor_initiative != 0);
|
|
515 }
|
|
516 else
|
|
517 {
|
|
518 if ( pQueue[0].actor_initiative > 0 )
|
|
519 {
|
|
520 v9 = pActors[PID_ID(pQueue[0].uPackedID)].uAIState;
|
|
521 if (!(v9 == AIState::Dying || v9 == AIState::Dead ||
|
|
522 v9 == AIState::Disabled || v9 == AIState::Removed))
|
|
523 {
|
|
524 do
|
|
525 {
|
|
526 for ( j = 0; j < uActorQueueSize; ++j )
|
|
527 {
|
|
528 --pQueue[j].actor_initiative;
|
|
529 if (pQueue[j].actor_initiative == 0)
|
|
530 pQueue[j].uActionLength = 0;
|
|
531 }
|
|
532 --turn_initiative;
|
|
533 if (turn_initiative == 0)
|
|
534 return true;
|
|
535 }
|
|
536 while (pQueue[0].actor_initiative > 0);
|
|
537 }
|
|
538 }
|
|
539 }
|
|
540 }
|
|
541 return false;
|
|
542 }
|
1332
|
543
|
|
544 //----- (00406457) --------------------------------------------------------
|
1340
|
545 void stru262_TurnBased::_406457( int a2 )
|
2242
|
546 {
|
|
547 signed int v4; // ecx@2
|
|
548 signed int v6; // eax@2
|
|
549 int i;
|
|
550 v6 = 0;
|
|
551 if ( PID_TYPE(pQueue[a2].uPackedID) == OBJECT_Player)
|
|
552 {
|
|
553 v4 = PID_ID(pQueue[a2].uPackedID);
|
|
554 if ( pParty->pTurnBasedPlayerRecoveryTimes[v4] )
|
|
555 pParty->pTurnBasedPlayerRecoveryTimes[v4] = 0;
|
1332
|
556 else
|
2242
|
557 v6 = pPlayers[v4 + 1]->GetAttackRecoveryTime(0);
|
|
558 if ( v6 < 30 )
|
|
559 v6 = 30;
|
|
560 }
|
|
561 else
|
|
562 v6 = pMonsterStats->pInfos[pActors[PID_ID(pQueue[a2].uPackedID)].pMonsterInfo.uID].uRecoveryTime;
|
1340
|
563
|
2242
|
564 pQueue[a2].actor_initiative = v6;
|
|
565 SortTurnQueue();
|
|
566 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
|
|
567 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
|
|
568 else
|
|
569 uActiveCharacter = 0;
|
|
570 viewparams->bRedrawGameUI = 1;
|
|
571 while ( (pQueue[0].actor_initiative > 0) && (turn_initiative > 0) )
|
|
572 {
|
|
573 for ( i = 0; i < uActorQueueSize; ++i)
|
|
574 {
|
|
575 --pQueue[i].actor_initiative;
|
|
576 if (pQueue[i].actor_initiative == 0)
|
|
577 pQueue[i].uActionLength=0;
|
1332
|
578 }
|
2242
|
579 --turn_initiative;
|
|
580 }
|
|
581 }
|
1332
|
582
|
|
583 //----- (0040652A) --------------------------------------------------------
|
1448
|
584 void stru262_TurnBased::SetAIRecoveryTimes()
|
2242
|
585 {
|
|
586 int i;
|
|
587 int monster_ai_state;
|
|
588 Actor *monster; // eax@5
|
1332
|
589
|
2242
|
590 for ( i = 0; i < uActorQueueSize; ++i )
|
|
591 {
|
|
592 if (pQueue[i].actor_initiative == 0)
|
|
593 {
|
|
594 if(PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)
|
|
595 break;
|
|
596 monster=&pActors[PID_ID(pQueue[i].uPackedID)];
|
|
597 monster_ai_state=monster->uAIState;
|
|
598 if (monster_ai_state == AIState::Standing ||
|
|
599 monster_ai_state == AIState::Fleeing ||
|
|
600 monster_ai_state == AIState::Fidgeting)
|
|
601 {
|
|
602 pQueue[i].actor_initiative = pMonsterStats->pInfos[monster->pMonsterInfo.uID].uRecoveryTime;
|
|
603 if (monster->pActorBuffs[ACTOR_BUFF_SLOWED].uExpireTime > 0)
|
|
604 pQueue[i].actor_initiative*=2;
|
|
605 }
|
1340
|
606 }
|
2242
|
607 }
|
|
608 }
|
1332
|
609
|
|
610 //----- (004065B0) --------------------------------------------------------
|
|
611 void stru262_TurnBased::_4065B0()
|
1333
|
612 {
|
2242
|
613 int i;
|
1332
|
614
|
2242
|
615 SortTurnQueue();
|
|
616 if (pQueue[0].actor_initiative <= 0)
|
|
617 {
|
|
618 for ( i = 0; i < uActorQueueSize; ++i )
|
|
619 {
|
|
620 if ((PID_TYPE(pQueue[i].uPackedID) == OBJECT_Player)|| (pQueue[i].actor_initiative > 0) )
|
|
621 break;
|
|
622 if ((pQueue[i].uActionLength <= 0) && (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor))
|
|
623 AI_Action_(i);
|
|
624 }
|
|
625 }
|
|
626 else
|
|
627 {
|
|
628 StepTurnQueue();
|
|
629 if (PID_TYPE(pQueue[0].uPackedID) == OBJECT_Player)
|
|
630 uActiveCharacter = PID_ID(pQueue[0].uPackedID) + 1;
|
1333
|
631 else
|
2242
|
632 uActiveCharacter = 0;
|
|
633 viewparams->bRedrawGameUI = 1;
|
|
634 }
|
|
635 for ( i = 0; i < uActorQueueSize; ++i )
|
|
636 AIAttacks(i);
|
1333
|
637 }
|
1332
|
638
|
|
639 //----- (00406648) --------------------------------------------------------
|
1448
|
640 void stru262_TurnBased::AIAttacks( unsigned int queue_index )
|
1546
|
641 {
|
2242
|
642 //TurnBased_QueueElem *v1; // ecx@1
|
|
643 //int v3; // eax@1
|
|
644 unsigned int actor_id; // ebx@2
|
|
645 //Actor *v5; // esi@2
|
|
646 char v19; // al@24
|
|
647 AIDirection a3; // [sp+Ch] [bp-3Ch]@2
|
|
648 AIDirection a4; // [sp+28h] [bp-20h]@2
|
|
649 //TurnBased_QueueElem *v28; // [sp+44h] [bp-4h]@1
|
|
650 //unsigned int a2a; // [sp+50h] [bp+8h]@2
|
1332
|
651
|
2242
|
652 //v1 = &pQueue[queue_index];
|
|
653 //v28 = v1;
|
|
654 //v3 = pQueue[queue_index].uPackedID;
|
|
655 if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
|
|
656 {
|
|
657 actor_id = PID_ID(pQueue[queue_index].uPackedID);
|
|
658 //a2a = ai_near_actors_targets_pid[v4];
|
|
659 Actor::GetDirectionInfo(pQueue[queue_index].uPackedID, ai_near_actors_targets_pid[actor_id], &a3, 0);
|
|
660 memcpy(&a4, &a3, sizeof(a4));
|
|
661 //v5 = &pActors[v4];
|
|
662 //LOWORD(v3) = v5->uAIState;
|
|
663 if (( pActors[actor_id].uAIState != AIState::Dead ) && ( pActors[actor_id].uAIState != AIState::Disabled )
|
|
664 &&( pActors[actor_id].uAIState != AIState::Removed ))
|
|
665 {
|
|
666 pActors[actor_id].uCurrentActionTime += pEventTimer->uTimeElapsed;
|
|
667 if ( (signed int)pActors[actor_id].uCurrentActionTime >= pActors[actor_id].uCurrentActionLength )
|
|
668 {
|
|
669 switch (pActors[actor_id].uAIState)
|
1332
|
670 {
|
2242
|
671 case AIState::AttackingMelee:
|
|
672 v19 = pActors[actor_id].special_ability_use_check(actor_id);
|
|
673 AttackerInfo.Add( pQueue[queue_index].uPackedID, 5120, pActors[actor_id].vPosition.x, pActors[actor_id].vPosition.y,
|
|
674 pActors[actor_id].vPosition.z + ((signed int)pActors[actor_id].uActorHeight >> 1), v19, 1);
|
|
675 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4);
|
|
676 break;
|
|
677 case AIState::AttackingRanged1:
|
|
678 Actor::AI_RangedAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uMissleAttack1Type, 0);
|
|
679 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
|
|
680 break;
|
|
681 case AIState::Dying:
|
|
682 pActors[actor_id].uCurrentActionTime = 0;
|
|
683 pActors[actor_id].uCurrentActionLength = 0;
|
|
684 pActors[actor_id].uAIState = Dead;
|
|
685 pActors[actor_id].UpdateAnimation();
|
|
686 break;
|
|
687 case AIState::Stunned:
|
|
688 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
|
|
689 break;
|
|
690 case AIState::AttackingRanged2:
|
|
691 Actor::AI_RangedAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uMissleAttack2Type, 1);
|
|
692 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0,&a4);
|
|
693 break;
|
|
694 case AIState::AttackingRanged3:
|
|
695 Actor::AI_SpellAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uSpell1ID, 2, pActors[actor_id].pMonsterInfo.uSpellSkillAndMastery1);
|
|
696 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4);
|
|
697 break;
|
|
698 case AIState::AttackingRanged4:
|
|
699 Actor::AI_SpellAttack(actor_id, &a4, pActors[actor_id].pMonsterInfo.uSpell2ID, 3, pActors[actor_id].pMonsterInfo.uSpellSkillAndMastery2);
|
|
700 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 0, &a4);
|
|
701 break;
|
|
702 default:
|
|
703 if ( !(rand() % 2) )
|
|
704 Actor::AI_Bored(actor_id, ai_near_actors_targets_pid[actor_id], &a4);
|
|
705 else
|
|
706 Actor::AI_Stand(actor_id, ai_near_actors_targets_pid[actor_id], 64,&a4);
|
1343
|
707 }
|
2242
|
708 }
|
1332
|
709 }
|
2242
|
710 }
|
|
711 }
|
2059
|
712 // 50FE08: using guessed type stru298 AttackerInfo;
|
1332
|
713
|
|
714 //----- (0040680F) --------------------------------------------------------
|
1450
|
715 void stru262_TurnBased::AI_Action_( int queue_index )
|
2242
|
716 {
|
|
717 //TurnBased_QueueElem *v2; // eax@1
|
|
718 //unsigned int v3; // eax@1
|
|
719 unsigned int actor_id; // edi@2
|
|
720 //Actor *v5; // ebx@2
|
|
721 AIDirection v7; // esi@10
|
|
722 //int v8; // eax@10
|
|
723 int v9; // ecx@10
|
|
724 signed int v10; // eax@13
|
|
725 int v14; // eax@29
|
|
726 AIDirection a3; // [sp+Ch] [bp-44h]@10
|
|
727 AIDirection v18; // [sp+28h] [bp-28h]@10
|
|
728 //int a2a; // [sp+44h] [bp-Ch]@2
|
|
729 //int v20; // [sp+48h] [bp-8h]@10
|
|
730 //TurnBased_QueueElem *v21; // [sp+4Ch] [bp-4h]@1
|
|
731 signed int v22; // [sp+58h] [bp+8h]@10
|
1367
|
732
|
2242
|
733 //v2 = &pQueue[queue_index];
|
|
734 //v21 = v2;
|
|
735 pQueue[queue_index].uActionLength = 0;
|
|
736 //v3 = pQueue[queue_index].uPackedID;
|
|
737 if (PID_TYPE(pQueue[queue_index].uPackedID) == OBJECT_Actor)
|
|
738 {
|
|
739 actor_id = PID_ID(pQueue[queue_index].uPackedID);
|
|
740 //a2a = pQueue[queue_index].uPackedID;
|
|
741 //v5 = &pActors[actor_id];
|
|
742 //v3 = v5->uAIState;
|
|
743 if (!(pActors[actor_id].uAIState == AIState::Dying || pActors[actor_id].uAIState == AIState::Dead || pActors[actor_id].uAIState == AIState::Summoned ||
|
|
744 pActors[actor_id].uAIState == AIState::Disabled || pActors[actor_id].uAIState == AIState::Removed))
|
|
745 {
|
|
746 Actor::_SelectTarget(actor_id, &ai_near_actors_targets_pid[actor_id], true);
|
|
747 v22 = ai_near_actors_targets_pid[actor_id];
|
|
748 if ( pActors[actor_id].pMonsterInfo.uHostilityType && !v22)
|
|
749 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
|
|
750 Actor::GetDirectionInfo(PID(OBJECT_Actor,actor_id), v22, &v7, 0);
|
|
751 //v8 = pActors[actor_id].uActorRadius;
|
|
752 memcpy(&a3, &v7, sizeof(AIDirection));
|
|
753 memcpy(&v18, &a3, sizeof(AIDirection));
|
|
754 v9 = a3.uDistance - pActors[actor_id].uActorRadius;
|
|
755 //v20 = a3.uDistance - pActors[actor_id].uActorRadius;
|
|
756 if ( v9 < 0 )
|
|
757 {
|
|
758 v9 = 0;
|
|
759 //v20 = 0;
|
|
760 }
|
|
761 if (PID_TYPE(v22) == OBJECT_Actor)
|
|
762 //v10 = (unsigned __int8)*(&byte_5C8D1A[89 * (pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID - 1) / 3] + (v5->pMonsterInfo.uID - 1) / 3);
|
|
763 v10 = pFactionTable->relations[(pMonsterStats->pInfos[pActors[PID_ID(v22)].pMonsterInfo.uID].uID) / 3 + 1][(pActors[actor_id].pMonsterInfo.uID - 1) / 3 + 1];
|
|
764 else
|
|
765 v10 = 4;
|
|
766 switch (v10)
|
|
767 {
|
|
768 case 1:
|
|
769 if ( (double)(signed int)v9 < 307.2 )
|
|
770 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
771 break;
|
|
772 case 2:
|
|
773 if ( v9 < 1024 )
|
|
774 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
775 break;
|
|
776 case 3:
|
|
777 if ( v9 < 2560 )
|
|
778 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
779 break;
|
|
780 case 4:
|
|
781 if ( v9 < 5120 )
|
|
782 pActors[actor_id].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
783 break;
|
|
784 }
|
|
785 if ( pActors[actor_id].pMonsterInfo.uHostilityType == 4 && v22 && (signed int)v9 < 5120 )
|
|
786 {
|
|
787 v14 = pActors[actor_id].special_ability_use_check(actor_id);
|
|
788 pQueue[queue_index].AI_action_type = TE_AI_STAND;
|
|
789 switch (v14)
|
|
790 {
|
|
791 case 1:
|
|
792 if ( pActors[actor_id].pMonsterInfo.uMissleAttack2Type )
|
|
793 {
|
|
794 Actor::AI_MissileAttack2(actor_id, v22, &v18);
|
|
795 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
|
1367
|
796 }
|
2242
|
797 break;
|
|
798 case 2:
|
|
799 if ( pActors[actor_id].pMonsterInfo.uSpell1ID )
|
|
800 {
|
|
801 Actor::AI_SpellAttack1(actor_id, v22, &v18);
|
|
802 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
|
|
803 }
|
|
804 break;
|
|
805 case 3:
|
|
806 if (pActors[actor_id].pMonsterInfo.uSpell2ID)
|
|
807 {
|
|
808 Actor::AI_SpellAttack2(actor_id, v22, &v18);
|
|
809 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
|
|
810 }
|
|
811 break;
|
|
812 default:
|
|
813 if ( pActors[actor_id].pMonsterInfo.uMissleAttack1Type )
|
|
814 {
|
|
815 Actor::AI_MissileAttack1(actor_id, v22, &v18);
|
|
816 pQueue[queue_index].AI_action_type = TE_AI_RANGED_ATTACK;
|
|
817 }
|
1367
|
818 }
|
2242
|
819 if (!pQueue[queue_index].AI_action_type)
|
|
820 if ( (double)v9 < 307.2)
|
|
821 {
|
|
822 Actor::AI_MeleeAttack(actor_id, v22, &v18);
|
|
823 pQueue[queue_index].AI_action_type = TE_AI_MELEE_ATTACK;
|
|
824 }
|
|
825 else
|
|
826 {
|
|
827 Actor::AI_Stand(actor_id, v22, 64, &v18);
|
|
828 pQueue[queue_index].AI_action_type = TE_AI_STAND;
|
|
829 }
|
|
830 }
|
|
831 else
|
|
832 {
|
|
833 Actor::AI_Stand(actor_id, v22, 64, &v18);
|
|
834 pQueue[queue_index].AI_action_type = TE_AI_STAND;
|
|
835 }
|
|
836 pQueue[queue_index].uActionLength = pActors[actor_id].uCurrentActionLength;
|
1332
|
837 }
|
2242
|
838 }
|
|
839 }
|
1332
|
840
|
|
841 //----- (00406A63) --------------------------------------------------------
|
1450
|
842 void stru262_TurnBased::ActorAISetMovementDecision()
|
2242
|
843 {
|
|
844 AIDirection a3; // [sp+8h] [bp-44h]@5
|
|
845 AIDirection v7; // [sp+24h] [bp-28h]@5
|
|
846 unsigned int target_pid; // [sp+40h] [bp-Ch]@5
|
|
847 int i;
|
1332
|
848
|
2242
|
849 this->ai_turn_timer = 64;
|
|
850 dword_50C994 = 0;
|
|
851 uActiveCharacter = 0;
|
|
852 for ( i = 0; i < uActorQueueSize; ++i )
|
|
853 {
|
|
854 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
|
|
855 {
|
|
856 target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
|
|
857 Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
|
|
858 if ( !ActorMove(i) )
|
|
859 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
|
1332
|
860 }
|
2242
|
861 }
|
|
862 }
|
1332
|
863 // 50C994: using guessed type int dword_50C994;
|
|
864
|
|
865 //----- (00406AFE) --------------------------------------------------------
|
1450
|
866 void stru262_TurnBased::ActorAIStopMovement()
|
2242
|
867 {
|
|
868 AIDirection a3; // [sp+4h] [bp-48h]@5
|
|
869 AIDirection v7; // [sp+20h] [bp-2Ch]@5
|
|
870 unsigned int target_pid;
|
|
871 int i;
|
1332
|
872
|
2242
|
873 for ( i = 0; i < uActorQueueSize; ++i )
|
|
874 {
|
|
875 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
|
|
876 {
|
|
877 target_pid = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
|
|
878 Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v7, 0);
|
|
879 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), target_pid, 32, &v7);
|
|
880 pQueue[i].AI_action_type = TE_AI_STAND;
|
|
881 pQueue[i].uActionLength = 0;
|
1332
|
882 }
|
2242
|
883 }
|
|
884 turn_stage = TE_ATTACK;
|
|
885 ai_turn_timer = 100;
|
|
886 }
|
1332
|
887
|
|
888 //----- (00406B9F) --------------------------------------------------------
|
1450
|
889 void stru262_TurnBased::ActorAIDoAdditionalMove()
|
2242
|
890 {
|
|
891 AIDirection a3; // [sp+0h] [bp-50h]@15
|
|
892 AIDirection v9; // [sp+1Ch] [bp-34h]@15
|
|
893 unsigned int v13; // [sp+44h] [bp-Ch]@8
|
|
894 unsigned int monster_id;
|
|
895
|
|
896 for ( int i = 0; i < uActorQueueSize; ++i )
|
|
897 {
|
|
898 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
|
1332
|
899 {
|
2242
|
900 monster_id = PID_ID(pQueue[i].uPackedID);
|
|
901 if ( !(pActors[monster_id].pActorBuffs[ACTOR_BUFF_STONED].uExpireTime > 0|| (pActors[monster_id].pActorBuffs[ACTOR_BUFF_PARALYZED].uExpireTime > 0) ||
|
|
902 pActors[monster_id].uAIState == AIState::Dead || pActors[monster_id].uAIState == AIState::Removed || pActors[monster_id].uAIState == AIState::Disabled) )
|
|
903 {
|
|
904 v13 = ai_near_actors_targets_pid[PID_ID(pQueue[i].uPackedID)];
|
|
905 Actor::GetDirectionInfo(pQueue[i].uPackedID, v13, &v9, 0);
|
|
906 if ( pActors[monster_id].uAIState == AIState::Pursuing || pActors[monster_id].uAIState == AIState::Tethered )
|
1332
|
907 {
|
2242
|
908 if ( (double)(signed int)v9.uDistance < 307.2 )
|
|
909 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
|
|
910 }
|
|
911 else
|
|
912 {
|
|
913 pActors[monster_id].uCurrentActionTime += pEventTimer->uTimeElapsed;
|
|
914 if ( pActors[monster_id].uCurrentActionTime > pActors[monster_id].uCurrentActionLength )
|
|
915 {
|
|
916 if ( pActors[monster_id].uAIState == AIState::Dying )
|
1332
|
917 {
|
2242
|
918 pActors[monster_id].uCurrentActionTime = 0;
|
|
919 pActors[monster_id].uCurrentActionLength = 0;
|
|
920 pActors[monster_id].uAIState = AIState::Dead;
|
|
921 pActors[monster_id].UpdateAnimation();
|
1332
|
922 }
|
2242
|
923 if ( !ActorMove(i) )
|
|
924 Actor::AI_Stand(PID_ID(pQueue[i].uPackedID), v13, 32, &v9);
|
|
925 }
|
1332
|
926 }
|
2242
|
927 }
|
1332
|
928 }
|
2242
|
929 }
|
|
930 }
|
1332
|
931
|
|
932 //----- (00406D10) --------------------------------------------------------
|
1450
|
933 bool stru262_TurnBased::ActorMove(signed int queue_position)
|
2242
|
934 {
|
|
935 //int v2; // ecx@1
|
|
936 //int v3; // ecx@2
|
|
937 //Actor *actor; // ebx@2
|
|
938 AIDirection v9; // esi@10
|
|
939 //int v10; // eax@10
|
|
940 int v11; // ecx@10
|
|
941 unsigned __int8 pHostileType; // al@12
|
|
942 AIDirection a3; // [sp+Ch] [bp-48h]@10
|
|
943 AIDirection pDir; // [sp+28h] [bp-2Ch]@10
|
|
944 //int v28; // [sp+48h] [bp-Ch]@10
|
|
945 //TurnBased_QueueElem *v29; // [sp+4Ch] [bp-8h]@7
|
|
946 unsigned int uActorID; // [sp+50h] [bp-4h]@2
|
|
947 //unsigned int a2a; // [sp+5Ch] [bp+8h]@7
|
1448
|
948
|
2242
|
949 // __debugbreak();//ñðàáàòûâàåò ïðè ïîøàãîâîì ðåæèìå ïîñëå ïÿòè øàãîâ
|
|
950 //v2 = pQueue[queue_position].uPackedID;
|
|
951 if (PID_TYPE(pQueue[queue_position].uPackedID) == OBJECT_Player)
|
|
952 return 0;
|
|
953 uActorID = PID_ID(pQueue[queue_position].uPackedID);
|
|
954 //uActorID = v3;
|
|
955 //actor = &pActors[uActorID];
|
|
956 //v5 = v4->uAIState;
|
|
957 if ( pActors[uActorID].uAIState == AIState::Dead || pActors[uActorID].uAIState == AIState::Dying ||
|
|
958 pActors[uActorID].uAIState == AIState::Removed|| pActors[uActorID].uAIState == AIState::Disabled ||
|
|
959 pActors[uActorID].uAIState == AIState::Summoned )
|
|
960 return 1;
|
|
961 //v29 = &pTurnEngine->pQueue[queue_position];
|
|
962 //a2a = ai_near_actors_targets_pid[uActorID];
|
|
963 Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
|
|
964 if ( pActors[uActorID].pMonsterInfo.uHostilityType && !ai_near_actors_targets_pid[uActorID] )
|
|
965 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Friendly;
|
|
966 Actor::GetDirectionInfo(pQueue[queue_position].uPackedID, ai_near_actors_targets_pid[uActorID], &v9, 0);
|
|
967 //v10 = pActors[uActorID].uActorRadius;
|
|
968 memcpy(&a3, &v9, sizeof(AIDirection));
|
|
969 memcpy(&pDir, &a3, sizeof(AIDirection));
|
|
970 v11 = a3.uDistance - pActors[uActorID].uActorRadius;
|
|
971 //v28 = a3.uDistance - pActors[uActorID].uActorRadius;
|
|
972 if ( v11 < 0 )
|
|
973 {
|
|
974 v11 = 0;
|
|
975 //v28 = 0;
|
|
976 }
|
|
977 pHostileType = pActors[uActorID].pMonsterInfo.uHostilityType;
|
|
978 switch (pHostileType)
|
|
979 {
|
|
980 case 1:
|
|
981 if ( (double)v11 < 307.2 )
|
|
982 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
983 break;
|
|
984 case 2:
|
|
985 if ( v11 < 1024 )
|
|
986 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
987 break;
|
|
988 case 3:
|
|
989 if ( v11 < 2560 )
|
|
990 pActors[uActorID].pMonsterInfo.uHostilityType = MonsterInfo::Hostility_Long;
|
|
991 break;
|
|
992 }
|
|
993 if ( pActors[uActorID].pActorBuffs[ACTOR_BUFF_AFRAID].uExpireTime > 0 )
|
|
994 {
|
|
995 if (v11 < 10240 )
|
|
996 {
|
|
997 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 0, &pDir);
|
|
998 pTurnEngine->pQueue[queue_position].AI_action_type = 4;
|
|
999 }
|
|
1000 else
|
|
1001 {
|
|
1002 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 1024, 0);
|
|
1003 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE;
|
|
1004 }
|
|
1005 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
|
|
1006 return true;
|
|
1007 }
|
|
1008 if ( pActors[uActorID].pMonsterInfo.uHostilityType == MonsterInfo::Hostility_Long )
|
|
1009 {
|
|
1010 if ( !(pActors[uActorID].uAttributes & 0x020000) || pActors[uActorID].pMonsterInfo.uAIType == 1 )
|
|
1011 {
|
|
1012 if ( pActors[uActorID].pMonsterInfo.uAIType == 1 )
|
|
1013 {
|
|
1014 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
|
|
1015 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1016 else
|
|
1017 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1018 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE;
|
|
1019 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
|
|
1020 return true;
|
|
1021 }
|
|
1022 if ( pActors[uActorID].pMonsterInfo.uAIType == 2 )
|
|
1023 {
|
|
1024 if (((double)pActors[uActorID].pMonsterInfo.uHP * 0.2) > (double)pActors[uActorID].sCurrentHP && (v11 < 10240 ) )
|
1332
|
1025 {
|
2242
|
1026 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
|
|
1027 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1028 else
|
|
1029 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1030 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE;
|
|
1031 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
|
|
1032 return true;
|
|
1033 }
|
|
1034 }
|
|
1035 if ( pActors[uActorID].pMonsterInfo.uAIType == 3 )
|
|
1036 {
|
|
1037 if ( ((double)pActors[uActorID].pMonsterInfo.uHP * 0.1) > (double)pActors[uActorID].sCurrentHP && (v11 < 10240 ))
|
|
1038 {
|
|
1039 if ( pActors[uActorID].pMonsterInfo.uMovementType == MONSTER_MOVEMENT_TYPE_STAIONARY )
|
|
1040 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1041 else
|
|
1042 Actor::AI_Flee(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1043 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_FLEE;
|
|
1044 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
|
|
1045 return true;
|
1332
|
1046 }
|
2242
|
1047 }
|
|
1048 }
|
|
1049 if ( (double)(signed int)v11 < 307.2 )
|
|
1050 return 0;
|
1332
|
1051 if ( (signed int)v11 < 5120 )
|
2242
|
1052 {
|
|
1053 if ( pActors[uActorID].pMonsterInfo.uMissleAttack1Type && (signed int)v11 < 1024 )
|
|
1054 Actor::AI_Pursue1(uActorID, ai_near_actors_targets_pid[uActorID], uActorID, 32, &pDir);
|
|
1055 else
|
|
1056 Actor::AI_Pursue2(uActorID, ai_near_actors_targets_pid[uActorID], 32, &pDir, 307);
|
|
1057 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE;
|
|
1058 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
|
|
1059 return true;
|
1332
|
1060 }
|
2242
|
1061 }
|
|
1062 switch(pActors[uActorID].pMonsterInfo.uMovementType)
|
|
1063 {
|
|
1064 case MONSTER_MOVEMENT_TYPE_SHORT:
|
|
1065 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 1024, 32);
|
|
1066 break;
|
|
1067 case MONSTER_MOVEMENT_TYPE_MEDIUM:
|
|
1068 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 2560, 32);
|
|
1069 break;
|
|
1070 case MONSTER_MOVEMENT_TYPE_LONG:
|
|
1071 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 5120, 32);
|
|
1072 break;
|
|
1073 case MONSTER_MOVEMENT_TYPE_FREE:
|
|
1074 Actor::AI_RandomMove(uActorID, ai_near_actors_targets_pid[uActorID], 10240, 32);
|
|
1075 break;
|
|
1076 case MONSTER_MOVEMENT_TYPE_STAIONARY:
|
|
1077 Actor::AI_Stand(uActorID, ai_near_actors_targets_pid[uActorID], 32, 0);
|
|
1078 break;
|
|
1079 default:
|
|
1080 return true;
|
|
1081 }
|
|
1082 pTurnEngine->pQueue[queue_position].AI_action_type = TE_AI_PURSUE;
|
|
1083 pTurnEngine->pQueue[queue_position].uActionLength = pActors[uActorID].uCurrentActionLength;
|
|
1084 return true;
|
|
1085 }
|
1332
|
1086
|
1367
|
1087 //----- (00406FA8) --------------------------------------------------------
|
1450
|
1088 void stru262_TurnBased::ActorAIChooseNewTargets()
|
2242
|
1089 {
|
|
1090 Actor *curr_acror; // ebx@4
|
|
1091 AIDirection a3; // [sp+Ch] [bp-6Ch]@8
|
|
1092 AIDirection v9; // [sp+28h] [bp-50h]@8
|
|
1093 AIDirection a4; // [sp+44h] [bp-34h]@8
|
|
1094 unsigned int target_pid; // [sp+60h] [bp-18h]@1
|
|
1095 int uActorID; // [sp+68h] [bp-10h]@4
|
|
1096 int i;
|
|
1097
|
|
1098 for ( i = 0; i < uActorQueueSize; ++i )
|
|
1099 {
|
|
1100 if (PID_TYPE(pQueue[i].uPackedID) == OBJECT_Actor)
|
1332
|
1101 {
|
2242
|
1102 uActorID=PID_ID(pQueue[i].uPackedID);
|
|
1103 curr_acror = &pActors[uActorID];
|
|
1104 if ( !( curr_acror->uAIState == AIState::Summoned|| curr_acror->uAIState == AIState::Dead ||
|
|
1105 curr_acror->uAIState == AIState::Removed || curr_acror->uAIState == AIState::Disabled) )
|
|
1106 {
|
|
1107 target_pid = ai_near_actors_targets_pid[uActorID];
|
|
1108 Actor::_SelectTarget(uActorID, &ai_near_actors_targets_pid[uActorID], true);
|
|
1109 Actor::GetDirectionInfo(pQueue[i].uPackedID, target_pid, &v9, 0);
|
|
1110 memcpy(&a4, &v9, sizeof(AIDirection));
|
|
1111 curr_acror->uCurrentActionTime += pEventTimer->uTimeElapsed;
|
|
1112 if ( curr_acror->uCurrentActionTime > curr_acror->uCurrentActionLength )
|
1332
|
1113 {
|
2242
|
1114 if ( curr_acror->uAIState == AIState::Dying )
|
|
1115 {
|
|
1116 curr_acror->uCurrentActionTime = 0;
|
|
1117 curr_acror->uCurrentActionLength = 0;
|
|
1118 curr_acror->uAIState = AIState::Dead;
|
|
1119 curr_acror->UpdateAnimation();
|
|
1120 break;
|
|
1121 }
|
|
1122 if ( rand() % 2 )
|
|
1123 Actor::AI_Stand(uActorID, target_pid, 64, &a4);
|
|
1124 else
|
|
1125 Actor::AI_Bored(uActorID, target_pid, &a4);
|
1332
|
1126 }
|
2242
|
1127 }
|
1332
|
1128 }
|
2242
|
1129 }
|
|
1130 }
|
1332
|
1131
|