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