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