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