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