| 1 | /* |
| 2 | * Descent 3 |
| 3 | * Copyright (C) 2024 Parallax Software |
| 4 | * |
| 5 | * This program is free software: you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation, either version 3 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | // AIGame3.cpp |
| 20 | // 0.1 |
| 21 | #include <stdio.h> |
| 22 | #include <stdlib.h> |
| 23 | #include <string.h> |
| 24 | #include "osiris_import.h" |
| 25 | #include "osiris_common.h" |
| 26 | #include "osiris_vector.h" |
| 27 | #include "DallasFuncs.cpp" |
| 28 | |
| 29 | #include "AIGame3_External.h" |
| 30 | |
| 31 | #include "module.h" |
| 32 | #include "psrand.h" |
| 33 | |
| 34 | #ifdef __cplusplus |
| 35 | extern "C" { |
| 36 | #endif |
| 37 | DLLEXPORT char STDCALL InitializeDLL(tOSIRISModuleInit *func_list); |
| 38 | DLLEXPORT void STDCALL ShutdownDLL(void); |
| 39 | DLLEXPORT int STDCALL GetGOScriptID(const char *name, uint8_t isdoor); |
| 40 | DLLEXPORT void STDCALLPTR CreateInstance(int id); |
| 41 | DLLEXPORT void STDCALL DestroyInstance(int id, void *ptr); |
| 42 | DLLEXPORT int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data); |
| 43 | DLLEXPORT int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state); |
| 44 | #ifdef __cplusplus |
| 45 | } |
| 46 | #endif |
| 47 | |
| 48 | static int String_table_size = 0; |
| 49 | static char **String_table = NULL; |
| 50 | static const char *_Error_string = "!!ERROR MISSING STRING!!"; |
| 51 | static const char *_Empty_string = ""; |
| 52 | const char *GetStringFromTable(int index) { |
| 53 | if ((index < 0) || (index >= String_table_size)) |
| 54 | return _Error_string; |
| 55 | if (!String_table[index]) |
| 56 | return _Empty_string; |
| 57 | return String_table[index]; |
| 58 | } |
| 59 | #define TXT(x) GetStringFromTable(x) |
| 60 | |
| 61 | //------------------- |
| 62 | // Function prototypes |
| 63 | //------------------- |
| 64 | |
| 65 | static int TurnOnSpew(int objref, int gunpoint, int effect_type, float mass, float drag, int gravity_type, uint8_t isreal, |
| 66 | float lifetime, float interval, float longevity, float size, float speed, uint8_t random); |
| 67 | // Returns the new child's handle |
| 68 | static int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap, |
| 69 | bool f_aligned = true, bool f_set_parent = false); |
| 70 | |
| 71 | static int FindClosestPlayer(int objhandle); |
| 72 | |
| 73 | // Returns true if object current has an active Dallas low priority goal |
| 74 | static bool HasLowPriorityGoal(int obj_handle); |
| 75 | |
| 76 | // Returns true if object current has an active Dallas high priority goal |
| 77 | static bool HasHighPriorityGoal(int obj_handle); |
| 78 | |
| 79 | // Wipes out all goals except slots 0 and 3 (used by Dallas) |
| 80 | static void SafeGoalClearAll(int obj_handle); |
| 81 | |
| 82 | static void AI_SafeSetType(int obj_handle, int ai_type); |
| 83 | |
| 84 | //---------------- |
| 85 | // Name lookups |
| 86 | //---------------- |
| 87 | |
| 88 | // Name lookup globals |
| 89 | static uint16_t energy_effect_id; // weapon ID for the energy charge effect |
| 90 | static uint16_t frag_burst_effect_id; // weapon ID for the frag burst effect |
| 91 | static uint16_t boss_frag_burst_id; // weapon ID for the boss frag burst effect |
| 92 | static uint16_t transfer_effect_id; // texture ID for the energy transfer lightning effect |
| 93 | static uint16_t heal_effect_id; // texture ID for the heal lightning effect |
| 94 | static uint16_t boss_heal_effect_id; // texture ID for the boss heal lightning effect |
| 95 | static uint16_t tractor_beam_effect_id; // texture ID for the tractor beam effect |
| 96 | static uint16_t alien_organism_id; // object type ID for the alien organism robot |
| 97 | static uint16_t shield_blast_id; // weapon ID for the HT shield blast effect |
| 98 | static uint16_t ht_grenade_id; // weapon ID for the HT grenade |
| 99 | static uint16_t ht_grenade_effect_id; // weapon ID for the HT grenade launch effect |
| 100 | static uint16_t lifter_blast_effect_id; // weapon ID for the lifter blast effect |
| 101 | static uint16_t lifter_stick_effect_id; // texture ID for lifter's night-stick lightning effect |
| 102 | static uint16_t teleport_effect_id; // weapon ID for teleporting effect |
| 103 | |
| 104 | static uint16_t ht_grenade_sound_id; // sound ID for firing the grenade |
| 105 | |
| 106 | static uint16_t powerup_id; // invisible powerup id |
| 107 | |
| 108 | static uint16_t boss_flapping_id; // flapping sound id |
| 109 | static uint16_t boss_turf_id; // turf id |
| 110 | static uint16_t boss_see_id; |
| 111 | static uint16_t boss_hurt_id; |
| 112 | |
| 113 | static uint16_t lifter_pull_sound_id; |
| 114 | static uint16_t lifter_amb_sound_id; |
| 115 | |
| 116 | // ========================== |
| 117 | // AI Goal Related Functions |
| 118 | // ========================== |
| 119 | |
| 120 | #define DALLAS_LOW_PRIORITY_GOAL_SLOT 0 |
| 121 | #define DALLAS_HIGH_PRIORITY_GOAL_SLOT 3 |
| 122 | |
| 123 | // Returns true if object current has an active Dallas low priority goal |
| 124 | bool HasLowPriorityGoal(int obj_handle) { |
| 125 | bool used; |
| 126 | AI_GoalValue(obj_handle, DALLAS_LOW_PRIORITY_GOAL_SLOT, VF_GET, AIGV_B_USED, &used); |
| 127 | |
| 128 | return used; |
| 129 | } |
| 130 | |
| 131 | // Returns true if object current has an active Dallas high priority goal |
| 132 | bool HasHighPriorityGoal(int obj_handle) { |
| 133 | bool used; |
| 134 | AI_GoalValue(obj_handle, DALLAS_HIGH_PRIORITY_GOAL_SLOT, VF_GET, AIGV_B_USED, &used); |
| 135 | |
| 136 | return used; |
| 137 | } |
| 138 | |
| 139 | // Returns True if given index implies that a goal is finished |
| 140 | static inline bool IsGoalFinishedNotify(int index) { |
| 141 | return (index == AIN_GOAL_COMPLETE || index == AIN_GOAL_INVALID || index == AIN_GOAL_FAIL || index == AIN_GOAL_ERROR); |
| 142 | } |
| 143 | |
| 144 | // Wipes out all goals except slots 0 and 3 (used by Dallas) |
| 145 | void SafeGoalClearAll(int obj_handle) { |
| 146 | int i; |
| 147 | |
| 148 | for (i = 0; i < MAX_GOALS; i++) { |
| 149 | if (i != DALLAS_LOW_PRIORITY_GOAL_SLOT && i != DALLAS_HIGH_PRIORITY_GOAL_SLOT) { |
| 150 | AI_ClearGoal(obj_handle, i); |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Works like AI_SetType(), but won't clear out Dallas' goal slots 0 or 3 |
| 156 | void AI_SafeSetType(int obj_handle, int ai_type) { |
| 157 | float aware = AWARE_BARELY; |
| 158 | float time = 25.0f; |
| 159 | |
| 160 | SafeGoalClearAll(obj_handle); |
| 161 | |
| 162 | switch (ai_type) { |
| 163 | case AIT_STALKER: { |
| 164 | vector goal_pos; |
| 165 | int goal_room; |
| 166 | |
| 167 | Obj_Value(obj_handle, VF_GET, OBJV_V_POS, &goal_pos); |
| 168 | Obj_Value(obj_handle, VF_GET, OBJV_I_ROOMNUM, &goal_room); |
| 169 | |
| 170 | AI_AddGoal(obj_handle, AIG_WANDER_AROUND, 1, 1.0f, -1, GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION, &goal_pos, |
| 171 | goal_room); |
| 172 | } break; |
| 173 | |
| 174 | case AIT_EVADER2: { |
| 175 | vector goal_pos; |
| 176 | int goal_room; |
| 177 | float size, circle_distance; |
| 178 | |
| 179 | Obj_Value(obj_handle, VF_GET, OBJV_V_POS, &goal_pos); |
| 180 | Obj_Value(obj_handle, VF_GET, OBJV_I_ROOMNUM, &goal_room); |
| 181 | Obj_Value(obj_handle, VF_GET, OBJV_F_SIZE, &size); |
| 182 | AI_Value(obj_handle, VF_GET, AIV_F_CIRCLE_DIST, &circle_distance); |
| 183 | |
| 184 | AI_AddGoal(obj_handle, AIG_GUARD_AREA, 1, 1.0f, -1, GF_NONFLUSHABLE, &goal_pos, goal_room); |
| 185 | AI_SetGoalCircleDist(obj_handle, 1, size * 2.0f); |
| 186 | AI_GoalAddEnabler(obj_handle, 1, AIE_GT_AWARENESS, 1.0, 0.0, &aware); |
| 187 | AI_GoalAddEnabler(obj_handle, 1, AIE_LTE_LAST_SEE_TARGET_INTERVAL, 1.0, 0.0, &time); |
| 188 | |
| 189 | int gi = AI_AddGoal(obj_handle, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 3.0f, -1, |
| 190 | GF_NONFLUSHABLE | GF_OBJ_IS_TARGET, OBJECT_HANDLE_NONE); |
| 191 | AI_GoalAddEnabler(obj_handle, gi, AIE_NEAR, 1.0, 0.0, &circle_distance); |
| 192 | AI_SetGoalCircleDist(obj_handle, gi, circle_distance); |
| 193 | } break; |
| 194 | |
| 195 | case AIT_EVADER1: { |
| 196 | float circle_distance; |
| 197 | AI_Value(obj_handle, VF_GET, AIV_F_CIRCLE_DIST, &circle_distance); |
| 198 | |
| 199 | AI_AddGoal(obj_handle, AIG_MOVE_RELATIVE_OBJ, 1, 1.0f, -1, GF_OBJ_IS_TARGET | GF_SPEED_ATTACK | GF_NONFLUSHABLE, |
| 200 | OBJECT_HANDLE_NONE); |
| 201 | AI_GoalAddEnabler(obj_handle, 1, AIE_GT_AWARENESS, 1.0, 0.0, &aware); |
| 202 | AI_GoalAddEnabler(obj_handle, 1, AIE_LTE_LAST_SEE_TARGET_INTERVAL, 1.0, 0.0, &time); |
| 203 | |
| 204 | if (circle_distance > 0.0f) { |
| 205 | int gi = AI_AddGoal(obj_handle, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 3.0f, -1, |
| 206 | GF_NONFLUSHABLE | GF_OBJ_IS_TARGET, OBJECT_HANDLE_NONE); |
| 207 | |
| 208 | float temp = circle_distance * 0.55f; |
| 209 | AI_GoalAddEnabler(obj_handle, gi, AIE_NEAR, 1.0, 0.0, &temp); |
| 210 | AI_SetGoalCircleDist(obj_handle, gi, circle_distance * 0.55f); |
| 211 | } |
| 212 | } break; |
| 213 | |
| 214 | case AIT_MELEE1: { |
| 215 | int flags = AISR_MELEE; |
| 216 | int m_goal; |
| 217 | |
| 218 | AI_AddGoal(obj_handle, AIG_MOVE_RELATIVE_OBJ, 1, 1.0f, -1, |
| 219 | GF_NONFLUSHABLE | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION, OBJECT_HANDLE_NONE); |
| 220 | AI_GoalAddEnabler(obj_handle, 1, AIE_GT_AWARENESS, 1.0, 0.0, &aware); |
| 221 | AI_GoalAddEnabler(obj_handle, 1, AIE_LTE_LAST_SEE_TARGET_INTERVAL, 1.0, 0.0, &time); |
| 222 | |
| 223 | AI_AddGoal(obj_handle, AIG_GET_TO_OBJ, 2, 1.0f, -1, |
| 224 | GF_SPEED_ATTACK | GF_NONFLUSHABLE | GF_OBJ_IS_TARGET | GF_USE_BLINE_IF_SEES_GOAL | GF_KEEP_AT_COMPLETION, |
| 225 | OBJECT_HANDLE_NONE); |
| 226 | AI_GoalAddEnabler(obj_handle, 2, AIE_AI_STATUS_FLAG, 1.0, 0.0, &flags); |
| 227 | AI_SetGoalCircleDist(obj_handle, 2, -100.0f); |
| 228 | AI_GoalAddEnabler(obj_handle, 2, AIE_GT_AWARENESS, 1.0, 0.0, &aware); |
| 229 | AI_GoalAddEnabler(obj_handle, 2, AIE_LTE_LAST_SEE_TARGET_INTERVAL, 1.0, 0.0, &time); |
| 230 | |
| 231 | m_goal = AI_AddGoal(obj_handle, AIG_MELEE_TARGET, ACTIVATION_BLEND_LEVEL, 1.0f, -1, |
| 232 | GF_NONFLUSHABLE | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION, OBJECT_HANDLE_NONE); |
| 233 | AI_GoalAddEnabler(obj_handle, m_goal, AIE_GT_AWARENESS, 1.0, 0.0, &aware); |
| 234 | AI_GoalAddEnabler(obj_handle, m_goal, AIE_LTE_LAST_SEE_TARGET_INTERVAL, 1.0, 0.0, &time); |
| 235 | } break; |
| 236 | |
| 237 | case AIT_BIRD_FLOCK1: { |
| 238 | } break; |
| 239 | |
| 240 | case AIT_HERD1: { |
| 241 | } break; |
| 242 | |
| 243 | case AIT_STATIONARY_TURRET: |
| 244 | break; |
| 245 | |
| 246 | case AIT_AIS: |
| 247 | break; |
| 248 | |
| 249 | case AIT_FLYLANDER: |
| 250 | break; |
| 251 | |
| 252 | default: { |
| 253 | mprintf(0, "Invalid AI type passed into AI_SafeSetType()\n"); |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
| 258 | // ============================ |
| 259 | // Miscellaneous Utility Funcs |
| 260 | // ============================ |
| 261 | |
| 262 | int TurnOnSpew(int objref, int gunpoint, int effect_type, float mass, float drag, int gravity_type, uint8_t isreal, |
| 263 | float lifetime, float interval, float longevity, float size, float speed, uint8_t random) { |
| 264 | msafe_struct mstruct; |
| 265 | |
| 266 | mstruct.objhandle = objref; |
| 267 | mstruct.gunpoint = gunpoint; |
| 268 | mstruct.effect_type = effect_type; |
| 269 | mstruct.mass = mass; |
| 270 | mstruct.drag = drag; |
| 271 | mstruct.phys_info = gravity_type; |
| 272 | mstruct.is_real = isreal; |
| 273 | mstruct.lifetime = lifetime; |
| 274 | mstruct.interval = interval; |
| 275 | mstruct.longevity = longevity; |
| 276 | mstruct.size = size; |
| 277 | mstruct.speed = speed; |
| 278 | mstruct.random = (random) ? SPEW_RAND_SIZE | SPEW_RAND_LIFETIME | SPEW_RAND_SPEED : 0; |
| 279 | |
| 280 | MSafe_CallFunction(MSAFE_OBJECT_START_SPEW, &mstruct); |
| 281 | |
| 282 | return mstruct.id; |
| 283 | } |
| 284 | |
| 285 | // Returns the new child's handle |
| 286 | int CreateAndAttach(int me, const char *child_name, uint8_t child_type, char parent_ap, char child_ap, bool f_aligned, |
| 287 | bool f_set_parent) { |
| 288 | int child_handle = OBJECT_HANDLE_NONE; |
| 289 | int child_id = Obj_FindID(child_name); |
| 290 | msafe_struct m; |
| 291 | m.objhandle = me; |
| 292 | MSafe_GetValue(MSAFE_OBJECT_POS, &m); |
| 293 | MSafe_GetValue(MSAFE_OBJECT_ROOMNUM, &m); |
| 294 | |
| 295 | if (child_id >= 0) { |
| 296 | int parent; |
| 297 | if (f_set_parent) |
| 298 | parent = me; |
| 299 | else |
| 300 | parent = OBJECT_HANDLE_NONE; |
| 301 | |
| 302 | child_handle = Obj_Create(child_type, child_id, m.roomnum, &m.pos, NULL, parent); |
| 303 | if (child_handle != OBJECT_HANDLE_NONE) { |
| 304 | if (!Obj_AttachObjectAP(me, parent_ap, child_handle, child_ap, f_aligned)) { |
| 305 | // chrishack (we need a way to instantly kill scripted objects) |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | return child_handle; |
| 311 | } |
| 312 | |
| 313 | int FindClosestPlayer(int objhandle) { |
| 314 | vector objpos, playerpos; |
| 315 | float closest_dist = FLT_MAX; |
| 316 | int closest_player = OBJECT_HANDLE_NONE; |
| 317 | msafe_struct mstruct; |
| 318 | |
| 319 | // Get the object position |
| 320 | mstruct.objhandle = objhandle; |
| 321 | MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct); |
| 322 | objpos = mstruct.pos; |
| 323 | |
| 324 | // Loop though all possible players and compute distance |
| 325 | for (int p = 0; p < MAX_PLAYERS; p++) { |
| 326 | |
| 327 | // Get player position |
| 328 | mstruct.slot = p; |
| 329 | MSafe_GetValue(MSAFE_OBJECT_PLAYER_HANDLE, &mstruct); |
| 330 | |
| 331 | // See if this player active |
| 332 | if (mstruct.objhandle == OBJECT_HANDLE_NONE) |
| 333 | continue; |
| 334 | |
| 335 | // Get the target position |
| 336 | MSafe_GetValue(MSAFE_OBJECT_POS, &mstruct); |
| 337 | |
| 338 | // Get the normalized vector from the source to the target |
| 339 | float dist = vm_VectorDistanceQuick(&objpos, &mstruct.pos); |
| 340 | |
| 341 | if (dist < closest_dist) { |
| 342 | closest_dist = dist; |
| 343 | closest_player = mstruct.objhandle; |
| 344 | } |
| 345 | } |
| 346 | |
| 347 | return closest_player; |
| 348 | } |
| 349 | |
| 350 | // ================== |
| 351 | // Clear Shot System |
| 352 | // ================== |
| 353 | |
| 354 | // Clear shot constants |
| 355 | #define MAX_SCAN_SHOT_OBJECTS 30 |
| 356 | #define MAX_SHOT_PATH_POSITIONS 256 |
| 357 | |
| 358 | // Reasons why not a clear shot |
| 359 | #define CS_ALL_CLEAR 0 |
| 360 | #define CS_SHOOTER_IN_WAY 1 |
| 361 | #define CS_FRIEND_IN_WAY 2 |
| 362 | #define CS_NO_ENEMY 3 |
| 363 | #define CS_NO_PATH 4 |
| 364 | |
| 365 | // Shot data structure |
| 366 | struct tShotData { |
| 367 | int object_handle; // IN: the object taking the shot |
| 368 | vector start_point; // IN: the starting point of the shot |
| 369 | int start_room; // IN: the room that the starting point is in |
| 370 | vector dir; // IN: the direction the shot is aimed |
| 371 | float max_dist; // IN: the maximum distance of the shot |
| 372 | float shot_radius; // IN: the radius of the projectile (used for the ray thickness) |
| 373 | float danger_radius; // IN: the initial danger radius for the scans |
| 374 | float radius_inc; // IN: the danger radius increase multiplier |
| 375 | float risk_factor; // IN: the amount of risk a robot is willing to take |
| 376 | }; |
| 377 | |
| 378 | // Shot scan position data structure |
| 379 | struct tShotPathPositionData { |
| 380 | int num_friends; // Number of friends found at this path position |
| 381 | int num_enemies; // Number of enemies found at this path position |
| 382 | int num_neutrals; // Number of neutrals found at this path position |
| 383 | bool contains_shooter; // Whether or not this path position contains the shooter |
| 384 | float path_dist; // The shot path distance of this scan position from the start |
| 385 | float scan_radius; // The radius of the scan that was done at this shot position |
| 386 | }; |
| 387 | |
| 388 | // Clear shot globals |
| 389 | static tShotPathPositionData ShotPathPositions[MAX_SHOT_PATH_POSITIONS]; |
| 390 | static int num_shot_path_positions; |
| 391 | |
| 392 | static bool ScanShotPathPosition(int obj_handle, vector *pos, int room, float radius, float dist); |
| 393 | static float TraverseShotPath(tShotData *shot_data); |
| 394 | static int ShotIsClear(float risk_factor); |
| 395 | static int HasClearShot(tShotData *shot_data); |
| 396 | |
| 397 | // Scans area around given shot position for object data |
| 398 | bool ScanShotPathPosition(int obj_handle, vector *pos, int room, float radius, float dist) { |
| 399 | int scan_objs[MAX_SCAN_SHOT_OBJECTS]; |
| 400 | int n_scan; |
| 401 | int n, i; |
| 402 | int type; |
| 403 | |
| 404 | // Make sure there is still a shot scan position available |
| 405 | if (num_shot_path_positions >= MAX_SHOT_PATH_POSITIONS) { |
| 406 | return false; |
| 407 | } |
| 408 | |
| 409 | // Init this shot path position's data |
| 410 | n = num_shot_path_positions; |
| 411 | ShotPathPositions[n].contains_shooter = false; |
| 412 | ShotPathPositions[n].path_dist = dist; |
| 413 | ShotPathPositions[n].scan_radius = radius; |
| 414 | ShotPathPositions[n].num_enemies = 0; |
| 415 | ShotPathPositions[n].num_friends = 0; |
| 416 | ShotPathPositions[n].num_neutrals = 0; |
| 417 | |
| 418 | // Scan for any nearby objects |
| 419 | // NOTE: check the func below to see what other params do!!! |
| 420 | n_scan = AI_GetNearbyObjs(pos, room, radius, scan_objs, MAX_SCAN_SHOT_OBJECTS, false, true, false, true); |
| 421 | |
| 422 | // Go through the objects that have been found and store tallies |
| 423 | for (i = 0; i < n_scan; i++) { |
| 424 | Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type); |
| 425 | if (type == OBJ_ROBOT || type == OBJ_PLAYER) { |
| 426 | // Make sure it's not cloaked |
| 427 | if (qObjectCloakTime(scan_objs[i]) == 0.0f) { |
| 428 | // Tallie the object accordingly |
| 429 | if (scan_objs[i] == obj_handle) { |
| 430 | // It's the shooter |
| 431 | ShotPathPositions[n].contains_shooter = true; |
| 432 | } else if (AI_IsObjEnemy(obj_handle, scan_objs[i])) { |
| 433 | // It's an enemy |
| 434 | ShotPathPositions[n].num_enemies++; |
| 435 | } else if (AI_IsObjFriend(obj_handle, scan_objs[i])) { |
| 436 | // It's a friend |
| 437 | ShotPathPositions[n].num_friends++; |
| 438 | } else { |
| 439 | // It's a neutral |
| 440 | ShotPathPositions[n].num_neutrals++; |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | } |
| 445 | num_shot_path_positions++; |
| 446 | |
| 447 | return true; |
| 448 | } |
| 449 | |
| 450 | // Traverses the straight-line shot path and gathers object data |
| 451 | float TraverseShotPath(tShotData *shot_data) { |
| 452 | float next_scan_dist, scan_radius; |
| 453 | float current_path_dist, dist; |
| 454 | vector start_pos, end_pos, target_pos; |
| 455 | vector shot_dir; |
| 456 | int start_room, end_room; |
| 457 | int flags, fate; |
| 458 | ray_info ray; |
| 459 | bool done, max_distance_reached; |
| 460 | |
| 461 | // Clear out any existing shot scan positions |
| 462 | num_shot_path_positions = 0; |
| 463 | |
| 464 | // Setup the shot's starting data |
| 465 | start_pos = shot_data->start_point; |
| 466 | start_room = shot_data->start_room; |
| 467 | shot_dir = shot_data->dir; |
| 468 | next_scan_dist = shot_data->danger_radius; |
| 469 | scan_radius = shot_data->danger_radius; |
| 470 | |
| 471 | // Start scanning |
| 472 | current_path_dist = 0.0f; |
| 473 | max_distance_reached = false; |
| 474 | done = false; |
| 475 | |
| 476 | while (!done) { |
| 477 | // Check the max shot distance |
| 478 | if ((current_path_dist + next_scan_dist) >= shot_data->max_dist) { |
| 479 | next_scan_dist = shot_data->max_dist - current_path_dist; |
| 480 | max_distance_reached = true; |
| 481 | } |
| 482 | |
| 483 | // Calculate shot's target position |
| 484 | target_pos = start_pos + (shot_dir * next_scan_dist); |
| 485 | |
| 486 | // Cast a ray to see if a wall or any clutter objects lie in the target path |
| 487 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 488 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 489 | fate = |
| 490 | FVI_RayCast(shot_data->object_handle, &start_pos, &target_pos, start_room, shot_data->shot_radius, flags, &ray); |
| 491 | |
| 492 | // Store the ray hit point and room |
| 493 | end_pos = ray.hit_point; |
| 494 | end_room = ray.hit_room; |
| 495 | |
| 496 | // If necessary, calculate the distance from start point to the hit point |
| 497 | if (fate == HIT_NONE) { |
| 498 | dist = next_scan_dist; |
| 499 | } else { |
| 500 | dist = vm_VectorDistance(&start_pos, &end_pos); |
| 501 | } |
| 502 | |
| 503 | // Add the new distance to our total shot path distance |
| 504 | current_path_dist += dist; |
| 505 | |
| 506 | // If it hit a wall, change the direction (perfect reflection) |
| 507 | if (fate == HIT_WALL) { |
| 508 | // Calculate the bounce dir from the current dir and face normal |
| 509 | vector new_dir = (-2.0f * (shot_dir * ray.hit_wallnorm)) * ray.hit_wallnorm + shot_dir; |
| 510 | shot_dir = new_dir; |
| 511 | |
| 512 | // Now, if necessary, cast another ray to finish off the scan dist |
| 513 | next_scan_dist -= dist; |
| 514 | if (next_scan_dist > 0.0f) { |
| 515 | start_pos = end_pos; |
| 516 | start_room = end_room; |
| 517 | continue; |
| 518 | } |
| 519 | } |
| 520 | |
| 521 | // Do an object scan at this point |
| 522 | if (!ScanShotPathPosition(shot_data->object_handle, &end_pos, end_room, scan_radius, current_path_dist)) { |
| 523 | done = true; |
| 524 | continue; |
| 525 | } |
| 526 | |
| 527 | // Obj_Create(OBJ_WEAPON, energy_effect_id, end_room, &end_pos, NULL, shot_data->object_handle); |
| 528 | |
| 529 | // If max distance was reached or we hit a clutter object, we're done |
| 530 | if (max_distance_reached || fate == HIT_OBJECT) { |
| 531 | done = true; |
| 532 | continue; |
| 533 | } |
| 534 | |
| 535 | // Update data for next run |
| 536 | next_scan_dist = scan_radius * 2.0f; |
| 537 | scan_radius *= shot_data->radius_inc; |
| 538 | start_pos = end_pos; |
| 539 | start_room = end_room; |
| 540 | } |
| 541 | |
| 542 | return true; |
| 543 | } |
| 544 | |
| 545 | // Analyzes data to determine if shot is clear |
| 546 | int ShotIsClear(float risk_factor) { |
| 547 | int j; |
| 548 | |
| 549 | if (num_shot_path_positions == 0) |
| 550 | return CS_NO_PATH; |
| 551 | |
| 552 | // If final shot path position contains shooter, don't shoot! |
| 553 | if (ShotPathPositions[num_shot_path_positions - 1].contains_shooter) |
| 554 | return CS_SHOOTER_IN_WAY; |
| 555 | |
| 556 | for (j = 0; j < num_shot_path_positions; j++) { |
| 557 | // Check and see if shooter is in the way (ok if it's the first position) |
| 558 | if (ShotPathPositions[j].contains_shooter && j != 0) |
| 559 | return CS_SHOOTER_IN_WAY; |
| 560 | |
| 561 | // Check if there are any friendlies or neutrals in the way |
| 562 | if ((ShotPathPositions[j].num_friends + ShotPathPositions[j].num_neutrals) > 0) |
| 563 | return CS_FRIEND_IN_WAY; |
| 564 | |
| 565 | // Check if any enemies are in the way |
| 566 | if (ShotPathPositions[j].num_enemies > 0 && !ShotPathPositions[j].contains_shooter) |
| 567 | return CS_ALL_CLEAR; |
| 568 | } |
| 569 | |
| 570 | return CS_NO_ENEMY; |
| 571 | } |
| 572 | |
| 573 | // Checks to see if object has a clear shot |
| 574 | int HasClearShot(tShotData *shot_data) { |
| 575 | // Traverse the shot trajectory, gathering data |
| 576 | TraverseShotPath(shot_data); |
| 577 | |
| 578 | // Analyze the shot data |
| 579 | return (ShotIsClear(shot_data->risk_factor)); |
| 580 | } |
| 581 | |
| 582 | // ========================== |
| 583 | // Script class definitions |
| 584 | // ========================== |
| 585 | #define NUM_IDS 6 // maximum number of IDs |
| 586 | |
| 587 | #define ID_ALIENORGANISM 1 // Alien organism robot |
| 588 | #define ID_HEAVYTROOPER 2 // CED Heavy Trooper robot |
| 589 | #define ID_LIFTER 3 // Lifter robot |
| 590 | #define ID_ALIENBOSS 4 // Alien Mini-boss |
| 591 | #define ID_SECURITYCAMERA 5 // Security Camera |
| 592 | #define ID_CROWDCONTROL 6 // Crowd Control for Merc6 Barges |
| 593 | |
| 594 | struct tScriptInfo { |
| 595 | int id; |
| 596 | const char *name; |
| 597 | }; |
| 598 | |
| 599 | static tScriptInfo ScriptInfo[NUM_IDS] = { |
| 600 | {ID_ALIENORGANISM, "AlienOrganism"}, {ID_HEAVYTROOPER, "HeavyTrooper"}, {ID_LIFTER, "Lifter"}, |
| 601 | {ID_ALIENBOSS, "AlienBoss"}, {ID_SECURITYCAMERA, "SecurityCamera"}, {ID_CROWDCONTROL, "CrowdControl"}}; |
| 602 | |
| 603 | class BaseObjScript { |
| 604 | public: |
| 605 | BaseObjScript(); |
| 606 | ~BaseObjScript(); |
| 607 | virtual int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 608 | }; |
| 609 | |
| 610 | // Priority Constants |
| 611 | #define LOW_PRIORITY 0 |
| 612 | #define MEDIUM_PRIORITY 1 |
| 613 | #define HIGH_PRIORITY 2 |
| 614 | |
| 615 | //--------------------- |
| 616 | // AlienOrganism class |
| 617 | //--------------------- |
| 618 | |
| 619 | // Alien Mode Types |
| 620 | #define ALIEN_LANDED 0 |
| 621 | #define ALIEN_LANDED_RESTING 1 |
| 622 | #define ALIEN_LANDED_HEALING 2 |
| 623 | #define ALIEN_LANDED_DEPOSITING 3 |
| 624 | #define ALIEN_LANDED_WITHDRAWING 4 |
| 625 | |
| 626 | #define ALIEN_LANDING_AT_HOME 10 |
| 627 | #define ALIEN_GOING_HOME 11 |
| 628 | #define ALIEN_FLEEING 12 |
| 629 | #define ALIEN_FINDING_BIRTHPLACE 13 |
| 630 | #define ALIEN_GIVING_BIRTH 14 |
| 631 | |
| 632 | #define ALIEN_HUNTING 20 |
| 633 | #define ALIEN_SCAVENGING 21 |
| 634 | |
| 635 | #define ALIEN_ATTACKING_MELEE 31 |
| 636 | #define ALIEN_ATTACKING_RANGED 32 |
| 637 | |
| 638 | #define ALIEN_MODE_NONE 50 |
| 639 | |
| 640 | // General Alien Constants |
| 641 | #define ALIEN_MEMORY_ID 4 |
| 642 | #define ALIEN_TYPE_NAME "AlienOrganism" |
| 643 | |
| 644 | #define ALIEN_MAX_ENERGY_CHARGES 20.0f |
| 645 | #define ALIEN_ENERGY_SUCK_CHARGE 20.0f |
| 646 | #define ALIEN_ENERGY_BOLT_COST 2.0f |
| 647 | |
| 648 | #define ALIEN_HEAL_PERCENTAGE 0.50f |
| 649 | #define ALIEN_LANDED_ACTION_TIME 2.0f |
| 650 | |
| 651 | #define ALIEN_BEAM_UPDATE_TIME 0.5f |
| 652 | #define ALIEN_SQUAD_RECRUIT_RADIUS 100.0f |
| 653 | |
| 654 | #define ALIEN_MAX_TAKEOFF_TIME 0.7f |
| 655 | |
| 656 | // Alien Lookup Names |
| 657 | #define ALIEN_ENERGY_EFFECT_NAME "AlienEnergyEffect" |
| 658 | #define ALIEN_TRANSFER_EFFECT_NAME "FunkyEffect1" |
| 659 | #define ALIEN_HEAL_EFFECT_NAME "FunkyEffectGreen" |
| 660 | |
| 661 | // Alien Flee Constants |
| 662 | #define ALIEN_ON_FIRE_FLEE_CHANCE 80 |
| 663 | #define ALIEN_NEAR_FIRE_FLEE_CHANCE 25 |
| 664 | #define ALIEN_SQUADIE_FLEE_SAVING_THROW 5 |
| 665 | #define ALIEN_LEADER_FLEE_SAVING_THROW 10 |
| 666 | |
| 667 | // Alien goal complete IDs |
| 668 | #define ALIEN_GUID_GOT_HOME 0x10100001 |
| 669 | #define ALIEN_GUID_LANDED 0x10100002 |
| 670 | #define ALIEN_GUID_FOUND_BIRTHPLACE 0x10100003 |
| 671 | #define ALIEN_GUID_RAN_AWAY 0x10100004 |
| 672 | #define ALIEN_GUID_GOT_TO_DEST_OBJ 0x10100005 |
| 673 | |
| 674 | // Alien Communication IDs |
| 675 | #define ALIEN_COM_JOIN_ME 0 |
| 676 | #define ALIEN_COM_LEAVE_ME 1 |
| 677 | #define ALIEN_COM_PROTECT_ME 2 |
| 678 | #define ALIEN_COM_BREAK_AND_ATTACK 3 |
| 679 | #define ALIEN_COM_REGROUP 4 |
| 680 | #define ALIEN_COM_SET_MODE 5 |
| 681 | #define ALIEN_COM_SET_PENDING_MODE 6 |
| 682 | #define ALIEN_COM_GET_MODE 7 |
| 683 | #define ALIEN_COM_SET_SQUAD_FLAGS 8 |
| 684 | #define ALIEN_COM_CLEAR_SQUAD_FLAGS 9 |
| 685 | |
| 686 | #define ALIEN_COM_REQUEST_LEAVE 10 |
| 687 | #define ALIEN_COM_LEAVING_YOU 11 |
| 688 | #define ALIEN_COM_GET_GOAL_POS 12 |
| 689 | #define ALIEN_COM_GET_GOAL_ROOM 13 |
| 690 | #define ALIEN_COM_I_WAS_HIT 14 |
| 691 | #define ALIEN_COM_CAN_YOU_SEE_ME 15 |
| 692 | #define ALIEN_COM_LEAVE_ME_FOR_MODE 16 |
| 693 | |
| 694 | // Squad Constants |
| 695 | #define ALIEN_MAX_TEAMMATES 2 |
| 696 | #define ALIEN_CATCHUP_DIST 4.0f |
| 697 | #define ALIEN_APPROACH_DIST 10.0f |
| 698 | #define ALIEN_ENGAGE_DIST 200.0f |
| 699 | #define ALIEN_BREAKUP_DIST 50.0f |
| 700 | #define ALIEN_REGROUP_DIST 120.0f |
| 701 | |
| 702 | // Alien Squad Flags |
| 703 | #define ALIEN_LEADER 0x01 |
| 704 | #define ALIEN_SQUADIE 0x02 |
| 705 | #define ALIEN_CATCHUP 0x04 |
| 706 | #define ALIEN_BROKEN 0x08 |
| 707 | |
| 708 | // Energy Beam Flags |
| 709 | #define ALIEN_BEAM1 0x01 |
| 710 | #define ALIEN_BEAM2 0x02 |
| 711 | #define ALIEN_BEAM3 0x04 |
| 712 | |
| 713 | // Auto avoid friends distances |
| 714 | #define ALIEN_NORMAL_AVOID_DIST 4.0f |
| 715 | #define ALIEN_SQUAD_AVOID_DIST 0.0f |
| 716 | |
| 717 | // Circle Distance (also for avoiding friends) |
| 718 | #define ALIEN_SQUAD_CIRC_DIST_MOD 0.4f |
| 719 | |
| 720 | // Formation Offset Constants |
| 721 | #define ALIEN_FO_HUNT_RVEC 8.0f |
| 722 | #define ALIEN_FO_HUNT_FVEC 10.0f |
| 723 | #define ALIEN_FO_SCAV_RVEC 3.0f |
| 724 | #define ALIEN_FO_SCAV_FVEC 15.0f |
| 725 | #define ALIEN_FO_ATTK_RVEC 7.0f |
| 726 | #define ALIEN_FO_ATTK_UVECP 7.0f |
| 727 | #define ALIEN_FO_ATTK_UVECN 5.0f |
| 728 | #define ALIEN_FO_ATTK_FVEC 3.0f |
| 729 | |
| 730 | // Speed Modifier Constants |
| 731 | #define ALIEN_ENGAGE_SPEED_MOD 1.4f |
| 732 | #define ALIEN_ATTACK_SPEED_MOD 1.8f |
| 733 | #define ALIEN_RETURN_SPEED_MOD 1.0f |
| 734 | #define ALIEN_LAND_SPEED_MOD 0.5f |
| 735 | #define ALIEN_HUNT_SPEED_MOD 1.0f |
| 736 | #define ALIEN_SCAV_SPEED_MOD 0.7f |
| 737 | #define ALIEN_FLEE_SPEED_MOD 2.0f |
| 738 | |
| 739 | #define ALIEN_CATCHUP_SPEED_MOD 0.23f |
| 740 | #define ALIEN_SQUADIE_INTERVAL 0.25f |
| 741 | |
| 742 | // Teammate data struct |
| 743 | struct teammate_data { |
| 744 | int handle; // the object handle for this teammate |
| 745 | bool is_visible; // whether this teammate can see me or not |
| 746 | }; |
| 747 | |
| 748 | // Alien memory data structure |
| 749 | struct alienorganism_data { |
| 750 | // Mode Data |
| 751 | int mode; // indicates what mode alien is currently in |
| 752 | int pending_mode; // mode to switch to when current task(s) are completed |
| 753 | int previous_mode; // mode alien was in before starting current task(s) |
| 754 | |
| 755 | float mode_time; // time spent in current mode |
| 756 | float next_activity_time; // next time resting alien should think about doing something |
| 757 | float max_wander_time; // maximum time to be spent out hunting/scavenging before returning |
| 758 | float next_update_squad_time; // the next time to do a squad update |
| 759 | float next_update_energy_time; // the next time to update the energy effect |
| 760 | float next_update_beam_time; // the next time to update the energy beams |
| 761 | float next_generic_check_time; // the next time to do generic checks |
| 762 | float next_squadie_update_time; // the next time to update the squadie's catchup speed |
| 763 | float next_special_damage_time; // the next time alien can take special damage |
| 764 | float next_vis_check_time; // the next time to do a squad visibility check |
| 765 | |
| 766 | // General Information |
| 767 | float base_speed; // the robot's base speed |
| 768 | float base_circle_distance; // the robot's base circle distance |
| 769 | float base_shields; // the robot's base shields |
| 770 | |
| 771 | float energy_charges; // the number of energy charges currently stored |
| 772 | float ok_to_deposit; // indicates whether alien is allowed to deposit charge |
| 773 | |
| 774 | float takeoff_time; // time since takeoff (used for clearing axes lock, etc.) |
| 775 | |
| 776 | int dest_object_handle; // destination handle for object to go to instead of wander |
| 777 | |
| 778 | // Indicators |
| 779 | bool done_turning; |
| 780 | bool done_moving; |
| 781 | bool hit_by_player; |
| 782 | bool energy_beams_on; |
| 783 | |
| 784 | // Home Data |
| 785 | vector home_pos; |
| 786 | int home_room; |
| 787 | vector home_fvec; |
| 788 | vector home_uvec; |
| 789 | |
| 790 | // Energy effect props |
| 791 | int pos1_handle; |
| 792 | int pos2_handle; |
| 793 | int pos3_handle; |
| 794 | int enabled_beams; |
| 795 | |
| 796 | // Squad Data |
| 797 | int squad_flags; |
| 798 | int leader_handle; |
| 799 | int num_teammates; |
| 800 | teammate_data teammate[ALIEN_MAX_TEAMMATES]; |
| 801 | vector squad_goal_pos; |
| 802 | int squad_goal_room; |
| 803 | |
| 804 | }; |
| 805 | |
| 806 | // Alien Organism class definition |
| 807 | class AlienOrganism : public BaseObjScript { |
| 808 | private: |
| 809 | alienorganism_data *memory; |
| 810 | |
| 811 | void SetMode(int me, char mode); |
| 812 | void DoTakeoff(int me, float takeoff_speed, float speed_variance); |
| 813 | |
| 814 | void DoInit(int me_handle); |
| 815 | void DoFrame(int me_handle); |
| 816 | bool DoNotify(int me, tOSIRISEventInfo *data); |
| 817 | void DoDamage(int me, tOSIRISEVTDAMAGED *damage_data); |
| 818 | void DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data); |
| 819 | |
| 820 | bool SendCommand(int me, int it, char command, void *ptr); |
| 821 | bool ReceiveCommand(int me, int it, char command, void *ptr); |
| 822 | |
| 823 | bool IssueSquadOrder(int leader_handle, char command, void *ptr); |
| 824 | |
| 825 | bool IsLandedMode(int mode); |
| 826 | bool IsEnergyRelatedLandedMode(int mode); |
| 827 | bool ModeIsAttackSensitive(int mode, int pending_mode); |
| 828 | bool ModeSupportsSquadEnlistment(int mode, int pending_mode, int recruiter_mode); |
| 829 | bool ModeSupportsSquadRecruitment(int mode); |
| 830 | bool ModeSupportsSquadMovement(int mode); |
| 831 | void DisperseSquad(int me); |
| 832 | void DisperseSquadToMode(int me, int mode); |
| 833 | bool LeaveLeader(int me); |
| 834 | |
| 835 | bool Flee(int me, bool force_flee = false); |
| 836 | bool Heal(int me); |
| 837 | bool MeleeAttack(int me, bool force_attack = false); |
| 838 | bool RangedAttack(int me); |
| 839 | bool Deposit(int me); |
| 840 | bool Withdraw(int me); |
| 841 | |
| 842 | bool WillJoinLeader(int me, int leader_handle, int priority); |
| 843 | |
| 844 | int FindTeammateID(int tm_handle); |
| 845 | int CalcFormationPosition(int me, int tm_ID, vector *pos); |
| 846 | void SetSquadieFormationGoal(int me); |
| 847 | void UpdateSquadieFormationGoal(int me); |
| 848 | void SetWanderGoal(int me); |
| 849 | void RemoveTeammate(int tm_id); |
| 850 | |
| 851 | bool IsNearFire(int me); |
| 852 | bool IsOnFire(int me); |
| 853 | |
| 854 | bool FindHome(int me); |
| 855 | void ProjectBeam(int me, int pos_handle, vector *start_pos, int start_room, vector *beam_dir, matrix *orient, |
| 856 | int beam_flag); |
| 857 | void CalcEnergyBeamPositions(int me); |
| 858 | void UpdateEnergyBeams(int me); |
| 859 | void UpdateEnergyEffect(int me); |
| 860 | void SetMaxSpeed(int me, float speed); |
| 861 | void SetCircleDist(int me, float dist); |
| 862 | |
| 863 | void UpdateSquadList(int me); |
| 864 | void UpdateSquad(int me); |
| 865 | void UpdateSquadVisibility(int me); |
| 866 | void DoSquadieFrame(int me); |
| 867 | |
| 868 | public: |
| 869 | AlienOrganism() {} |
| 870 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 871 | }; |
| 872 | |
| 873 | //--------------------- |
| 874 | // Heavy Trooper class |
| 875 | //--------------------- |
| 876 | |
| 877 | // Heavy Trooper Mode Types |
| 878 | #define HT_ATTACK_NORMAL 0 |
| 879 | #define HT_PREPARING_GRENADE 1 |
| 880 | #define HT_FIRING_GRENADE 2 |
| 881 | #define HT_RECOVERING 3 |
| 882 | |
| 883 | #define HT_PREPARING_FOR_CURL 10 |
| 884 | #define HT_CURLING_UP 11 |
| 885 | #define HT_UNCURLING 12 |
| 886 | #define HT_ARMORED_ATTACK 13 |
| 887 | #define HT_ARMORED_CIRCLE_BACK 14 |
| 888 | |
| 889 | // General Heavy Trooper Constants |
| 890 | #define HT_MEMORY_ID 4 |
| 891 | |
| 892 | #define HT_PARTICLE_SPEW_TIME 0.4f |
| 893 | #define HT_MAX_PARTICLE_TIME 0.5f |
| 894 | |
| 895 | #define HT_CURLUP_DIST 10.0f |
| 896 | #define HT_CURLUP_DIST_VARIANCE 20.0f |
| 897 | #define HT_CURLUP_DAMAGE 0.2f |
| 898 | |
| 899 | #define HT_GRENADE_DIST 40.0f |
| 900 | #define HT_GRENADE_DIST_MAX 130.0f |
| 901 | |
| 902 | #define HT_RECHARGE_TIME 1.0f |
| 903 | #define HT_DECHARGE_TIME 0.8f |
| 904 | #define HT_MAX_CHARGE 8.0f |
| 905 | #define HT_MAX_CHARGE_VARIANCE 6.0f |
| 906 | #define HT_CHARGE_INC 1.0f |
| 907 | |
| 908 | #define HT_CIRCLE_BACK_TIME 1.0f |
| 909 | |
| 910 | #define HT_SHIELD_BLAST_DELAY 1.5f |
| 911 | #define HT_ARMOR_DAMAGED_MOD 0.02f |
| 912 | #define HT_CURLING_DAMAGED_MOD 0.2f |
| 913 | |
| 914 | #define HT_GRENADE_CHECK_INTERVAL 1.0f |
| 915 | #define HT_GRENADE_CHECK_VARIANCE 1.5f |
| 916 | #define HT_GRENADE_RELOAD_TIME 3.0f |
| 917 | |
| 918 | #define HT_GRENADE_GUNPOINT 2 |
| 919 | |
| 920 | // Heavy Trooper Custom Anim Frames |
| 921 | #define HT_CURLUP_START_FRAME 202.0f |
| 922 | #define HT_CURLUP_END_FRAME 216.0f |
| 923 | #define HT_CURLUP_ANIM_TIME 2.0f |
| 924 | |
| 925 | #define HT_UNCURL_START_FRAME 146.0f |
| 926 | #define HT_UNCURL_END_FRAME 173.0f |
| 927 | #define HT_UNCURL_ANIM_TIME 3.5f |
| 928 | |
| 929 | #define HT_ROLL_START_FRAME 185.0f |
| 930 | #define HT_ROLL_END_FRAME 195.0f |
| 931 | #define HT_ROLL_ANIM_TIME 0.7f |
| 932 | |
| 933 | #define HT_GUNFIRE_START_FRAME 95.0f |
| 934 | #define HT_GUNFIRE_END_FRAME 105.0f |
| 935 | |
| 936 | #define HT_GRENADE_START_FRAME 105.0f |
| 937 | #define HT_GRENADE_FIRE_FRAME 119.0f |
| 938 | #define HT_GRENADE_END_FRAME 126.0f |
| 939 | |
| 940 | #define HT_GRENADE_FIRE_ANIM_TIME 1.2f |
| 941 | #define HT_GRENADE_RECOIL_ANIM_TIME 1.3f |
| 942 | #define HT_GRENADE_MISFIRE_ANIM_TIME 1.0f |
| 943 | |
| 944 | // Heavy Trooper Speed modifiers |
| 945 | #define HT_GRENADE_FIRING_SPEED_MOD 0.2f |
| 946 | #define HT_GRENADE_AIMING_SPEED_MOD 0.6f |
| 947 | #define HT_CURLING_SPEED_MOD 0.8f |
| 948 | #define HT_RAMMING_SPEED_MOD 2.5f |
| 949 | #define HT_CIRCLE_BACK_SPEED_MOD 2.5f |
| 950 | |
| 951 | #define HT_RAMMING_DELTA_SPEED_MOD 3.0f |
| 952 | |
| 953 | #define HT_RAMMING_TURN_RATE_MOD 1.1f |
| 954 | #define HT_RAMMING_DELTA_TURN_RATE_MOD 3.0f |
| 955 | |
| 956 | // Heavy Trooper ID's |
| 957 | #define HT_SHIELD_BLAST_NAME "HTShieldBlast" |
| 958 | #define HT_GRENADE_NAME "Impact Mortar" |
| 959 | #define HT_GRENADE_EFFECT_NAME "AlienEnergyEffect" |
| 960 | |
| 961 | // Heavy Trooper memory data structure |
| 962 | struct heavytrooper_data { |
| 963 | // Mode Data |
| 964 | int mode; // indicates what mode trooper is currently in |
| 965 | float mode_time; // time spent in current mode |
| 966 | |
| 967 | float base_shields; // original shields |
| 968 | float base_speed; // original max speed |
| 969 | float base_delta_speed; // original max delta speed |
| 970 | float base_turn_rate; // original turn rate |
| 971 | float base_delta_turn_rate; // original delta turn rate |
| 972 | |
| 973 | float charge; // stores energy used by curl-up mode |
| 974 | |
| 975 | float curlup_dist; // stores this robot's max curlup dist |
| 976 | float max_charge; // stores this robot's max charge |
| 977 | |
| 978 | float last_grenade_time; // last time a grenade was fired |
| 979 | float next_grenade_check_time; // next time to check if we have a clear grenade shot |
| 980 | float next_charge_time; // next time to re-charge or deplete charge |
| 981 | float next_blast_time; // next time a shield collision blast can be created |
| 982 | float next_particle_time; // next time to create a casing particle spew |
| 983 | |
| 984 | }; |
| 985 | |
| 986 | // Heavy Trooper class definition |
| 987 | class HeavyTrooper : public BaseObjScript { |
| 988 | private: |
| 989 | heavytrooper_data *memory; |
| 990 | |
| 991 | void SetMode(int me, char mode); |
| 992 | |
| 993 | void DoInit(int me_handle); |
| 994 | void DoFrame(int me_handle); |
| 995 | bool DoNotify(int me, tOSIRISEventInfo *data); |
| 996 | void DoDamage(int me, tOSIRISEVTDAMAGED *damage_data); |
| 997 | void DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data); |
| 998 | |
| 999 | void LaunchGrenade(int me); |
| 1000 | bool HasAClearGrenadeShot(int me, bool use_grenade_gunpoint = false); |
| 1001 | |
| 1002 | void SetMaxSpeed(int me, float speed, bool accel_faster = false); |
| 1003 | void EnableGunAttack(int me, bool enable = true); |
| 1004 | |
| 1005 | public: |
| 1006 | HeavyTrooper() {} |
| 1007 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 1008 | }; |
| 1009 | |
| 1010 | //--------------------- |
| 1011 | // Lifter class |
| 1012 | //--------------------- |
| 1013 | |
| 1014 | // Lifter Mode Types |
| 1015 | #define LIFTER_PASSIVE 0 |
| 1016 | #define LIFTER_AGITATED 1 |
| 1017 | #define LIFTER_HOSTILE 2 |
| 1018 | #define LIFTER_PULLING 3 |
| 1019 | #define LIFTER_PASSIFYING 4 |
| 1020 | |
| 1021 | // General Lifter Constants |
| 1022 | #define LIFTER_MEMORY_ID 4 |
| 1023 | |
| 1024 | #define LIFTER_MAX_PULL_TIME 8.0f |
| 1025 | #define LIFTER_PULL_CHECK_INTERVAL 0.5f |
| 1026 | #define LIFTER_PULL_VALIDATE_INTERVAL 0.25f |
| 1027 | #define LIFTER_PULL_TARGET_INTERVAL 0.15f |
| 1028 | |
| 1029 | #define LIFTER_NEXT_PULL_DELAY 3.0f |
| 1030 | #define LIFTER_NEXT_PULL_VARIANCE 5.0f |
| 1031 | |
| 1032 | #define LIFTER_MAX_PULLING_DIST 250.0f |
| 1033 | #define LIFTER_MIN_PULLING_DIST 20.0f |
| 1034 | |
| 1035 | #define LIFTER_MIN_HOSTILE_MODE_TIME 8.0f |
| 1036 | #define LIFTER_MIN_AGITATED_MODE_TIME 2.0f |
| 1037 | |
| 1038 | #define LIFTER_AGITATED_INTEREST_TIME 8.0f |
| 1039 | #define LIFTER_HOSTILE_INTEREST_TIME 18.0f |
| 1040 | |
| 1041 | #define LIFTER_AGITATED_SHIELD_PERCENT 0.95f |
| 1042 | #define LIFTER_HOSTILE_SHIELD_PERCENT 0.85f |
| 1043 | |
| 1044 | #define LIFTER_LOSE_PULL_SHIELD_PERCENT 0.20f |
| 1045 | |
| 1046 | #define LIFTER_TARGET_PULL_SPEED 35.0f |
| 1047 | |
| 1048 | #define LIFTER_LIFT_BEAM_UPDATE_TIME 0.25f |
| 1049 | |
| 1050 | // Lifter speed constants |
| 1051 | #define LIFTER_AGITATED_SPEED_MOD 1.2f |
| 1052 | #define LIFTER_HOSTILE_SPEED_MOD 2.0f |
| 1053 | #define LIFTER_PULLING_SPEED_MOD 0.6f |
| 1054 | |
| 1055 | // Lifter memory data structure |
| 1056 | struct lifter_data { |
| 1057 | // Mode Data |
| 1058 | int mode; // indicates what mode lifter is currently in |
| 1059 | float mode_time; // time spent in current mode |
| 1060 | |
| 1061 | float base_shields; // original shields |
| 1062 | float base_speed; // original max speed |
| 1063 | |
| 1064 | float shield_loss_margin; // amount of shields that must be lost before pull is lost |
| 1065 | float shields_at_pull_start; // shield total at start of pull |
| 1066 | |
| 1067 | int pull_target; // the target being pulled |
| 1068 | int pull_target_prop; // invisible powerup target pos |
| 1069 | int pull_source_prop; // invisible powerup source pos |
| 1070 | |
| 1071 | bool not_hostile_yet; // whether or not it's been in hostile mode yet |
| 1072 | |
| 1073 | float last_damaged_time; // last time we were damaged |
| 1074 | float next_pull_check_time; // the next time we can check if a pull can be done |
| 1075 | float last_target_pull_time; // the last time the target was pulled |
| 1076 | |
| 1077 | float next_lift_beam_time; // the next time to update the lift beam |
| 1078 | |
| 1079 | }; |
| 1080 | |
| 1081 | // Lifter class definition |
| 1082 | class Lifter : public BaseObjScript { |
| 1083 | private: |
| 1084 | lifter_data *memory; |
| 1085 | |
| 1086 | void SetMode(int me, char mode); |
| 1087 | |
| 1088 | void DoInit(int me_handle); |
| 1089 | void DoFrame(int me_handle); |
| 1090 | bool DoNotify(int me, tOSIRISEventInfo *data); |
| 1091 | void DoDamage(int me, tOSIRISEVTDAMAGED *damage_data); |
| 1092 | void DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data); |
| 1093 | void DoCleanUp(int me); |
| 1094 | |
| 1095 | void SetMaxSpeed(int me, float speed); |
| 1096 | bool OkToPull(int me, bool initial_check = true); |
| 1097 | void PullTarget(int me); |
| 1098 | void UpdateTractorBeam(int me); |
| 1099 | |
| 1100 | void ConfineTarget(int me); |
| 1101 | void ReleaseTarget(int me); |
| 1102 | void StopPulling(int me); |
| 1103 | void MoveTargetProp(int target_handle); |
| 1104 | void SwitchToAlert(int me); |
| 1105 | void UpdateLiftBeam(int me); |
| 1106 | |
| 1107 | public: |
| 1108 | Lifter() {} |
| 1109 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 1110 | }; |
| 1111 | |
| 1112 | //--------------------- |
| 1113 | // AlienBoss class |
| 1114 | //--------------------- |
| 1115 | |
| 1116 | // Alien Boss Mode Types |
| 1117 | #define AB_WANDERING 0 |
| 1118 | #define AB_HUNTING 1 |
| 1119 | #define AB_ATTACKING 2 |
| 1120 | #define AB_PREPARE_SPECIAL_ATTACK 3 |
| 1121 | #define AB_SPECIAL_ATTACK 4 |
| 1122 | #define AB_SPECIAL_ATTACK_RECOIL 5 |
| 1123 | #define AB_MELEE_ATTACK 6 |
| 1124 | |
| 1125 | #define AB_GOING_TO_NEST 10 |
| 1126 | #define AB_LANDING_AT_NEST 11 |
| 1127 | #define AB_HEALING 12 |
| 1128 | #define AB_FLEEING 13 |
| 1129 | |
| 1130 | #define AB_HIDING_FROM_THRUSTER 20 |
| 1131 | #define AB_GOING_TO_PROTECT_NEST 21 |
| 1132 | #define AB_DYING 22 |
| 1133 | #define AB_WAITING 23 |
| 1134 | #define AB_TELEPORTING 24 |
| 1135 | |
| 1136 | // Alien Boss State Types |
| 1137 | #define AB_NORMAL 0 |
| 1138 | #define AB_PROTECTIVE 1 |
| 1139 | #define AB_ANGRY 2 |
| 1140 | |
| 1141 | // General Alien Boss Constants |
| 1142 | #define AB_MEMORY_ID 4 |
| 1143 | |
| 1144 | #define AB_HEALING_ACTION_TIME 1.0f |
| 1145 | #define AB_HEAL_AMOUNT_PERCENT 0.05f |
| 1146 | #define AB_BEAM_UPDATE_TIME 0.25f |
| 1147 | |
| 1148 | #define AB_NORMAL_DAMAGE_LEVEL 0.25f |
| 1149 | #define AB_PROTECTIVE_DAMAGE_LEVEL 0.4f |
| 1150 | #define AB_ANGRY_DAMAGE_LEVEL 0.6f |
| 1151 | |
| 1152 | #define AB_MAX_FLEE_TIME 10.0f |
| 1153 | #define AB_STARTING_FLEE_CHANCE 90 |
| 1154 | #define AB_FLEE_CHANCE_DECREMENT 10 |
| 1155 | |
| 1156 | #define AB_ATTACK_CHECK_INTERVAL 0.5f |
| 1157 | |
| 1158 | #define AB_DAMAGE_EFFECT_INTERVAL 0.5f |
| 1159 | #define AB_MAX_DAMAGE_SPARK_RATE 20.0f |
| 1160 | |
| 1161 | #define AB_MAX_SPECIAL_ATTACK_DIST 70.0f |
| 1162 | #define AB_MAX_STING_DIST 40.0f |
| 1163 | |
| 1164 | #define AB_STING_DAMAGE 20.0f |
| 1165 | |
| 1166 | #define AB_SPECIAL_ATTACK_DELAY 6.0f |
| 1167 | #define AB_SPECIAL_ATTACK_VARIANCE 14.0f |
| 1168 | |
| 1169 | #define AB_MELEE_ATTACK_DELAY 5.0f |
| 1170 | #define AB_MELEE_ATTACK_VARIANCE 5.0f |
| 1171 | #define AB_MELEE_DIST 40.0f |
| 1172 | #define AB_MAX_MELEE_TIME 5.0f |
| 1173 | |
| 1174 | #define AB_CHECK_IF_STUCK_INTERVAL 10.0f |
| 1175 | #define AB_CHECK_IF_STUCK_DIST 10.0f |
| 1176 | |
| 1177 | // Alien Boss goal complete IDs |
| 1178 | #define AB_GUID_GOT_TO_NEST 0x10100001 |
| 1179 | #define AB_GUID_LANDED 0x10100002 |
| 1180 | #define AB_GUID_GOT_TO_DEST_OBJ 0x10100003 |
| 1181 | #define AB_GUID_GOT_TO_WANDER_ROOM 0x10100004 |
| 1182 | #define AB_GUID_GOT_TO_NEST_ROOM 0x10100005 |
| 1183 | #define AB_GUID_GOT_TO_HIDE_ROOM 0x10100006 |
| 1184 | |
| 1185 | // Alien Boss Custom Anim Frames |
| 1186 | #define AB_HEALING_START_FRAME 1.0f |
| 1187 | #define AB_HEALING_END_FRAME 10.0f |
| 1188 | #define AB_HEALING_ANIM_TIME 2.0f |
| 1189 | |
| 1190 | #define AB_LANDING_START_FRAME 50.0f |
| 1191 | #define AB_LANDING_END_FRAME 53.0f |
| 1192 | #define AB_LANDING_ANIM_TIME 1.0f |
| 1193 | |
| 1194 | #define AB_TAKEOFF_START_FRAME 10.0f |
| 1195 | #define AB_TAKEOFF_END_FRAME 25.0f |
| 1196 | #define AB_TAKEOFF_ANIM_TIME 1.0f |
| 1197 | |
| 1198 | #define AB_ATTACK_START_FRAME 36.0f |
| 1199 | #define AB_ATTACK_END_FRAME 45.0f |
| 1200 | #define AB_ATTACK_ANIM_TIME 0.5f |
| 1201 | |
| 1202 | #define AB_RECOIL_START_FRAME 45.0f |
| 1203 | #define AB_RECOIL_END_FRAME 50.0f |
| 1204 | #define AB_RECOIL_ANIM_TIME 0.5f |
| 1205 | |
| 1206 | // Speed Modifier Constants |
| 1207 | #define AB_WANDER_SPEED_MOD 1.0f |
| 1208 | #define AB_ATTACK_SPEED_MOD 0.9f |
| 1209 | #define AB_MELEE_ATTACK_SPEED_MOD 1.1f |
| 1210 | #define AB_SPEC_ATTACK_SPEED_MOD 0.3f |
| 1211 | #define AB_RETURN_SPEED_MOD 1.2f |
| 1212 | #define AB_LAND_SPEED_MOD 0.4f |
| 1213 | #define AB_FLEE_SPEED_MOD 1.0f |
| 1214 | #define AB_GUARD_SPEED_MOD 0.9f |
| 1215 | #define AB_HIDE_SPEED_MOD 1.0f |
| 1216 | #define AB_DIE_SPEED_MOD 1.0f |
| 1217 | |
| 1218 | // Alien Boss Lookup Globals |
| 1219 | #define AB_NUM_WANDER_ROOMS 11 |
| 1220 | |
| 1221 | static const char *const AB_WanderRoomNames[AB_NUM_WANDER_ROOMS] = { |
| 1222 | "BossRoomA", "BossTunnelAB", "BossRoomB", "BossTunnelBC", "BossRoomC", "BossTunnelCE", |
| 1223 | "BossRoomD", "BossTunnelAE", "BossRoomE", "BossTunnelCE", "BossRoomD"}; |
| 1224 | |
| 1225 | // Alien Boss memory data structure |
| 1226 | struct alienboss_data { |
| 1227 | // Mode Data |
| 1228 | int mode; // indicates what mode alien boss is currently in |
| 1229 | int state; // indicates the boss's current state |
| 1230 | |
| 1231 | float mode_time; // time spent in current mode |
| 1232 | float next_activity_time; // next time to do something |
| 1233 | float max_wander_time; // maximum time to be spent wandering |
| 1234 | float next_update_beam_time; // the next time to update the energy beams |
| 1235 | float next_generic_check_time; // the next time to do generic checks |
| 1236 | float next_special_damage_time; // the next time alien boss can take special damage |
| 1237 | float next_special_attack_time; // the next time boss can do a special attack |
| 1238 | float next_melee_attack_time; // the next time boss can do a melee attack |
| 1239 | float next_damage_effect_time; // the next time to do the damage effect |
| 1240 | float intro_end_time; // the time intro ends |
| 1241 | |
| 1242 | // General Information |
| 1243 | float base_speed; // the robot's base speed |
| 1244 | float base_shields; // the robot's base shields |
| 1245 | int dest_object_handle; // destination handle for object to go to instead of wander |
| 1246 | float damage; // the amount of damage currently sustained |
| 1247 | float damage_threshold; // the damage that can be sustained before returning to heal |
| 1248 | int fire_flee_chance; // the chance to flee when caught on fire |
| 1249 | |
| 1250 | int wander_rooms[AB_NUM_WANDER_ROOMS]; // the rooms alien wanders through |
| 1251 | int curr_wander_room_index; // the room currently wandering to |
| 1252 | bool wander_forward; // whether to follow list normally or in reverse |
| 1253 | bool waiting_effect_enabled; // whether waiting effect should be done yet |
| 1254 | bool intro_ended; // whether intro is over yet |
| 1255 | |
| 1256 | // Indicators |
| 1257 | bool done_turning; |
| 1258 | bool done_moving; |
| 1259 | bool hit_by_player; |
| 1260 | bool protected_nest; |
| 1261 | |
| 1262 | // Home Data |
| 1263 | vector home_pos; |
| 1264 | int home_room; |
| 1265 | vector home_fvec; |
| 1266 | vector home_uvec; |
| 1267 | |
| 1268 | // Energy effect props |
| 1269 | int pos1_handle; |
| 1270 | int pos2_handle; |
| 1271 | int pos3_handle; |
| 1272 | |
| 1273 | int tail_pos_handle; |
| 1274 | |
| 1275 | // Scenario objects |
| 1276 | int nest_handle; |
| 1277 | |
| 1278 | // Hiding from thruster rooms |
| 1279 | int left_hide_room; |
| 1280 | int right_hide_room; |
| 1281 | |
| 1282 | // Teleport values |
| 1283 | vector dest_pos; |
| 1284 | int dest_room; |
| 1285 | int mode_prior_teleporting; |
| 1286 | bool did_transfer; |
| 1287 | |
| 1288 | // Getting Stuck Prevention |
| 1289 | float squared_dist_moved; |
| 1290 | float next_check_if_stuck_time; |
| 1291 | vector last_pos; |
| 1292 | |
| 1293 | }; |
| 1294 | |
| 1295 | // Alien Boss class definition |
| 1296 | class AlienBoss : public BaseObjScript { |
| 1297 | private: |
| 1298 | alienboss_data *memory; |
| 1299 | |
| 1300 | void SetMode(int me, char mode); |
| 1301 | void DoTakeoff(int me, float takeoff_speed, float speed_variance); |
| 1302 | |
| 1303 | void DoInit(int me_handle); |
| 1304 | void DoFrame(int me_handle); |
| 1305 | bool DoNotify(int me, tOSIRISEventInfo *data); |
| 1306 | void DoDamage(int me, tOSIRISEVTDAMAGED *damage_data); |
| 1307 | void DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data); |
| 1308 | void DoCleanUp(int me); |
| 1309 | |
| 1310 | bool SendCommand(int me, int it, char command, void *ptr); |
| 1311 | bool ReceiveCommand(int me, int it, char command, void *ptr); |
| 1312 | |
| 1313 | bool IsOnFire(int me); |
| 1314 | void SetMaxSpeed(int me, float speed); |
| 1315 | void SetWanderGoal(int me); |
| 1316 | void SetWanderRoomGoal(int me); |
| 1317 | int DetermineClosestRoom(int me); |
| 1318 | void SetProtectNestGoal(int me); |
| 1319 | void SetHideRoomGoal(int me); |
| 1320 | |
| 1321 | bool OkToStartSpecialAttack(int me); |
| 1322 | bool DoStingAttack(int me); |
| 1323 | void AbortCurrentMode(int me); |
| 1324 | void UpdateHealingEnergyBeams(int me); |
| 1325 | void UpdateDamageEffect(int me); |
| 1326 | void StartHealing(int me); |
| 1327 | void StopHealing(int me); |
| 1328 | |
| 1329 | bool ModeIsStuckSensitive(int mode); |
| 1330 | |
| 1331 | void DoCustomLookups(void); |
| 1332 | |
| 1333 | public: |
| 1334 | AlienBoss() {} |
| 1335 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 1336 | }; |
| 1337 | |
| 1338 | //--------------------- |
| 1339 | // Security Camera class |
| 1340 | //--------------------- |
| 1341 | |
| 1342 | // Security Camera Mode Types |
| 1343 | #define SC_PANNING 0 |
| 1344 | #define SC_TRACKING 1 |
| 1345 | |
| 1346 | // Security Camera Panning types |
| 1347 | #define SC_LOOPING 0 |
| 1348 | #define SC_WARMING_UP 1 |
| 1349 | |
| 1350 | // General Security Camera Constants |
| 1351 | #define SC_MEMORY_ID 4 |
| 1352 | |
| 1353 | #define SC_TRACK_TIME_TO_ALERT 3.0f |
| 1354 | #define SC_TIME_TO_LOSE_TARGET 1.0f |
| 1355 | #define SC_TIME_TO_GAIN_TARGET 1.0f |
| 1356 | |
| 1357 | #define SC_PAN_SPEED 26.0f // frames per second |
| 1358 | #define SC_TRACK_SPEED 52.0f // frames per second |
| 1359 | |
| 1360 | #define SC_START_FRAME 0.0f |
| 1361 | #define SC_MID_FRAME 90.0f |
| 1362 | #define SC_END_FRAME 180.0f |
| 1363 | #define SC_MAX_FRAME 360.0f // end frame to max frame are reverse of start to end |
| 1364 | #define SC_MAX_FRAME_OFFSET 90.0f |
| 1365 | |
| 1366 | #define SC_FRAME_DELTA_ERROR 1.5f |
| 1367 | |
| 1368 | #define SC_TRACK_INTERVAL 0.25f |
| 1369 | |
| 1370 | // Security camera memory data structure |
| 1371 | struct securitycamera_data { |
| 1372 | // Mode Data |
| 1373 | int mode; // indicates what mode security camera is currently in |
| 1374 | float mode_time; // time spent in current mode |
| 1375 | |
| 1376 | bool alerted; // whether camera is on alert |
| 1377 | |
| 1378 | int panning_state; // whether it is looping or warming up |
| 1379 | |
| 1380 | float next_activity_time; // the next time to do tracking |
| 1381 | float last_update_anim_time; // the last time tracking was done |
| 1382 | float curr_track_anim_frame; // the current tracking animation frame |
| 1383 | |
| 1384 | }; |
| 1385 | |
| 1386 | // Security Camera class definition |
| 1387 | class SecurityCamera : public BaseObjScript { |
| 1388 | private: |
| 1389 | securitycamera_data *memory; |
| 1390 | |
| 1391 | void SetMode(int me, char mode); |
| 1392 | |
| 1393 | void DoInit(int me_handle); |
| 1394 | void DoFrame(int me_handle); |
| 1395 | bool DoNotify(int me, tOSIRISEventInfo *data); |
| 1396 | void DoDamage(int me, tOSIRISEVTDAMAGED *damage_data); |
| 1397 | void DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data); |
| 1398 | |
| 1399 | bool SendCommand(int me, int it, char command, void *ptr); |
| 1400 | bool ReceiveCommand(int me, int it, char command, void *ptr); |
| 1401 | |
| 1402 | public: |
| 1403 | SecurityCamera() {} |
| 1404 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 1405 | }; |
| 1406 | |
| 1407 | //--------------------- |
| 1408 | // CrowdControl Class |
| 1409 | //--------------------- |
| 1410 | |
| 1411 | // General Crowd Control Constants |
| 1412 | #define CC_MEMORY_ID 4 |
| 1413 | |
| 1414 | #define CC_CHECK_INTERVAL 0.2f |
| 1415 | #define CC_MIN_STOPPING_SPEED 0.0000001f // we want to preserve the direction of velocity |
| 1416 | |
| 1417 | // Crowd Control memory data structure |
| 1418 | struct crowdcontrol_data { |
| 1419 | int follow_handle; // handle of object to not crowd |
| 1420 | float stop_dist; // dist at which to stop completely |
| 1421 | float slowdown_offset; // dist at which to start slowing down (added to stop dist) |
| 1422 | |
| 1423 | bool disable_check; // allows slowdown check to be turned on/off dynamically |
| 1424 | |
| 1425 | float base_speed; // the base speed of the object |
| 1426 | float next_check_time; // the next time to do closeness check |
| 1427 | |
| 1428 | }; |
| 1429 | |
| 1430 | // Security Camera class definition |
| 1431 | class CrowdControl : public BaseObjScript { |
| 1432 | private: |
| 1433 | crowdcontrol_data *memory; |
| 1434 | |
| 1435 | void DoInit(int me_handle); |
| 1436 | void DoFrame(int me_handle); |
| 1437 | bool DoNotify(int me, tOSIRISEventInfo *data); |
| 1438 | |
| 1439 | bool SendCommand(int me, int it, char command, void *ptr); |
| 1440 | bool ReceiveCommand(int me, int it, char command, void *ptr); |
| 1441 | |
| 1442 | public: |
| 1443 | CrowdControl() {} |
| 1444 | int16_t CallEvent(int event, tOSIRISEventInfo *data); |
| 1445 | }; |
| 1446 | |
| 1447 | //----------------------- |
| 1448 | // Name lookup functions |
| 1449 | //----------------------- |
| 1450 | |
| 1451 | // Looks up any names and stores the returned ID's |
| 1452 | void DoNameLookups(void) { |
| 1453 | energy_effect_id = Wpn_FindID(ALIEN_ENERGY_EFFECT_NAME); |
| 1454 | frag_burst_effect_id = Wpn_FindID("FragBurstEffect"); |
| 1455 | boss_frag_burst_id = Wpn_FindID("AlienBossFragBurst"); |
| 1456 | transfer_effect_id = Scrpt_FindTextureName(ALIEN_TRANSFER_EFFECT_NAME); |
| 1457 | heal_effect_id = Scrpt_FindTextureName(ALIEN_HEAL_EFFECT_NAME); |
| 1458 | boss_heal_effect_id = Scrpt_FindTextureName("FunkyEffect4"); |
| 1459 | tractor_beam_effect_id = Scrpt_FindTextureName("FunkyEffectGreen"); |
| 1460 | alien_organism_id = Obj_FindID(ALIEN_TYPE_NAME); |
| 1461 | shield_blast_id = Wpn_FindID(HT_SHIELD_BLAST_NAME); |
| 1462 | ht_grenade_id = Wpn_FindID(HT_GRENADE_NAME); |
| 1463 | ht_grenade_effect_id = Wpn_FindID(HT_GRENADE_EFFECT_NAME); |
| 1464 | lifter_blast_effect_id = Wpn_FindID("LifterHitBlast"); |
| 1465 | lifter_stick_effect_id = Scrpt_FindTextureName("FunkyEffect2"); |
| 1466 | teleport_effect_id = Wpn_FindID("TeleportEffect"); |
| 1467 | |
| 1468 | ht_grenade_sound_id = Sound_FindId("Drop weapon"); |
| 1469 | |
| 1470 | powerup_id = Obj_FindID("Invisiblepowerup"); |
| 1471 | |
| 1472 | boss_flapping_id = Sound_FindId("Merc4BossBuzz"); |
| 1473 | boss_turf_id = Sound_FindId("Merc4BossTurf"); |
| 1474 | boss_see_id = Sound_FindId("Merc4BossSee"); |
| 1475 | boss_hurt_id = Sound_FindId("Merc4BossHurt"); |
| 1476 | |
| 1477 | lifter_pull_sound_id = Sound_FindId("RbtLifterBeam"); |
| 1478 | lifter_amb_sound_id = Sound_FindId("RbtLifterAmb1"); |
| 1479 | } |
| 1480 | |
| 1481 | //---------------- |
| 1482 | // Standard stuff |
| 1483 | //---------------- |
| 1484 | |
| 1485 | // InitializeDLL |
| 1486 | // Purpose: |
| 1487 | // This function gets called when the DLL first gets loaded. It will only be called once (until the |
| 1488 | // DLL is unloaded). Passed in is a struct of data passed from the game needed for the DLL to interact |
| 1489 | // with D3. Usually this function will just call osicommon_Initialize(), which sets up the imported |
| 1490 | // functions. However, you can alloc some memory or whatever in this function, and free it in ShutdownDLL(). |
| 1491 | // Note: You cannot call any imported functions until osicommon_Initialize() is called. |
| 1492 | // Returns 1 if initialization went ok, 0 if there was an error and the DLL should not be loaded. |
| 1493 | char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) { |
| 1494 | osicommon_Initialize((tOSIRISModuleInit *)func_list); |
| 1495 | String_table_size = func_list->string_count; |
| 1496 | String_table = func_list->string_table; |
| 1497 | |
| 1498 | // Do name lookups |
| 1499 | DoNameLookups(); |
| 1500 | |
| 1501 | InitMathTables(); |
| 1502 | |
| 1503 | if (func_list->game_checksum != CHECKSUM) { |
| 1504 | mprintf(0, "Game-Checksum FAIL!!! (%ul!=%ul)\n", func_list->game_checksum, CHECKSUM); |
| 1505 | mprintf(0, "RECOMPILE YOUR SCRIPTS!!!\n"); |
| 1506 | return 0; |
| 1507 | } |
| 1508 | return 1; |
| 1509 | } |
| 1510 | |
| 1511 | // ShutdownDLL |
| 1512 | // Purpose: |
| 1513 | // This function is called right before a DLL is about to be unloaded from memory. You can free |
| 1514 | // any unfree'd memory, or anything else you need to do. Don't worry about destroying any instances |
| 1515 | // of scripts, as they will all be automatically destroyed before this function is called. The |
| 1516 | // same goes for any memory allocated with Scrpt_MemAlloc(), as this will automatically be freed |
| 1517 | // when a scripts instance is destroyed. |
| 1518 | void STDCALL ShutdownDLL(void) {} |
| 1519 | |
| 1520 | // GetGOScriptID |
| 1521 | // Purpose: |
| 1522 | // Given the name of the object (from it's pagename), this function will search through it's |
| 1523 | // list of General Object Scripts for a script with a matching name (to see if there is a script |
| 1524 | // for that type/id of object within this DLL). If a matching scriptname is found, a UNIQUE ID |
| 1525 | // is to be returned back to Descent 3. This ID will be used from here on out for all future |
| 1526 | // interaction with the DLL. Since doors are not part of the generic object's, it's possible |
| 1527 | // for a door to have the same name as a generic object (OBJ_POWERUP, OBJ_BUILDING, OBJ_CLUTTER |
| 1528 | // or OBJ_ROBOT), therefore, a 1 is passed in for isdoor if the given object name refers to a |
| 1529 | // door, else it is a 0. The return value is the unique identifier, else -1 if the script |
| 1530 | // does not exist in the DLL. |
| 1531 | int STDCALL GetGOScriptID(const char *name, uint8_t isdoor) { |
| 1532 | for (int i = 0; i < NUM_IDS; i++) { |
| 1533 | if (!stricmp(name, ScriptInfo[i].name)) { |
| 1534 | return ScriptInfo[i].id; |
| 1535 | } |
| 1536 | } |
| 1537 | return -1; |
| 1538 | } |
| 1539 | |
| 1540 | // CreateInstance |
| 1541 | // Purpose: |
| 1542 | // Given an ID from a call to GetGOScriptID(), this function will create a new instance for that |
| 1543 | // particular script (by allocating and initializing memory, etc.). A pointer to this instance |
| 1544 | // is to be returned back to Descent 3. This pointer will be passed around, along with the ID |
| 1545 | // for CallInstanceEvent() and DestroyInstance(). Return NULL if there was an error. |
| 1546 | void STDCALLPTR CreateInstance(int id) { |
| 1547 | switch (id) { |
| 1548 | case ID_ALIENORGANISM: |
| 1549 | return new AlienOrganism; |
| 1550 | break; |
| 1551 | case ID_HEAVYTROOPER: |
| 1552 | return new HeavyTrooper; |
| 1553 | break; |
| 1554 | case ID_LIFTER: |
| 1555 | return new Lifter; |
| 1556 | break; |
| 1557 | case ID_ALIENBOSS: |
| 1558 | return new AlienBoss; |
| 1559 | break; |
| 1560 | case ID_SECURITYCAMERA: |
| 1561 | return new SecurityCamera; |
| 1562 | break; |
| 1563 | case ID_CROWDCONTROL: |
| 1564 | return new CrowdControl; |
| 1565 | break; |
| 1566 | default: |
| 1567 | mprintf(0, "SCRIPT: Illegal ID (%d)\n", id); |
| 1568 | break; |
| 1569 | }; |
| 1570 | return NULL; |
| 1571 | } |
| 1572 | |
| 1573 | // DestroyInstance |
| 1574 | // Purpose: |
| 1575 | // Given an ID, and a pointer to a particular instance of a script, this function will delete and |
| 1576 | // destruct all information associated with that script, so it will no longer exist. |
| 1577 | void STDCALL DestroyInstance(int id, void *ptr) { |
| 1578 | switch (id) { |
| 1579 | case ID_ALIENORGANISM: |
| 1580 | delete ((AlienOrganism *)ptr); |
| 1581 | break; |
| 1582 | case ID_HEAVYTROOPER: |
| 1583 | delete ((HeavyTrooper *)ptr); |
| 1584 | break; |
| 1585 | case ID_LIFTER: |
| 1586 | delete ((Lifter *)ptr); |
| 1587 | break; |
| 1588 | case ID_ALIENBOSS: |
| 1589 | delete ((AlienBoss *)ptr); |
| 1590 | break; |
| 1591 | case ID_SECURITYCAMERA: |
| 1592 | delete ((SecurityCamera *)ptr); |
| 1593 | break; |
| 1594 | case ID_CROWDCONTROL: |
| 1595 | delete ((CrowdControl *)ptr); |
| 1596 | break; |
| 1597 | default: |
| 1598 | mprintf(0, "SCRIPT: Illegal ID (%d)\n", id); |
| 1599 | break; |
| 1600 | } |
| 1601 | } |
| 1602 | |
| 1603 | // CallInstanceEvent |
| 1604 | // Purpose: |
| 1605 | // Given an ID, a pointer to a script instance, an event and a pointer to the struct of |
| 1606 | // information about the event, this function will translate who this event belongs to and |
| 1607 | // passes the event to that instance of the script to be handled. Return a combination of |
| 1608 | // CONTINUE_CHAIN and CONTINUE_DEFAULT, to give instructions on what to do based on the |
| 1609 | // event. CONTINUE_CHAIN means to continue through the chain of scripts (custom script, level |
| 1610 | // script, mission script, and finally default script). If CONTINUE_CHAIN is not specified, |
| 1611 | // than the chain is broken and those scripts of lower priority will never get the event. Return |
| 1612 | // CONTINUE_DEFAULT in order to tell D3 if you want process the normal action that is built into |
| 1613 | // the game for that event. This only pertains to certain events. If the chain continues |
| 1614 | // after this script, than the CONTINUE_DEFAULT setting will be overridden by lower priority |
| 1615 | // scripts return value. |
| 1616 | int16_t STDCALL CallInstanceEvent(int id, void *ptr, int event, tOSIRISEventInfo *data) { |
| 1617 | return ((BaseObjScript *)ptr)->CallEvent(event, data); |
| 1618 | } |
| 1619 | |
| 1620 | // SaveRestoreState |
| 1621 | // Purpose: |
| 1622 | // This function is called when Descent 3 is saving or restoring the game state. In this function |
| 1623 | // you should save/restore any global data that you want preserved through load/save (which includes |
| 1624 | // demos). You must be very careful with this function, corrupting the file (reading or writing too |
| 1625 | // much or too little) may be hazardous to the game (possibly making it impossible to restore the |
| 1626 | // state). It would be best to use version information to keep older versions of saved states still |
| 1627 | // able to be used. IT IS VERY IMPORTANT WHEN SAVING THE STATE TO RETURN THE NUMBER OF _BYTES_ WROTE |
| 1628 | // TO THE FILE. When restoring the data, the return value is ignored. saving_state is 1 when you should |
| 1629 | // write data to the file_ptr, 0 when you should read in the data. |
| 1630 | int STDCALL SaveRestoreState(void *file_ptr, uint8_t saving_state) { return 0; } |
| 1631 | |
| 1632 | //============================================ |
| 1633 | // Script Implementation |
| 1634 | //============================================ |
| 1635 | BaseObjScript::BaseObjScript() {} |
| 1636 | |
| 1637 | BaseObjScript::~BaseObjScript() {} |
| 1638 | |
| 1639 | int16_t BaseObjScript::CallEvent(int event, tOSIRISEventInfo *data) { return CONTINUE_CHAIN | CONTINUE_DEFAULT; } |
| 1640 | |
| 1641 | //--------------------- |
| 1642 | // AlienOrganism class |
| 1643 | //--------------------- |
| 1644 | |
| 1645 | // Sends a command out to another alien |
| 1646 | bool AlienOrganism::SendCommand(int me, int it, char command, void *ptr) { |
| 1647 | bot_com com; |
| 1648 | |
| 1649 | com.action = command; |
| 1650 | com.ptr = ptr; |
| 1651 | |
| 1652 | tOSIRISEventInfo ei; |
| 1653 | |
| 1654 | ei.me_handle = it; |
| 1655 | ei.extra_info = (void *)&com; |
| 1656 | ei.evt_ai_notify.notify_type = AIN_USER_DEFINED; |
| 1657 | ei.evt_ai_notify.it_handle = me; |
| 1658 | |
| 1659 | return Obj_CallEvent(it, EVT_AI_NOTIFY, &ei); |
| 1660 | } |
| 1661 | |
| 1662 | // Processes a command from another alien |
| 1663 | bool AlienOrganism::ReceiveCommand(int me, int it, char command, void *ptr) { |
| 1664 | switch (command) { |
| 1665 | // Leader is asking alien to join squad |
| 1666 | case ALIEN_COM_JOIN_ME: |
| 1667 | if (WillJoinLeader(me, it, *(int *)ptr)) { |
| 1668 | return true; |
| 1669 | } |
| 1670 | break; |
| 1671 | |
| 1672 | // Leader is telling squadie to leave the squad |
| 1673 | case ALIEN_COM_LEAVE_ME: |
| 1674 | memory->squad_flags = 0; |
| 1675 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 1676 | memory->num_teammates = 0; |
| 1677 | SetMode(me, memory->mode); |
| 1678 | return true; |
| 1679 | break; |
| 1680 | |
| 1681 | // Leader is telling squadie to leave the squad for the given mode |
| 1682 | case ALIEN_COM_LEAVE_ME_FOR_MODE: |
| 1683 | memory->squad_flags = 0; |
| 1684 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 1685 | memory->num_teammates = 0; |
| 1686 | SetMode(me, *(int *)ptr); |
| 1687 | return true; |
| 1688 | break; |
| 1689 | |
| 1690 | case ALIEN_COM_PROTECT_ME: |
| 1691 | break; |
| 1692 | |
| 1693 | // Leader is telling squadie to break formation and attack |
| 1694 | case ALIEN_COM_BREAK_AND_ATTACK: |
| 1695 | memory->squad_flags |= ALIEN_BROKEN; |
| 1696 | SetMode(me, memory->mode); |
| 1697 | return true; |
| 1698 | break; |
| 1699 | |
| 1700 | // Leader is telling squadie to resume formation |
| 1701 | case ALIEN_COM_REGROUP: |
| 1702 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 1703 | SetMode(me, memory->mode); |
| 1704 | return true; |
| 1705 | break; |
| 1706 | |
| 1707 | // Leader is telling squadie to switch to given mode |
| 1708 | case ALIEN_COM_SET_MODE: |
| 1709 | SetMode(me, *(int *)ptr); |
| 1710 | return true; |
| 1711 | break; |
| 1712 | |
| 1713 | // Leader is telling squadie to set pending mode |
| 1714 | case ALIEN_COM_SET_PENDING_MODE: |
| 1715 | memory->pending_mode = *(int *)ptr; |
| 1716 | return true; |
| 1717 | break; |
| 1718 | |
| 1719 | // Alien is asked to return current mode |
| 1720 | case ALIEN_COM_GET_MODE: |
| 1721 | *(int *)ptr = memory->mode; |
| 1722 | return true; |
| 1723 | break; |
| 1724 | |
| 1725 | // Alien is told to set the given squad flags |
| 1726 | case ALIEN_COM_SET_SQUAD_FLAGS: { |
| 1727 | int flags = *(int *)ptr; |
| 1728 | memory->squad_flags |= flags; |
| 1729 | return true; |
| 1730 | } break; |
| 1731 | |
| 1732 | // Alien is told to clear the given squad flags |
| 1733 | case ALIEN_COM_CLEAR_SQUAD_FLAGS: { |
| 1734 | int flags = *(int *)ptr; |
| 1735 | memory->squad_flags &= ~flags; |
| 1736 | return true; |
| 1737 | } break; |
| 1738 | |
| 1739 | // Squadie is asking leader if it can leave |
| 1740 | case ALIEN_COM_REQUEST_LEAVE: |
| 1741 | break; |
| 1742 | |
| 1743 | // Squadie is telling leader that he's leaving |
| 1744 | case ALIEN_COM_LEAVING_YOU: { |
| 1745 | int tm_id = FindTeammateID(it); |
| 1746 | if (tm_id >= 0) { |
| 1747 | RemoveTeammate(tm_id); |
| 1748 | if (memory->num_teammates == 0) { |
| 1749 | memory->squad_flags = 0; |
| 1750 | SetMode(me, memory->mode); |
| 1751 | } |
| 1752 | return true; |
| 1753 | } |
| 1754 | } break; |
| 1755 | |
| 1756 | // Squadie is asking for it's formation position |
| 1757 | case ALIEN_COM_GET_GOAL_POS: { |
| 1758 | int tm_id = FindTeammateID(it); |
| 1759 | if (tm_id >= 0) { |
| 1760 | CalcFormationPosition(me, tm_id, (vector *)ptr); |
| 1761 | return true; |
| 1762 | } |
| 1763 | } break; |
| 1764 | |
| 1765 | // Squadie is asking for it's formation goal room |
| 1766 | case ALIEN_COM_GET_GOAL_ROOM: { |
| 1767 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, (int *)ptr); |
| 1768 | return true; |
| 1769 | } break; |
| 1770 | |
| 1771 | // I'm being informed that a squadmate has been hit |
| 1772 | case ALIEN_COM_I_WAS_HIT: { |
| 1773 | // mprintf(0,"I was hit message received!\n"); |
| 1774 | |
| 1775 | if (MeleeAttack(me)) { |
| 1776 | return true; |
| 1777 | } |
| 1778 | } break; |
| 1779 | |
| 1780 | // I'm being asked if I can see a squadie or not |
| 1781 | case ALIEN_COM_CAN_YOU_SEE_ME: { |
| 1782 | int tm_id = FindTeammateID(it); |
| 1783 | if (tm_id >= 0) { |
| 1784 | *(bool *)ptr = memory->teammate[tm_id].is_visible; |
| 1785 | return true; |
| 1786 | } |
| 1787 | } break; |
| 1788 | |
| 1789 | // I'm being told to go hunt to a certain object |
| 1790 | case ALIEN_COM_HUNT_TO_OBJ: { |
| 1791 | // Make sure we're in a mode that is ok to switch from |
| 1792 | if (memory->mode != ALIEN_LANDED_RESTING) |
| 1793 | return false; |
| 1794 | |
| 1795 | // If we're a squadie, forward this to the leader and let him take care of it |
| 1796 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 1797 | return SendCommand(me, memory->leader_handle, ALIEN_COM_HUNT_TO_OBJ, ptr); |
| 1798 | } |
| 1799 | |
| 1800 | // Otherwise, set the destination object |
| 1801 | memory->dest_object_handle = *(int *)ptr; |
| 1802 | |
| 1803 | // Switch to hunting mode |
| 1804 | SetMode(me, ALIEN_HUNTING); |
| 1805 | |
| 1806 | // If leading, tell the squad to do the same |
| 1807 | if (memory->squad_flags & ALIEN_LEADER) { |
| 1808 | int mode = ALIEN_HUNTING; |
| 1809 | IssueSquadOrder(me, ALIEN_COM_SET_MODE, &mode); |
| 1810 | } |
| 1811 | |
| 1812 | return true; |
| 1813 | } break; |
| 1814 | |
| 1815 | // I'm being told to go hunt to a certain object |
| 1816 | case ALIEN_COM_SCAV_TO_OBJ: { |
| 1817 | // Make sure we're in a mode that is ok to switch from |
| 1818 | if (memory->mode != ALIEN_LANDED_RESTING) |
| 1819 | return false; |
| 1820 | |
| 1821 | // If we're a squadie, forward this to the leader and let him take care of it |
| 1822 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 1823 | return SendCommand(me, memory->leader_handle, ALIEN_COM_SCAV_TO_OBJ, ptr); |
| 1824 | } |
| 1825 | |
| 1826 | // Otherwise, set the destination object |
| 1827 | memory->dest_object_handle = *(int *)ptr; |
| 1828 | |
| 1829 | // Switch to hunting mode |
| 1830 | SetMode(me, ALIEN_SCAVENGING); |
| 1831 | |
| 1832 | // If leading, tell the squad to do the same |
| 1833 | if (memory->squad_flags & ALIEN_LEADER) { |
| 1834 | int mode = ALIEN_SCAVENGING; |
| 1835 | IssueSquadOrder(me, ALIEN_COM_SET_MODE, &mode); |
| 1836 | } |
| 1837 | |
| 1838 | return true; |
| 1839 | } break; |
| 1840 | } |
| 1841 | |
| 1842 | // mprintf(0, "AlienOrganism action %d failed\n"); |
| 1843 | return false; |
| 1844 | } |
| 1845 | |
| 1846 | // Sends a command (rhetorical) to all of a leader's teammates |
| 1847 | bool AlienOrganism::IssueSquadOrder(int leader_handle, char command, void *ptr) { |
| 1848 | for (int j = 0; j < memory->num_teammates; j++) |
| 1849 | SendCommand(leader_handle, memory->teammate[j].handle, command, ptr); |
| 1850 | |
| 1851 | return true; |
| 1852 | } |
| 1853 | |
| 1854 | // Returns true if mode is one of the landed modes |
| 1855 | bool AlienOrganism::IsLandedMode(int mode) { |
| 1856 | if (mode == ALIEN_LANDED || mode == ALIEN_LANDED_RESTING || mode == ALIEN_LANDED_HEALING || |
| 1857 | mode == ALIEN_LANDED_DEPOSITING || mode == ALIEN_LANDED_WITHDRAWING) |
| 1858 | return true; |
| 1859 | |
| 1860 | return false; |
| 1861 | } |
| 1862 | |
| 1863 | // Returns true if mode is one of the energy related landed modes |
| 1864 | bool AlienOrganism::IsEnergyRelatedLandedMode(int mode) { |
| 1865 | if (mode == ALIEN_LANDED_HEALING || mode == ALIEN_LANDED_DEPOSITING || mode == ALIEN_LANDED_WITHDRAWING) |
| 1866 | return true; |
| 1867 | |
| 1868 | return false; |
| 1869 | } |
| 1870 | |
| 1871 | // Returns true if current mode warrants fighting back when hit by player |
| 1872 | bool AlienOrganism::ModeIsAttackSensitive(int mode, int pending_mode) { |
| 1873 | // Make sure we're not already in an attack mode |
| 1874 | if (mode != ALIEN_ATTACKING_MELEE && mode != ALIEN_ATTACKING_RANGED) { |
| 1875 | // Make sure we're not healing, giving birth, or fleeing |
| 1876 | if (mode != ALIEN_FLEEING && mode != ALIEN_LANDING_AT_HOME && mode != ALIEN_LANDED_HEALING && |
| 1877 | (mode != ALIEN_LANDED_DEPOSITING || rand() % 100 < 2) && |
| 1878 | (mode != ALIEN_LANDED_WITHDRAWING || rand() % 100 < 5) && pending_mode != ALIEN_LANDED_HEALING && |
| 1879 | pending_mode != ALIEN_LANDED_DEPOSITING && pending_mode != ALIEN_LANDED_WITHDRAWING && |
| 1880 | mode != ALIEN_FINDING_BIRTHPLACE && mode != ALIEN_GIVING_BIRTH) { |
| 1881 | return true; |
| 1882 | } |
| 1883 | } |
| 1884 | |
| 1885 | return false; |
| 1886 | } |
| 1887 | |
| 1888 | // These are the modes from which a leader may attempt to recruit squadies |
| 1889 | bool AlienOrganism::ModeSupportsSquadRecruitment(int mode) { |
| 1890 | if (mode == ALIEN_LANDED_RESTING || mode == ALIEN_HUNTING || mode == ALIEN_SCAVENGING || |
| 1891 | mode == ALIEN_ATTACKING_MELEE) |
| 1892 | return true; |
| 1893 | |
| 1894 | return false; |
| 1895 | } |
| 1896 | |
| 1897 | // These are the modes from which an alien may enlist in a squad |
| 1898 | bool AlienOrganism::ModeSupportsSquadEnlistment(int mode, int pending_mode, int recruiter_mode) { |
| 1899 | // If recruiter is landed resting, only join if we are too |
| 1900 | if (recruiter_mode == ALIEN_LANDED_RESTING && mode != ALIEN_LANDED_RESTING) |
| 1901 | return false; |
| 1902 | |
| 1903 | if (mode == ALIEN_LANDED_RESTING || (mode == ALIEN_GOING_HOME && pending_mode == ALIEN_LANDED_RESTING) || |
| 1904 | mode == ALIEN_HUNTING || mode == ALIEN_SCAVENGING || mode == ALIEN_ATTACKING_MELEE) |
| 1905 | return true; |
| 1906 | |
| 1907 | return false; |
| 1908 | } |
| 1909 | |
| 1910 | // These are the modes in which a squadie may follow formation movement |
| 1911 | bool AlienOrganism::ModeSupportsSquadMovement(int mode) { |
| 1912 | if (mode == ALIEN_HUNTING || mode == ALIEN_SCAVENGING || mode == ALIEN_ATTACKING_MELEE) |
| 1913 | return true; |
| 1914 | |
| 1915 | return false; |
| 1916 | } |
| 1917 | |
| 1918 | // Tells all current teammates that they are on their own again |
| 1919 | void AlienOrganism::DisperseSquad(int me) { |
| 1920 | if (!(memory->squad_flags & ALIEN_LEADER)) |
| 1921 | return; |
| 1922 | |
| 1923 | for (int i = 0; i < memory->num_teammates; i++) { |
| 1924 | SendCommand(me, memory->teammate[i].handle, ALIEN_COM_LEAVE_ME, NULL); |
| 1925 | } |
| 1926 | |
| 1927 | memory->squad_flags = 0; |
| 1928 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 1929 | memory->num_teammates = 0; |
| 1930 | } |
| 1931 | |
| 1932 | // Tells all current teammates that they are to leave the squad and enter the given mode |
| 1933 | void AlienOrganism::DisperseSquadToMode(int me, int mode) { |
| 1934 | if (!(memory->squad_flags & ALIEN_LEADER)) |
| 1935 | return; |
| 1936 | |
| 1937 | for (int i = 0; i < memory->num_teammates; i++) { |
| 1938 | SendCommand(me, memory->teammate[i].handle, ALIEN_COM_LEAVE_ME_FOR_MODE, &mode); |
| 1939 | } |
| 1940 | |
| 1941 | memory->squad_flags = 0; |
| 1942 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 1943 | memory->num_teammates = 0; |
| 1944 | } |
| 1945 | |
| 1946 | bool AlienOrganism::LeaveLeader(int me) { |
| 1947 | if (!(memory->squad_flags & ALIEN_SQUADIE)) |
| 1948 | return true; |
| 1949 | |
| 1950 | SendCommand(me, memory->leader_handle, ALIEN_COM_LEAVING_YOU, NULL); |
| 1951 | memory->squad_flags = 0; |
| 1952 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 1953 | memory->num_teammates = 0; |
| 1954 | |
| 1955 | return true; |
| 1956 | } |
| 1957 | |
| 1958 | // Attempts to make an alien flee (returns true if it does, false otherwise) |
| 1959 | bool AlienOrganism::Flee(int me, bool force_flee /*=false*/) { |
| 1960 | // If we're a squadie, tell the leader we are leaving |
| 1961 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 1962 | if (!force_flee) { |
| 1963 | // do squadie saving throw |
| 1964 | if ((rand() % 100) < ALIEN_SQUADIE_FLEE_SAVING_THROW) |
| 1965 | return false; |
| 1966 | } |
| 1967 | |
| 1968 | LeaveLeader(me); |
| 1969 | } |
| 1970 | |
| 1971 | // If we're a leader, disperse the squad |
| 1972 | if (memory->squad_flags & ALIEN_LEADER) { |
| 1973 | if (!force_flee) { |
| 1974 | // do leader saving throw |
| 1975 | if ((rand() % 100) < ALIEN_LEADER_FLEE_SAVING_THROW) |
| 1976 | return false; |
| 1977 | } |
| 1978 | |
| 1979 | DisperseSquad(me); |
| 1980 | } |
| 1981 | |
| 1982 | // Ok, let's flee |
| 1983 | SetMode(me, ALIEN_FLEEING); |
| 1984 | // mprintf(0,"Alien is fleeing!\n"); |
| 1985 | |
| 1986 | return true; |
| 1987 | } |
| 1988 | |
| 1989 | // Attempts to make an alien attack (and his squad if leading one) |
| 1990 | bool AlienOrganism::MeleeAttack(int me, bool force_attack /*=false*/) { |
| 1991 | // If leading squad, tell squad to switch to melee mode |
| 1992 | if (memory->squad_flags & ALIEN_LEADER) { |
| 1993 | int mode = ALIEN_ATTACKING_MELEE; |
| 1994 | IssueSquadOrder(me, ALIEN_COM_SET_MODE, &mode); |
| 1995 | } |
| 1996 | |
| 1997 | // Attack target! |
| 1998 | SetMode(me, ALIEN_ATTACKING_MELEE); |
| 1999 | |
| 2000 | // mprintf(0,"Alien is switching to Melee Attack mode!\n"); |
| 2001 | |
| 2002 | return true; |
| 2003 | } |
| 2004 | |
| 2005 | // Makes an alien go into ranged attack mode |
| 2006 | bool AlienOrganism::RangedAttack(int me) { |
| 2007 | // If we're a squadie, tell the leader we are leaving |
| 2008 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 2009 | LeaveLeader(me); |
| 2010 | } |
| 2011 | |
| 2012 | // If we're a leader, disperse the squad |
| 2013 | if (memory->squad_flags & ALIEN_LEADER) { |
| 2014 | DisperseSquad(me); |
| 2015 | } |
| 2016 | |
| 2017 | SetMode(me, ALIEN_ATTACKING_RANGED); |
| 2018 | // mprintf(0,"Alien is switching to ranged attack mode!\n"); |
| 2019 | |
| 2020 | return true; |
| 2021 | } |
| 2022 | |
| 2023 | // Makes an alien go into ranged attack mode |
| 2024 | bool AlienOrganism::Heal(int me) { |
| 2025 | |
| 2026 | // If we're a squadie, tell the leader we are leaving |
| 2027 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 2028 | LeaveLeader(me); |
| 2029 | } |
| 2030 | |
| 2031 | // If we're a leader, disperse the squad |
| 2032 | if (memory->squad_flags & ALIEN_LEADER) { |
| 2033 | DisperseSquad(me); |
| 2034 | } |
| 2035 | |
| 2036 | // mprintf(0,"Heading home to heal...\n"); |
| 2037 | |
| 2038 | // Ok, let's go home and heal |
| 2039 | memory->pending_mode = ALIEN_LANDED_HEALING; |
| 2040 | SetMode(me, ALIEN_GOING_HOME); |
| 2041 | |
| 2042 | return true; |
| 2043 | } |
| 2044 | |
| 2045 | // Makes an alien go into ranged attack mode |
| 2046 | bool AlienOrganism::Deposit(int me) { |
| 2047 | // If we're a squadie, tell the leader we are leaving |
| 2048 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 2049 | LeaveLeader(me); |
| 2050 | } |
| 2051 | |
| 2052 | // If we're a leader, disperse the squad |
| 2053 | if (memory->squad_flags & ALIEN_LEADER) { |
| 2054 | DisperseSquad(me); |
| 2055 | } |
| 2056 | |
| 2057 | // mprintf(0,"Alien is going home to deposit...\n"); |
| 2058 | |
| 2059 | memory->pending_mode = ALIEN_LANDED_DEPOSITING; |
| 2060 | SetMode(me, ALIEN_GOING_HOME); |
| 2061 | |
| 2062 | return true; |
| 2063 | } |
| 2064 | |
| 2065 | // Makes an alien go into ranged attack mode |
| 2066 | bool AlienOrganism::Withdraw(int me) { |
| 2067 | // If we're a squadie, tell the leader we are leaving |
| 2068 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 2069 | LeaveLeader(me); |
| 2070 | } |
| 2071 | |
| 2072 | // If we're a leader, disperse the squad |
| 2073 | if (memory->squad_flags & ALIEN_LEADER) { |
| 2074 | DisperseSquad(me); |
| 2075 | } |
| 2076 | |
| 2077 | // mprintf(0,"Alien is going home to withdraw...\n"); |
| 2078 | |
| 2079 | memory->pending_mode = ALIEN_LANDED_WITHDRAWING; |
| 2080 | SetMode(me, ALIEN_GOING_HOME); |
| 2081 | |
| 2082 | return true; |
| 2083 | } |
| 2084 | |
| 2085 | // Checks to see if we can join the leader |
| 2086 | bool AlienOrganism::WillJoinLeader(int me, int leader_handle, int priority) { |
| 2087 | // Get the recruiter's current mode |
| 2088 | int recruiter_mode; |
| 2089 | SendCommand(me, leader_handle, ALIEN_COM_GET_MODE, &recruiter_mode); |
| 2090 | |
| 2091 | // If can't join a squad in current mode, decline offer |
| 2092 | if (!ModeSupportsSquadEnlistment(memory->mode, memory->pending_mode, recruiter_mode)) |
| 2093 | return false; |
| 2094 | |
| 2095 | // If not currently in a squad, possibly join up |
| 2096 | if (memory->squad_flags == 0) { |
| 2097 | // Only join 60% of the time (to help prevent mass join slowdowns) |
| 2098 | if (rand() % 100 > 60) |
| 2099 | return false; |
| 2100 | |
| 2101 | memory->leader_handle = leader_handle; |
| 2102 | memory->squad_flags |= ALIEN_SQUADIE; |
| 2103 | return true; |
| 2104 | } |
| 2105 | |
| 2106 | return false; |
| 2107 | } |
| 2108 | |
| 2109 | // Returns the Teammate ID for a given handle (returns -1 if not on team) |
| 2110 | int AlienOrganism::FindTeammateID(int tm_handle) { |
| 2111 | for (int i = 0; i < memory->num_teammates; i++) { |
| 2112 | if (memory->teammate[i].handle == tm_handle) |
| 2113 | return i; |
| 2114 | } |
| 2115 | |
| 2116 | return -1; |
| 2117 | } |
| 2118 | |
| 2119 | // Calculates a squad position for given teammate based on leader's mode |
| 2120 | int AlienOrganism::CalcFormationPosition(int me, int tm_ID, vector *pos) { |
| 2121 | vector me_pos, goal_pos; |
| 2122 | matrix orient; |
| 2123 | |
| 2124 | Obj_Value(me, VF_GET, OBJV_V_POS, &me_pos); |
| 2125 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 2126 | |
| 2127 | goal_pos = me_pos; |
| 2128 | |
| 2129 | switch (memory->mode) { |
| 2130 | // When hunting, form a horizontal diamond |
| 2131 | case ALIEN_HUNTING: { |
| 2132 | switch (tm_ID) { |
| 2133 | case 0: |
| 2134 | goal_pos -= orient.fvec * ALIEN_FO_HUNT_FVEC; |
| 2135 | goal_pos += orient.rvec * ALIEN_FO_HUNT_RVEC; |
| 2136 | break; |
| 2137 | case 1: |
| 2138 | goal_pos -= orient.fvec * ALIEN_FO_HUNT_FVEC; |
| 2139 | goal_pos -= orient.rvec * ALIEN_FO_HUNT_RVEC; |
| 2140 | break; |
| 2141 | case 2: |
| 2142 | goal_pos -= orient.fvec * ALIEN_FO_HUNT_FVEC * 2.0f; |
| 2143 | break; |
| 2144 | } |
| 2145 | } break; |
| 2146 | |
| 2147 | // When scavenging, form a scavenge line |
| 2148 | case ALIEN_SCAVENGING: { |
| 2149 | switch (tm_ID) { |
| 2150 | case 0: |
| 2151 | goal_pos -= orient.fvec * ALIEN_FO_SCAV_FVEC; |
| 2152 | goal_pos -= orient.rvec * ALIEN_FO_SCAV_RVEC; |
| 2153 | break; |
| 2154 | case 1: |
| 2155 | goal_pos -= orient.fvec * ALIEN_FO_SCAV_FVEC * 2.0f; |
| 2156 | goal_pos += orient.rvec * ALIEN_FO_SCAV_RVEC; |
| 2157 | break; |
| 2158 | case 2: |
| 2159 | goal_pos -= orient.fvec * ALIEN_FO_SCAV_FVEC * 3.0f; |
| 2160 | break; |
| 2161 | } |
| 2162 | } break; |
| 2163 | |
| 2164 | // When attacking, form a vertical triangle |
| 2165 | case ALIEN_ATTACKING_MELEE: |
| 2166 | case ALIEN_ATTACKING_RANGED: { |
| 2167 | switch (tm_ID) { |
| 2168 | case 0: |
| 2169 | goal_pos += orient.fvec * ALIEN_FO_ATTK_FVEC; |
| 2170 | goal_pos -= orient.uvec * ALIEN_FO_ATTK_UVECN; |
| 2171 | goal_pos += orient.rvec * ALIEN_FO_ATTK_RVEC; |
| 2172 | break; |
| 2173 | case 1: |
| 2174 | goal_pos += orient.fvec * ALIEN_FO_ATTK_FVEC; |
| 2175 | goal_pos -= orient.uvec * ALIEN_FO_ATTK_UVECN; |
| 2176 | goal_pos -= orient.rvec * ALIEN_FO_ATTK_RVEC; |
| 2177 | break; |
| 2178 | case 2: |
| 2179 | goal_pos += orient.fvec * ALIEN_FO_ATTK_FVEC; |
| 2180 | goal_pos += orient.uvec * ALIEN_FO_ATTK_UVECP; |
| 2181 | break; |
| 2182 | } |
| 2183 | } break; |
| 2184 | } |
| 2185 | |
| 2186 | // Return the goal position |
| 2187 | (*pos) = goal_pos; |
| 2188 | return true; |
| 2189 | } |
| 2190 | |
| 2191 | void AlienOrganism::SetSquadieFormationGoal(int me) { |
| 2192 | float cd = .1f; |
| 2193 | float temp = 0.0f; |
| 2194 | |
| 2195 | // Do the get to position goal for when squadie can't see leader |
| 2196 | SendCommand(me, memory->leader_handle, ALIEN_COM_GET_GOAL_POS, &memory->squad_goal_pos); |
| 2197 | AI_GoalValue(me, 1, VF_SET, AIGV_V_POS, &memory->squad_goal_pos); |
| 2198 | |
| 2199 | SendCommand(me, memory->leader_handle, ALIEN_COM_GET_GOAL_ROOM, &memory->squad_goal_room); |
| 2200 | AI_GoalValue(me, 1, VF_SET, AIGV_I_ROOMNUM, &memory->squad_goal_room); |
| 2201 | |
| 2202 | AI_AddGoal(me, AIG_GET_TO_POS, 1, 1.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, &memory->squad_goal_pos, |
| 2203 | memory->squad_goal_room); |
| 2204 | AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &cd); |
| 2205 | |
| 2206 | // Do the custom goal for when squadie can see leader (similar to use bline when sees goal) |
| 2207 | AI_AddGoal(me, AIG_SCRIPTED, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, NULL); |
| 2208 | AI_GoalAddEnabler(me, 2, AIE_SCRIPTED, 1.0, 0.0, &temp); |
| 2209 | } |
| 2210 | |
| 2211 | void AlienOrganism::UpdateSquadieFormationGoal(int me) { |
| 2212 | // Update the squadie positions |
| 2213 | SendCommand(me, memory->leader_handle, ALIEN_COM_GET_GOAL_POS, &memory->squad_goal_pos); |
| 2214 | AI_GoalValue(me, 1, VF_SET, AIGV_V_POS, &memory->squad_goal_pos); |
| 2215 | |
| 2216 | SendCommand(me, memory->leader_handle, ALIEN_COM_GET_GOAL_ROOM, &memory->squad_goal_room); |
| 2217 | AI_GoalValue(me, 1, VF_SET, AIGV_I_ROOMNUM, &memory->squad_goal_room); |
| 2218 | } |
| 2219 | |
| 2220 | void AlienOrganism::SetWanderGoal(int me) { |
| 2221 | vector pos; |
| 2222 | int room = 0; |
| 2223 | float dist = 15.0f; |
| 2224 | |
| 2225 | // If the destination object is valid, set the goals to go to that object |
| 2226 | if (memory->dest_object_handle != OBJECT_HANDLE_NONE) { |
| 2227 | int type; |
| 2228 | Obj_Value(memory->dest_object_handle, VF_GET, OBJV_I_TYPE, &type); |
| 2229 | if (type != OBJ_NONE) { |
| 2230 | AI_AddGoal(me, AIG_GET_TO_OBJ, 2, 1.0f, ALIEN_GUID_GOT_TO_DEST_OBJ, |
| 2231 | GF_ORIENT_VELOCITY | GF_USE_BLINE_IF_SEES_GOAL | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, |
| 2232 | memory->dest_object_handle); |
| 2233 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 2234 | |
| 2235 | return; |
| 2236 | } |
| 2237 | memory->dest_object_handle = OBJECT_HANDLE_NONE; |
| 2238 | } |
| 2239 | |
| 2240 | // Set the goal to wander |
| 2241 | AI_AddGoal(me, AIG_WANDER_AROUND, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, room, room); |
| 2242 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 2243 | } |
| 2244 | |
| 2245 | // Removes a teammate from the squad |
| 2246 | void AlienOrganism::RemoveTeammate(int tm_id) { |
| 2247 | for (int j = tm_id; j < memory->num_teammates - 1; j++) { |
| 2248 | memory->teammate[j] = memory->teammate[j + 1]; |
| 2249 | } |
| 2250 | |
| 2251 | memory->num_teammates--; |
| 2252 | } |
| 2253 | |
| 2254 | // Called by a leader to update his squad list (removes any that have died) |
| 2255 | void AlienOrganism::UpdateSquadList(int me) { |
| 2256 | if (!(memory->squad_flags & ALIEN_LEADER)) |
| 2257 | return; |
| 2258 | |
| 2259 | for (int i = 0; i < memory->num_teammates; i++) { |
| 2260 | int type; |
| 2261 | Obj_Value(memory->teammate[i].handle, VF_GET, OBJV_I_TYPE, &type); |
| 2262 | if (type == OBJ_NONE) { |
| 2263 | RemoveTeammate(i); |
| 2264 | i--; |
| 2265 | } |
| 2266 | } |
| 2267 | } |
| 2268 | |
| 2269 | // Updates the squad (recruitment, etc.) |
| 2270 | void AlienOrganism::UpdateSquad(int me) { |
| 2271 | // If me's a squadie, get outta here |
| 2272 | if (memory->squad_flags & ALIEN_SQUADIE) |
| 2273 | return; |
| 2274 | |
| 2275 | // Remove any dead teammates |
| 2276 | if (memory->squad_flags & ALIEN_LEADER) { |
| 2277 | UpdateSquadList(me); |
| 2278 | |
| 2279 | if (memory->num_teammates == 0) |
| 2280 | memory->squad_flags = 0; |
| 2281 | |
| 2282 | if (memory->num_teammates >= ALIEN_MAX_TEAMMATES) |
| 2283 | return; |
| 2284 | } |
| 2285 | |
| 2286 | // If can't recruit in current mode get outta here |
| 2287 | if (!ModeSupportsSquadRecruitment(memory->mode)) |
| 2288 | return; |
| 2289 | |
| 2290 | // Try to recruit some teammates |
| 2291 | int scan_objs[25]; |
| 2292 | int n_scan; |
| 2293 | int room; |
| 2294 | vector pos; |
| 2295 | int i; |
| 2296 | |
| 2297 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 2298 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 2299 | |
| 2300 | n_scan = AI_GetNearbyObjs(&pos, room, ALIEN_SQUAD_RECRUIT_RADIUS, scan_objs, 25, false, true, false, true); |
| 2301 | |
| 2302 | for (i = 0; i < n_scan; i++) { |
| 2303 | uint16_t id; |
| 2304 | Obj_Value(scan_objs[i], VF_GET, OBJV_US_ID, &id); |
| 2305 | |
| 2306 | // this is more rare than the types matching; so, do it first |
| 2307 | if (id == alien_organism_id) { |
| 2308 | int type; |
| 2309 | Obj_Value(scan_objs[i], VF_GET, OBJV_I_TYPE, &type); |
| 2310 | if (type == OBJ_ROBOT && scan_objs[i] != me) { |
| 2311 | // Make sure this guy isn't already a squadmate |
| 2312 | bool already_on_team = false; |
| 2313 | if (memory->squad_flags & ALIEN_LEADER) { |
| 2314 | if (FindTeammateID(scan_objs[i]) >= 0) |
| 2315 | already_on_team = true; |
| 2316 | } |
| 2317 | |
| 2318 | if (!already_on_team) { |
| 2319 | // Try and recruit him |
| 2320 | int priority = MEDIUM_PRIORITY; |
| 2321 | if (SendCommand(me, scan_objs[i], ALIEN_COM_JOIN_ME, &priority)) { |
| 2322 | // If not currently a leader, it's time to become one |
| 2323 | if (!(memory->squad_flags & ALIEN_LEADER)) { |
| 2324 | memory->squad_flags = ALIEN_LEADER; |
| 2325 | memory->num_teammates = 0; |
| 2326 | |
| 2327 | // Reset the current mode to take squad grouping into account |
| 2328 | SetMode(me, memory->mode); |
| 2329 | } |
| 2330 | memory->teammate[memory->num_teammates++].handle = scan_objs[i]; |
| 2331 | |
| 2332 | // Tell squadie whether he should be in formation or not |
| 2333 | int sflags = ALIEN_BROKEN; |
| 2334 | if (memory->squad_flags & ALIEN_BROKEN) |
| 2335 | SendCommand(me, scan_objs[i], ALIEN_COM_SET_SQUAD_FLAGS, &sflags); |
| 2336 | else |
| 2337 | SendCommand(me, scan_objs[i], ALIEN_COM_CLEAR_SQUAD_FLAGS, &sflags); |
| 2338 | |
| 2339 | // Tell squadie to set his mode to the leader's mode |
| 2340 | int mode = memory->mode; |
| 2341 | SendCommand(me, scan_objs[i], ALIEN_COM_SET_MODE, &mode); |
| 2342 | } |
| 2343 | } |
| 2344 | } |
| 2345 | } |
| 2346 | |
| 2347 | // If squad is full get outta here |
| 2348 | if (memory->num_teammates >= ALIEN_MAX_TEAMMATES) |
| 2349 | return; |
| 2350 | } |
| 2351 | } |
| 2352 | |
| 2353 | // Checks which of my boys I can see |
| 2354 | void AlienOrganism::UpdateSquadVisibility(int me) { |
| 2355 | int i, flags, fate; |
| 2356 | vector start_pos, end_pos; |
| 2357 | int start_room; |
| 2358 | ray_info ray; |
| 2359 | |
| 2360 | // First, remove any dead squadies |
| 2361 | UpdateSquadList(me); |
| 2362 | |
| 2363 | // Get my room and position |
| 2364 | Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos); |
| 2365 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room); |
| 2366 | |
| 2367 | // Do the visibility check for each teammate |
| 2368 | for (i = 0; i < memory->num_teammates; i++) { |
| 2369 | // Get teammate's position |
| 2370 | Obj_Value(memory->teammate[i].handle, VF_GET, OBJV_V_POS, &end_pos); |
| 2371 | |
| 2372 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 2373 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 2374 | fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, 1.0f, flags, &ray); |
| 2375 | |
| 2376 | // Set whether or not this guy is visible |
| 2377 | memory->teammate[i].is_visible = (fate == HIT_NONE) ? true : false; |
| 2378 | } |
| 2379 | } |
| 2380 | |
| 2381 | // Checks to see if any fire blobs are nearby |
| 2382 | bool AlienOrganism::IsNearFire(int me) { return false; } |
| 2383 | |
| 2384 | // Checks to see if alien is currently on fire |
| 2385 | bool AlienOrganism::IsOnFire(int me) { return (Obj_IsEffect(me, EF_NAPALMED)); } |
| 2386 | |
| 2387 | #define ALIEN_MAX_BEAM_DIST 30.0f |
| 2388 | #define ALIEN_ATTEMPT_BEAM_DIST 40.0f |
| 2389 | |
| 2390 | void AlienOrganism::ProjectBeam(int me, int pos_handle, vector *start_pos, int start_room, vector *beam_dir, |
| 2391 | matrix *orient, int beam_flag) { |
| 2392 | ray_info ray; |
| 2393 | int flags, fate; |
| 2394 | vector end_pos, landing_pos; |
| 2395 | int landing_room; |
| 2396 | float dist; |
| 2397 | |
| 2398 | // Calculate beam's destination |
| 2399 | end_pos = (*start_pos) + ((*beam_dir) * ALIEN_ATTEMPT_BEAM_DIST); |
| 2400 | |
| 2401 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 2402 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 2403 | fate = FVI_RayCast(me, start_pos, &end_pos, start_room, 0.0f, flags, &ray); |
| 2404 | |
| 2405 | landing_pos = ray.hit_point; |
| 2406 | landing_room = ray.hit_room; |
| 2407 | |
| 2408 | // If beam is within certain distance, move the destination object to destination position |
| 2409 | dist = vm_VectorDistance(start_pos, &landing_pos); |
| 2410 | if (dist < ALIEN_MAX_BEAM_DIST) { |
| 2411 | msafe_struct mstruct; |
| 2412 | mstruct.objhandle = pos_handle; |
| 2413 | mstruct.pos = landing_pos; |
| 2414 | mstruct.orient = (*orient); |
| 2415 | mstruct.roomnum = landing_room; |
| 2416 | MSafe_CallFunction(MSAFE_OBJECT_WORLD_POSITION, &mstruct); |
| 2417 | |
| 2418 | // Mark this beam as enabled |
| 2419 | memory->enabled_beams |= beam_flag; |
| 2420 | } |
| 2421 | } |
| 2422 | |
| 2423 | // Calculates positions and moves invisible powerups to them |
| 2424 | void AlienOrganism::CalcEnergyBeamPositions(int me) { |
| 2425 | int start_room; |
| 2426 | vector beam1_dir, beam2_dir, beam3_dir; |
| 2427 | vector start_pos; |
| 2428 | matrix orient; |
| 2429 | |
| 2430 | // Get our object's pos and orientation |
| 2431 | Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos); |
| 2432 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 2433 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room); |
| 2434 | |
| 2435 | // If we're in a beam mode, get the appropriate beam directions |
| 2436 | if (memory->mode == ALIEN_LANDED_DEPOSITING) { |
| 2437 | beam1_dir = -0.40f * orient.uvec - orient.fvec; |
| 2438 | // beam1_dir += orient.rvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f); |
| 2439 | vm_VectorNormalize(&beam1_dir); |
| 2440 | |
| 2441 | beam2_dir = -0.40f * orient.uvec + orient.fvec - orient.rvec; |
| 2442 | // beam2_dir += orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f); |
| 2443 | vm_VectorNormalize(&beam2_dir); |
| 2444 | |
| 2445 | beam3_dir = -0.40f * orient.uvec + orient.fvec + orient.rvec; |
| 2446 | // beam3_dir += orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f); |
| 2447 | vm_VectorNormalize(&beam3_dir); |
| 2448 | } else if (memory->mode == ALIEN_LANDED_WITHDRAWING) { |
| 2449 | beam1_dir = -0.3f * orient.uvec + orient.fvec; |
| 2450 | // beam1_dir += orient.rvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f); |
| 2451 | vm_VectorNormalize(&beam1_dir); |
| 2452 | |
| 2453 | beam2_dir = -0.3f * orient.uvec - orient.fvec - orient.rvec; |
| 2454 | // beam2_dir -= orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f); |
| 2455 | vm_VectorNormalize(&beam2_dir); |
| 2456 | |
| 2457 | beam3_dir = -0.3f * orient.uvec - orient.fvec + orient.rvec; |
| 2458 | // beam3_dir -= orient.fvec*(0.5f-((float)rand()/(float)D3_RAND_MAX)*1.0f); |
| 2459 | vm_VectorNormalize(&beam3_dir); |
| 2460 | } else if (memory->mode == ALIEN_LANDED_HEALING) { |
| 2461 | beam2_dir = -0.4f * orient.uvec + orient.rvec * 2.0f; |
| 2462 | vm_VectorNormalize(&beam2_dir); |
| 2463 | |
| 2464 | beam3_dir = -0.4f * orient.uvec - orient.rvec * 2.0f; |
| 2465 | vm_VectorNormalize(&beam3_dir); |
| 2466 | } else { |
| 2467 | return; |
| 2468 | } |
| 2469 | |
| 2470 | // All beams off initially |
| 2471 | memory->enabled_beams = 0; |
| 2472 | |
| 2473 | // Project the three beams |
| 2474 | if (memory->mode != ALIEN_LANDED_HEALING) { |
| 2475 | ProjectBeam(me, memory->pos1_handle, &start_pos, start_room, &beam1_dir, &orient, ALIEN_BEAM1); |
| 2476 | } |
| 2477 | ProjectBeam(me, memory->pos2_handle, &start_pos, start_room, &beam2_dir, &orient, ALIEN_BEAM2); |
| 2478 | ProjectBeam(me, memory->pos3_handle, &start_pos, start_room, &beam3_dir, &orient, ALIEN_BEAM3); |
| 2479 | |
| 2480 | // Set flag so that this calculation is only done once |
| 2481 | memory->energy_beams_on = true; |
| 2482 | } |
| 2483 | |
| 2484 | // Creates the different lightning beam effects |
| 2485 | void AlienOrganism::UpdateEnergyBeams(int me) { |
| 2486 | int b1_obj1, b1_obj2; |
| 2487 | int b2_obj1, b2_obj2; |
| 2488 | int b3_obj1, b3_obj2; |
| 2489 | int b1_texture_id; |
| 2490 | int b2_texture_id; |
| 2491 | int b3_texture_id; |
| 2492 | |
| 2493 | if (!memory->energy_beams_on) |
| 2494 | return; |
| 2495 | |
| 2496 | // See if it's time to create the next energy effect |
| 2497 | if (memory->next_update_beam_time <= Game_GetTime()) { |
| 2498 | float next_duration = ALIEN_BEAM_UPDATE_TIME /*+ ((float)rand()/(float)D3_RAND_MAX)*0.2f*/; |
| 2499 | memory->next_update_beam_time = Game_GetTime() + next_duration; |
| 2500 | |
| 2501 | if (memory->mode == ALIEN_LANDED_DEPOSITING) { |
| 2502 | b1_obj1 = memory->pos1_handle; |
| 2503 | b1_obj2 = me; |
| 2504 | b1_texture_id = transfer_effect_id; |
| 2505 | |
| 2506 | b2_obj1 = memory->pos2_handle; |
| 2507 | b2_obj2 = me; |
| 2508 | b2_texture_id = transfer_effect_id; |
| 2509 | |
| 2510 | b3_obj1 = memory->pos3_handle; |
| 2511 | b3_obj2 = me; |
| 2512 | b3_texture_id = transfer_effect_id; |
| 2513 | } else if (memory->mode == ALIEN_LANDED_WITHDRAWING) { |
| 2514 | b1_obj1 = me; |
| 2515 | b1_obj2 = memory->pos1_handle; |
| 2516 | b1_texture_id = transfer_effect_id; |
| 2517 | |
| 2518 | b2_obj1 = me; |
| 2519 | b2_obj2 = memory->pos2_handle; |
| 2520 | b2_texture_id = transfer_effect_id; |
| 2521 | |
| 2522 | b3_obj1 = me; |
| 2523 | b3_obj2 = memory->pos3_handle; |
| 2524 | b3_texture_id = transfer_effect_id; |
| 2525 | } else if (memory->mode == ALIEN_LANDED_HEALING) { |
| 2526 | b1_obj1 = memory->pos1_handle; |
| 2527 | b1_obj2 = me; |
| 2528 | b1_texture_id = heal_effect_id; |
| 2529 | |
| 2530 | b2_obj1 = me; |
| 2531 | b2_obj2 = memory->pos2_handle; |
| 2532 | b2_texture_id = heal_effect_id; |
| 2533 | |
| 2534 | b3_obj1 = me; |
| 2535 | b3_obj2 = memory->pos3_handle; |
| 2536 | b3_texture_id = heal_effect_id; |
| 2537 | } else { |
| 2538 | mprintf(0, "Invalid energy beam effect mode!\n"); |
| 2539 | return; |
| 2540 | } |
| 2541 | |
| 2542 | // Now create the beams |
| 2543 | if (memory->enabled_beams & ALIEN_BEAM1) { |
| 2544 | aLightningCreate(b1_obj1, b1_obj2, next_duration, 1.0f, 2, b1_texture_id, next_duration, 1, 255, 255, 255, false); |
| 2545 | } |
| 2546 | |
| 2547 | if (memory->enabled_beams & ALIEN_BEAM2) { |
| 2548 | aLightningCreate(b2_obj1, b2_obj2, next_duration, 1.0f, 2, b2_texture_id, next_duration, 1, 255, 255, 255, false); |
| 2549 | } |
| 2550 | |
| 2551 | if (memory->enabled_beams & ALIEN_BEAM3) { |
| 2552 | aLightningCreate(b3_obj1, b3_obj2, next_duration, 1.0f, 2, b3_texture_id, next_duration, 1, 255, 255, 255, false); |
| 2553 | } |
| 2554 | } |
| 2555 | } |
| 2556 | |
| 2557 | // Sets the correct energy effect for an alien |
| 2558 | void AlienOrganism::UpdateEnergyEffect(int me) { |
| 2559 | int room; |
| 2560 | vector pos; |
| 2561 | int weapon_id; |
| 2562 | |
| 2563 | // See if this object has an energy charge |
| 2564 | if (memory->energy_charges > 0.0f) { |
| 2565 | // See if it's time to create the next energy effect |
| 2566 | if (memory->next_update_energy_time <= Game_GetTime()) { |
| 2567 | float slow_down = 0.5f * (ALIEN_MAX_ENERGY_CHARGES - memory->energy_charges) / ALIEN_MAX_ENERGY_CHARGES; |
| 2568 | memory->next_update_energy_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 0.1f + 0.05f + slow_down; |
| 2569 | |
| 2570 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 2571 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 2572 | |
| 2573 | Obj_Create(OBJ_WEAPON, energy_effect_id, room, &pos, NULL, me); |
| 2574 | } |
| 2575 | } |
| 2576 | } |
| 2577 | |
| 2578 | // Sets the alien's max speed |
| 2579 | void AlienOrganism::SetMaxSpeed(int me, float speed) { AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed); } |
| 2580 | |
| 2581 | // Sets the alien's circle distance |
| 2582 | void AlienOrganism::SetCircleDist(int me, float dist) { AI_Value(me, VF_GET, AIV_F_CIRCLE_DIST, &dist); } |
| 2583 | |
| 2584 | // Sets the Current Mode |
| 2585 | void AlienOrganism::SetMode(int me, char mode) { |
| 2586 | // mprintf(0, "From mode %d, ",memory->mode); |
| 2587 | |
| 2588 | int flags; |
| 2589 | char movement_type; |
| 2590 | vector vel; |
| 2591 | |
| 2592 | // Clear out any goals |
| 2593 | AI_SafeSetType(me, AIT_AIS); |
| 2594 | |
| 2595 | // Set FOV to 360 |
| 2596 | float fov = -1.0f; |
| 2597 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 2598 | |
| 2599 | // Turn off ranged firing |
| 2600 | flags = AIF_DISABLE_FIRING; |
| 2601 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2602 | |
| 2603 | // Make it persistant |
| 2604 | flags = AIF_PERSISTANT; |
| 2605 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2606 | |
| 2607 | // Turn off the energy beams |
| 2608 | memory->energy_beams_on = false; |
| 2609 | |
| 2610 | // Do mode specific setups |
| 2611 | switch (mode) { |
| 2612 | case ALIEN_GOING_HOME: { |
| 2613 | // mprintf(0,"Going home mode set.\n"); |
| 2614 | |
| 2615 | ray_info ray; |
| 2616 | int fate; |
| 2617 | vector end_pos, landing_pos; |
| 2618 | int end_room, landing_room; |
| 2619 | |
| 2620 | // If currently landed, set take off velocity |
| 2621 | DoTakeoff(me, 8.0f, 3.0f); |
| 2622 | |
| 2623 | // Turn on friend avoidance |
| 2624 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2625 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2626 | |
| 2627 | // Set friend avoidance distance |
| 2628 | float avoid_dist = ALIEN_NORMAL_AVOID_DIST; |
| 2629 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2630 | SetCircleDist(me, memory->base_circle_distance); |
| 2631 | |
| 2632 | // Make it aware |
| 2633 | flags = AIF_FORCE_AWARENESS; |
| 2634 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2635 | |
| 2636 | // Clear wall point collision and axes lock |
| 2637 | flags = PF_POINT_COLLIDE_WALLS; |
| 2638 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2639 | |
| 2640 | // Set movement type back to physics for flying around |
| 2641 | movement_type = MT_PHYSICS; |
| 2642 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2643 | |
| 2644 | // Make sure squad broken flag isn't set |
| 2645 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 2646 | |
| 2647 | // Calculate destination home point a int16_t distance from actual landing point |
| 2648 | end_pos = memory->home_pos + (memory->home_uvec * 20.0f); |
| 2649 | |
| 2650 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 2651 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 2652 | fate = FVI_RayCast(me, &memory->home_pos, &end_pos, memory->home_room, 0.0f, flags, &ray); |
| 2653 | |
| 2654 | landing_pos = ray.hit_point; |
| 2655 | landing_room = ray.hit_room; |
| 2656 | |
| 2657 | // Set goal to head home |
| 2658 | AI_AddGoal(me, AIG_GET_TO_POS, 2, 1.0f, ALIEN_GUID_GOT_HOME, GF_ORIENT_VELOCITY, &landing_pos, landing_room); |
| 2659 | AI_SetGoalCircleDist(me, 2, 2.0f); |
| 2660 | |
| 2661 | // Set returning home speed |
| 2662 | SetMaxSpeed(me, memory->base_speed * ALIEN_RETURN_SPEED_MOD); |
| 2663 | |
| 2664 | // Clear the next activity time |
| 2665 | memory->next_activity_time = 0.0f; |
| 2666 | |
| 2667 | // Clear the next wander time |
| 2668 | memory->max_wander_time = 0.0f; |
| 2669 | } break; |
| 2670 | |
| 2671 | case ALIEN_LANDING_AT_HOME: { |
| 2672 | // mprintf(0,"Landing at home mode set.\n"); |
| 2673 | |
| 2674 | // If currently landed, set take off velocity |
| 2675 | DoTakeoff(me, 8.0f, 3.0f); |
| 2676 | |
| 2677 | // Turn off dodging |
| 2678 | flags = AIF_DODGE; |
| 2679 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2680 | |
| 2681 | // Turn off friend avoidance |
| 2682 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2683 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2684 | SetCircleDist(me, memory->base_circle_distance); |
| 2685 | |
| 2686 | // Turn on point-collide-walls and lock axes |
| 2687 | flags = PF_POINT_COLLIDE_WALLS | PF_LOCK_MASK; |
| 2688 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2689 | |
| 2690 | // Turn off auto-level |
| 2691 | flags = PF_LEVELING; |
| 2692 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2693 | |
| 2694 | // Make it aware |
| 2695 | flags = AIF_FORCE_AWARENESS; |
| 2696 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2697 | |
| 2698 | // Set movement type back to physics for flying around |
| 2699 | movement_type = MT_PHYSICS; |
| 2700 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2701 | |
| 2702 | // Make sure squad broken flag isn't set |
| 2703 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 2704 | |
| 2705 | // Make him land at his home point |
| 2706 | AI_AddGoal(me, AIG_GET_TO_POS, 2, 100.0f, ALIEN_GUID_LANDED, |
| 2707 | GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION | GF_ORIENT_SCRIPTED, &memory->home_pos, memory->home_room); |
| 2708 | AI_SetGoalCircleDist(me, 2, 0.0f); |
| 2709 | |
| 2710 | // Play his landing animation |
| 2711 | Obj_SetCustomAnim(me, 50, 72, 2.5f, 0, -1, -1); |
| 2712 | |
| 2713 | // Set landing speed |
| 2714 | SetMaxSpeed(me, memory->base_speed * ALIEN_LAND_SPEED_MOD); |
| 2715 | |
| 2716 | // Clear the next activity time |
| 2717 | memory->next_activity_time = 0.0f; |
| 2718 | |
| 2719 | // Clear the next wander time |
| 2720 | memory->max_wander_time = 0.0f; |
| 2721 | } break; |
| 2722 | |
| 2723 | case ALIEN_LANDED: |
| 2724 | case ALIEN_LANDED_RESTING: |
| 2725 | case ALIEN_LANDED_HEALING: |
| 2726 | case ALIEN_LANDED_DEPOSITING: |
| 2727 | case ALIEN_LANDED_WITHDRAWING: { |
| 2728 | // mprintf(0,"Landed mode set.\n"); |
| 2729 | |
| 2730 | // Turn off dodging |
| 2731 | flags = AIF_DODGE; |
| 2732 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2733 | |
| 2734 | // Turn off friend avoidance |
| 2735 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2736 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2737 | SetCircleDist(me, memory->base_circle_distance); |
| 2738 | |
| 2739 | // Turn off auto-level |
| 2740 | flags = PF_LEVELING; |
| 2741 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2742 | |
| 2743 | // Turn on point-collide-walls and lock axes |
| 2744 | flags = PF_POINT_COLLIDE_WALLS | PF_LOCK_MASK; |
| 2745 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2746 | |
| 2747 | // Get rid of forced awareness |
| 2748 | flags = AIF_FORCE_AWARENESS; |
| 2749 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2750 | |
| 2751 | // Get rid of persistance |
| 2752 | flags = AIF_PERSISTANT; |
| 2753 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2754 | |
| 2755 | // Set to barely aware |
| 2756 | float awareness = AWARE_BARELY; |
| 2757 | AI_Value(me, VF_SET, AIV_F_AWARENESS, &awareness); |
| 2758 | |
| 2759 | // No movement allowed |
| 2760 | movement_type = MT_NONE; |
| 2761 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2762 | |
| 2763 | // Set FOV to nearly 0 |
| 2764 | // float sleep_fov = 1.0f; |
| 2765 | // AI_Value(me, VF_SET, AIV_F_FOV, &sleep_fov); |
| 2766 | |
| 2767 | // Make sure squad broken flag isn't set |
| 2768 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 2769 | |
| 2770 | // If just landed, set it to the pending landed mode, and play looping idle anim |
| 2771 | if (mode == ALIEN_LANDED) { |
| 2772 | mode = memory->pending_mode; |
| 2773 | if (!IsLandedMode(mode)) { |
| 2774 | mode = ALIEN_LANDED_RESTING; |
| 2775 | } |
| 2776 | |
| 2777 | // Play his landed animation |
| 2778 | Obj_SetCustomAnim(me, 1, 10, 1, 0, -1, -1); |
| 2779 | } |
| 2780 | memory->pending_mode = ALIEN_LANDED_RESTING; |
| 2781 | memory->previous_mode = ALIEN_GOING_HOME; |
| 2782 | |
| 2783 | // Set landed speed |
| 2784 | SetMaxSpeed(me, 0.0f); |
| 2785 | |
| 2786 | // Set the next activity time |
| 2787 | if (mode == ALIEN_LANDED_RESTING) { |
| 2788 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 2.0f; |
| 2789 | memory->ok_to_deposit = true; |
| 2790 | } else { |
| 2791 | memory->next_activity_time = Game_GetTime() + ALIEN_LANDED_ACTION_TIME; |
| 2792 | } |
| 2793 | |
| 2794 | // Clear the next wander time |
| 2795 | memory->max_wander_time = 0.0f; |
| 2796 | } break; |
| 2797 | |
| 2798 | case ALIEN_HUNTING: { |
| 2799 | // mprintf(0,"Hunting mode set.\n"); |
| 2800 | |
| 2801 | // If currently landed, set take off velocity |
| 2802 | DoTakeoff(me, 8.0f, 3.0f); |
| 2803 | |
| 2804 | // Turn on friend avoidance |
| 2805 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2806 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2807 | |
| 2808 | // Only avoid friends alot if not in a squad |
| 2809 | if (memory->squad_flags == 0) { |
| 2810 | float avoid_dist = ALIEN_NORMAL_AVOID_DIST; |
| 2811 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2812 | SetCircleDist(me, memory->base_circle_distance); |
| 2813 | } else { |
| 2814 | float avoid_dist = ALIEN_SQUAD_AVOID_DIST; |
| 2815 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2816 | SetCircleDist(me, memory->base_circle_distance * ALIEN_SQUAD_CIRC_DIST_MOD); |
| 2817 | } |
| 2818 | |
| 2819 | // Make it aware |
| 2820 | flags = AIF_FORCE_AWARENESS; |
| 2821 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2822 | |
| 2823 | // Clear wall point collision and axes lock |
| 2824 | flags = PF_POINT_COLLIDE_WALLS; |
| 2825 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2826 | |
| 2827 | // Set movement type back to physics for flying around |
| 2828 | movement_type = MT_PHYSICS; |
| 2829 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2830 | |
| 2831 | // Make sure squad broken flag isn't set |
| 2832 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 2833 | |
| 2834 | // Only set goals if not currently in squad formation |
| 2835 | if (!(memory->squad_flags & ALIEN_SQUADIE)) { |
| 2836 | SetWanderGoal(me); |
| 2837 | } |
| 2838 | |
| 2839 | // Set previous mode so alien can return to this if it needs to |
| 2840 | memory->previous_mode = ALIEN_HUNTING; |
| 2841 | |
| 2842 | // Set returning home speed |
| 2843 | SetMaxSpeed(me, memory->base_speed * ALIEN_HUNT_SPEED_MOD); |
| 2844 | |
| 2845 | // Set the next activity check to happen within .4 to .8 seconds |
| 2846 | memory->next_activity_time = 0.0f; |
| 2847 | |
| 2848 | // Set the max time to wander between 20 and 40 seconds |
| 2849 | memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 20.0f + 40.0f; |
| 2850 | } break; |
| 2851 | |
| 2852 | case ALIEN_SCAVENGING: { |
| 2853 | // mprintf(0,"Scavenge mode set.\n"); |
| 2854 | |
| 2855 | // If currently landed, set take off velocity |
| 2856 | DoTakeoff(me, 8.0f, 3.0f); |
| 2857 | |
| 2858 | // Turn on friend avoidance |
| 2859 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2860 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2861 | |
| 2862 | // Only avoid friends alot if not in a squad |
| 2863 | if (memory->squad_flags == 0) { |
| 2864 | float avoid_dist = ALIEN_NORMAL_AVOID_DIST; |
| 2865 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2866 | SetCircleDist(me, memory->base_circle_distance); |
| 2867 | } else { |
| 2868 | float avoid_dist = ALIEN_SQUAD_AVOID_DIST; |
| 2869 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2870 | SetCircleDist(me, memory->base_circle_distance * ALIEN_SQUAD_CIRC_DIST_MOD); |
| 2871 | } |
| 2872 | |
| 2873 | // Make it aware |
| 2874 | flags = AIF_FORCE_AWARENESS; |
| 2875 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2876 | |
| 2877 | // Clear wall point collision and axes lock |
| 2878 | flags = PF_POINT_COLLIDE_WALLS; |
| 2879 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2880 | |
| 2881 | // Set movement type back to physics for flying around |
| 2882 | movement_type = MT_PHYSICS; |
| 2883 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2884 | |
| 2885 | // Make sure squad broken flag isn't set |
| 2886 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 2887 | |
| 2888 | // Only set goals if not currently in squad formation |
| 2889 | if (!(memory->squad_flags & ALIEN_SQUADIE)) { |
| 2890 | SetWanderGoal(me); |
| 2891 | } |
| 2892 | |
| 2893 | // Set previous mode so alien can return to this if it needs to |
| 2894 | memory->previous_mode = ALIEN_SCAVENGING; |
| 2895 | |
| 2896 | // Set returning home speed |
| 2897 | SetMaxSpeed(me, memory->base_speed * ALIEN_SCAV_SPEED_MOD); |
| 2898 | |
| 2899 | // Set the next activity check to happen within .4 to .8 seconds |
| 2900 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f; |
| 2901 | |
| 2902 | // Set the max time to wander between 20 and 40 seconds |
| 2903 | memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 10.0f + 10.0f; |
| 2904 | } break; |
| 2905 | |
| 2906 | case ALIEN_ATTACKING_MELEE: { |
| 2907 | // mprintf(0,"Melee mode set.\n"); |
| 2908 | |
| 2909 | // If currently landed, set take off velocity |
| 2910 | DoTakeoff(me, 8.0f, 3.0f); |
| 2911 | |
| 2912 | // Turn on friend avoidance |
| 2913 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2914 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2915 | |
| 2916 | // Only avoid friends alot if not in a squad or if in a broken squad |
| 2917 | if ((memory->squad_flags == 0) || (memory->squad_flags & ALIEN_BROKEN)) { |
| 2918 | float avoid_dist = ALIEN_NORMAL_AVOID_DIST; |
| 2919 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2920 | SetCircleDist(me, memory->base_circle_distance); |
| 2921 | } else { |
| 2922 | float avoid_dist = ALIEN_SQUAD_AVOID_DIST; |
| 2923 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2924 | SetCircleDist(me, memory->base_circle_distance * ALIEN_SQUAD_CIRC_DIST_MOD); |
| 2925 | } |
| 2926 | |
| 2927 | // Make it aware |
| 2928 | flags = AIF_FORCE_AWARENESS; |
| 2929 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2930 | |
| 2931 | // Clear wall point collision and axes lock |
| 2932 | flags = PF_POINT_COLLIDE_WALLS; |
| 2933 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2934 | |
| 2935 | // Set movement type back to physics for flying around |
| 2936 | movement_type = MT_PHYSICS; |
| 2937 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2938 | |
| 2939 | // Only set goals if not currently in squad formation |
| 2940 | if (!(memory->squad_flags & ALIEN_SQUADIE) || (memory->squad_flags & ALIEN_BROKEN)) { |
| 2941 | AI_SafeSetType(me, AIT_MELEE1); |
| 2942 | } |
| 2943 | |
| 2944 | // Set Engage and Attack Speeds |
| 2945 | if ((memory->squad_flags == 0) || (memory->squad_flags & ALIEN_BROKEN)) { |
| 2946 | SetMaxSpeed(me, memory->base_speed * ALIEN_ATTACK_SPEED_MOD); |
| 2947 | } else { |
| 2948 | SetMaxSpeed(me, memory->base_speed * ALIEN_ENGAGE_SPEED_MOD); |
| 2949 | } |
| 2950 | |
| 2951 | // Clear the next activity time |
| 2952 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 0.5f + 0.7f; |
| 2953 | |
| 2954 | // Clear the next wander time |
| 2955 | memory->max_wander_time = 0.0f; |
| 2956 | } break; |
| 2957 | |
| 2958 | case ALIEN_ATTACKING_RANGED: { |
| 2959 | // mprintf(0,"Ranged mode set.\n"); |
| 2960 | |
| 2961 | // If currently landed, set take off velocity |
| 2962 | DoTakeoff(me, 8.0f, 3.0f); |
| 2963 | |
| 2964 | // Turn on friend avoidance |
| 2965 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 2966 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2967 | |
| 2968 | // Set friend avoidance distance |
| 2969 | float avoid_dist = ALIEN_NORMAL_AVOID_DIST; |
| 2970 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 2971 | SetCircleDist(me, memory->base_circle_distance); |
| 2972 | |
| 2973 | // Make it aware |
| 2974 | flags = AIF_FORCE_AWARENESS; |
| 2975 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 2976 | |
| 2977 | // Clear wall point collision and axes lock |
| 2978 | flags = PF_POINT_COLLIDE_WALLS; |
| 2979 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 2980 | |
| 2981 | // Set movement type back to physics for flying around |
| 2982 | movement_type = MT_PHYSICS; |
| 2983 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 2984 | |
| 2985 | // Make sure squad broken flag isn't set |
| 2986 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 2987 | |
| 2988 | // Enable ranged firing |
| 2989 | flags = AIF_DISABLE_FIRING; |
| 2990 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 2991 | |
| 2992 | // Only set goals if not currently in squad formation |
| 2993 | AI_SafeSetType(me, AIT_EVADER1); |
| 2994 | |
| 2995 | // Set Engage and Attack Speeds |
| 2996 | SetMaxSpeed(me, memory->base_speed * ALIEN_ATTACK_SPEED_MOD); |
| 2997 | |
| 2998 | // Clear the next activity time |
| 2999 | memory->next_activity_time = 0.0f; |
| 3000 | |
| 3001 | // Clear the next wander time |
| 3002 | memory->max_wander_time = 0.0f; |
| 3003 | } break; |
| 3004 | |
| 3005 | case ALIEN_FLEEING: { |
| 3006 | // mprintf(0,"Fleeing mode set.\n"); |
| 3007 | |
| 3008 | // If currently landed, set take off velocity |
| 3009 | DoTakeoff(me, 8.0f, 3.0f); |
| 3010 | |
| 3011 | // avoid friends while fleeing |
| 3012 | flags = AIF_AUTO_AVOID_FRIENDS; |
| 3013 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 3014 | |
| 3015 | // Set friend avoidance distance |
| 3016 | float avoid_dist = ALIEN_NORMAL_AVOID_DIST; |
| 3017 | AI_Value(me, VF_SET, AIV_F_AVOID_FRIENDS_DIST, &avoid_dist); |
| 3018 | SetCircleDist(me, memory->base_circle_distance); |
| 3019 | |
| 3020 | // Make it aware |
| 3021 | flags = AIF_FORCE_AWARENESS; |
| 3022 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 3023 | |
| 3024 | // Clear wall point collision and axes lock |
| 3025 | flags = PF_POINT_COLLIDE_WALLS; |
| 3026 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 3027 | |
| 3028 | // Set movement type back to physics for flying around |
| 3029 | movement_type = MT_PHYSICS; |
| 3030 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 3031 | |
| 3032 | // Make sure squad broken flag isn't set |
| 3033 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 3034 | |
| 3035 | // Set Goal to go somewhere else |
| 3036 | SetWanderGoal(me); |
| 3037 | |
| 3038 | // Set Fleeing Speed |
| 3039 | SetMaxSpeed(me, memory->base_speed * ALIEN_FLEE_SPEED_MOD); |
| 3040 | |
| 3041 | // Clear the next activity time |
| 3042 | memory->next_activity_time = 0.0f; |
| 3043 | |
| 3044 | // Set the max time to flee (base time somewhat off of damage) |
| 3045 | float curr_shields, percent_damaged; |
| 3046 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &curr_shields); |
| 3047 | percent_damaged = (memory->base_shields - curr_shields) / memory->base_shields; |
| 3048 | |
| 3049 | memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f + (percent_damaged * 6.0f); |
| 3050 | } break; |
| 3051 | |
| 3052 | default: |
| 3053 | mprintf(0, "AlienOrganism is all messed up!\n"); |
| 3054 | } |
| 3055 | |
| 3056 | // If following leader in formation and mode supports squads, assign follow goals |
| 3057 | if ((memory->squad_flags & ALIEN_SQUADIE) && !(memory->squad_flags & ALIEN_BROKEN) && |
| 3058 | ModeSupportsSquadMovement(mode)) { |
| 3059 | SetSquadieFormationGoal(me); |
| 3060 | } |
| 3061 | |
| 3062 | // Reset the landing flags |
| 3063 | memory->done_moving = false; |
| 3064 | memory->done_turning = false; |
| 3065 | |
| 3066 | // Set the current mode and reset the mode time |
| 3067 | memory->mode = mode; |
| 3068 | memory->mode_time = 0.0f; |
| 3069 | } |
| 3070 | |
| 3071 | // Handles alien takeoffs |
| 3072 | void AlienOrganism::DoTakeoff(int me, float takeoff_speed, float speed_variance) { |
| 3073 | // If currently landed, set take off velocity |
| 3074 | if (IsLandedMode(memory->mode)) { |
| 3075 | vector vel; |
| 3076 | |
| 3077 | Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &vel); |
| 3078 | vel += (memory->home_uvec * (takeoff_speed + ((float)rand() / (float)D3_RAND_MAX) * speed_variance)); |
| 3079 | Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel); |
| 3080 | |
| 3081 | // Play the takeoff anim and tell it to go to alert next |
| 3082 | Obj_SetCustomAnim(me, 10, 31, 1, AIAF_NOTIFY, -1, AS_ALERT); |
| 3083 | |
| 3084 | // Reset the takeoff time |
| 3085 | memory->takeoff_time = 0.0f; |
| 3086 | } |
| 3087 | } |
| 3088 | |
| 3089 | // Processes the AI Initialize event |
| 3090 | void AlienOrganism::DoInit(int me) { |
| 3091 | int flags; |
| 3092 | msafe_struct m; |
| 3093 | m.objhandle = me; |
| 3094 | |
| 3095 | // Setup memory data |
| 3096 | tOSIRISMEMCHUNK ch; |
| 3097 | ch.id = ALIEN_MEMORY_ID; |
| 3098 | ch.size = sizeof(alienorganism_data); |
| 3099 | ch.my_id.type = OBJECT_SCRIPT; |
| 3100 | ch.my_id.objhandle = me; |
| 3101 | |
| 3102 | memory = (alienorganism_data *)Scrpt_MemAlloc(&ch); |
| 3103 | |
| 3104 | // Init base values |
| 3105 | AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed); |
| 3106 | AI_Value(me, VF_GET, AIV_F_CIRCLE_DIST, &memory->base_circle_distance); |
| 3107 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &memory->base_shields); |
| 3108 | |
| 3109 | // Init energy charge |
| 3110 | memory->energy_charges = 0.0f; |
| 3111 | memory->ok_to_deposit = true; |
| 3112 | |
| 3113 | // All beams off initially |
| 3114 | memory->enabled_beams = 0; |
| 3115 | |
| 3116 | // Clear the destination object handle |
| 3117 | memory->dest_object_handle = OBJECT_HANDLE_NONE; |
| 3118 | |
| 3119 | // Alien hasn't been hit by player yet |
| 3120 | memory->hit_by_player = false; |
| 3121 | |
| 3122 | // Alien hasn't taken off yet |
| 3123 | memory->takeoff_time = ALIEN_MAX_TAKEOFF_TIME; |
| 3124 | |
| 3125 | // Setup Squad Information |
| 3126 | memory->squad_flags = 0; |
| 3127 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 3128 | memory->num_teammates = 0; |
| 3129 | |
| 3130 | // .1 to 1.1 seconds into the level, do the first squad matching |
| 3131 | memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 2.0f + 0.1f; |
| 3132 | |
| 3133 | // Update the energy effect as soon as charge exists |
| 3134 | memory->next_update_energy_time = Game_GetTime(); |
| 3135 | memory->next_update_beam_time = Game_GetTime(); |
| 3136 | |
| 3137 | // Update the squadie catchup speed as soon as possible |
| 3138 | memory->next_squadie_update_time = Game_GetTime(); |
| 3139 | |
| 3140 | // Do special damage as soon as relevant |
| 3141 | memory->next_special_damage_time = Game_GetTime(); |
| 3142 | |
| 3143 | // Set the next generic check time |
| 3144 | memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 0.5f; |
| 3145 | memory->next_vis_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 2.0f + 1.0f; |
| 3146 | |
| 3147 | // Init other times |
| 3148 | memory->next_activity_time = Game_GetTime(); |
| 3149 | memory->max_wander_time = 0.0f; |
| 3150 | |
| 3151 | // Store Home Information |
| 3152 | Obj_Value(me, VF_GET, OBJV_V_POS, &memory->home_pos); |
| 3153 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &memory->home_room); |
| 3154 | |
| 3155 | matrix orient; |
| 3156 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 3157 | memory->home_fvec = orient.fvec; |
| 3158 | vm_VectorNormalize(&memory->home_fvec); |
| 3159 | memory->home_uvec = orient.uvec; |
| 3160 | vm_VectorNormalize(&memory->home_uvec); |
| 3161 | |
| 3162 | // Check and see whether we've been spawned from a matcen or not |
| 3163 | bool spawned_from_matcen = false; |
| 3164 | char type; |
| 3165 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 3166 | if (type == AS_BIRTH) { |
| 3167 | mprintf(0, "Alien organism produced by matcen.\n"); |
| 3168 | // Note that we came from a matcen |
| 3169 | spawned_from_matcen = true; |
| 3170 | |
| 3171 | // Find a new home |
| 3172 | FindHome(me); |
| 3173 | } |
| 3174 | |
| 3175 | // Init squadie goal positions |
| 3176 | memory->squad_goal_pos = memory->home_pos; |
| 3177 | memory->squad_goal_room = memory->home_room; |
| 3178 | |
| 3179 | // Create and setup the energy effect props |
| 3180 | msafe_struct mstruct; |
| 3181 | |
| 3182 | memory->pos1_handle = Obj_Create(OBJ_POWERUP, powerup_id, memory->home_room, &memory->home_pos, NULL, me); |
| 3183 | mstruct.objhandle = memory->pos1_handle; |
| 3184 | MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct); |
| 3185 | |
| 3186 | memory->pos2_handle = Obj_Create(OBJ_POWERUP, powerup_id, memory->home_room, &memory->home_pos, NULL, me); |
| 3187 | mstruct.objhandle = memory->pos2_handle; |
| 3188 | MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct); |
| 3189 | |
| 3190 | memory->pos3_handle = Obj_Create(OBJ_POWERUP, powerup_id, memory->home_room, &memory->home_pos, NULL, me); |
| 3191 | mstruct.objhandle = memory->pos3_handle; |
| 3192 | MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct); |
| 3193 | |
| 3194 | // Set starting mode |
| 3195 | if (spawned_from_matcen) { |
| 3196 | // Set our starting mode to landed-resting |
| 3197 | memory->previous_mode = ALIEN_GOING_HOME; |
| 3198 | memory->pending_mode = ALIEN_LANDED_RESTING; |
| 3199 | SetMode(me, ALIEN_ATTACKING_MELEE); |
| 3200 | } else { |
| 3201 | // Set our starting mode to landed-resting |
| 3202 | memory->pending_mode = ALIEN_LANDED_RESTING; |
| 3203 | SetMode(me, ALIEN_LANDED); |
| 3204 | } |
| 3205 | } |
| 3206 | |
| 3207 | // Tries to find a home for an alien (returns false if this fails) |
| 3208 | #define MAX_HOME_FINDING_ATTEMPTS 20 |
| 3209 | #define MAX_HOME_FINDING_DIST 1000 |
| 3210 | #define HOME_LOOK_OFFSET 0.18f // for a 40 degree search pyramid |
| 3211 | #define HOME_PLACE_DISTANCE 1.0f |
| 3212 | bool AlienOrganism::FindHome(int me) { |
| 3213 | int num_attempts; |
| 3214 | bool home_found; |
| 3215 | vector start_pos, target_pos, landed_pos, home_dir; |
| 3216 | int start_room, landed_room; |
| 3217 | matrix start_orient; |
| 3218 | int flags, fate; |
| 3219 | ray_info ray; |
| 3220 | float size; |
| 3221 | |
| 3222 | // Find start point |
| 3223 | Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos); |
| 3224 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room); |
| 3225 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &start_orient); |
| 3226 | Obj_Value(me, VF_GET, OBJV_F_SIZE, &size); |
| 3227 | |
| 3228 | home_found = false; |
| 3229 | num_attempts = 0; |
| 3230 | while (!home_found && num_attempts < MAX_HOME_FINDING_ATTEMPTS) { |
| 3231 | // Determine ray angle |
| 3232 | home_dir = start_orient.fvec; |
| 3233 | home_dir += start_orient.uvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)D3_RAND_MAX) * 2.0f * HOME_LOOK_OFFSET); |
| 3234 | home_dir += start_orient.rvec * (HOME_LOOK_OFFSET - ((float)rand() / (float)D3_RAND_MAX) * 2.0f * HOME_LOOK_OFFSET); |
| 3235 | |
| 3236 | // Cast home-finding ray |
| 3237 | target_pos = start_pos + (home_dir * MAX_HOME_FINDING_DIST); |
| 3238 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 3239 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 3240 | fate = FVI_RayCast(me, &start_pos, &target_pos, start_room, size, flags, &ray); |
| 3241 | |
| 3242 | // Check if it hit a face |
| 3243 | if (fate == HIT_WALL) { |
| 3244 | matrix temp; |
| 3245 | |
| 3246 | memory->home_pos = ray.hit_face_pnt; |
| 3247 | memory->home_room = ray.hit_face_room; |
| 3248 | memory->home_uvec = ray.hit_wallnorm; |
| 3249 | |
| 3250 | vm_VectorToMatrix(&temp, &memory->home_uvec, NULL, NULL); |
| 3251 | if (rand() % 100 > 50) { |
| 3252 | memory->home_fvec = temp.uvec; |
| 3253 | } else { |
| 3254 | memory->home_fvec = temp.rvec; |
| 3255 | } |
| 3256 | if (rand() % 100 > 50) |
| 3257 | memory->home_fvec = -memory->home_fvec; |
| 3258 | |
| 3259 | // Place the object a little away from the wall |
| 3260 | target_pos = memory->home_pos + (memory->home_uvec * HOME_PLACE_DISTANCE); |
| 3261 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 3262 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 3263 | FVI_RayCast(me, &memory->home_pos, &target_pos, memory->home_room, 0.0f, flags, &ray); |
| 3264 | |
| 3265 | memory->home_pos = ray.hit_point; |
| 3266 | memory->home_room = ray.hit_room; |
| 3267 | |
| 3268 | home_found = true; |
| 3269 | } |
| 3270 | |
| 3271 | num_attempts++; |
| 3272 | } |
| 3273 | |
| 3274 | return home_found; |
| 3275 | } |
| 3276 | |
| 3277 | void AlienOrganism::DoSquadieFrame(int me) { |
| 3278 | vector my_pos; |
| 3279 | int type; |
| 3280 | |
| 3281 | // Check if the leader is still alive |
| 3282 | Obj_Value(memory->leader_handle, VF_GET, OBJV_I_TYPE, &type); |
| 3283 | if (type == OBJ_NONE) { |
| 3284 | memory->squad_flags = 0; |
| 3285 | memory->leader_handle = OBJECT_HANDLE_NONE; |
| 3286 | memory->num_teammates = 0; |
| 3287 | |
| 3288 | SetMode(me, memory->mode); |
| 3289 | return; |
| 3290 | } |
| 3291 | |
| 3292 | // If current mode disallows formation following, get outta here |
| 3293 | if (!ModeSupportsSquadMovement(memory->mode)) |
| 3294 | return; |
| 3295 | |
| 3296 | // If squad is currently broken, get outta here |
| 3297 | if (memory->squad_flags & ALIEN_BROKEN) |
| 3298 | return; |
| 3299 | |
| 3300 | // The leader is alive, so set new goal pos |
| 3301 | UpdateSquadieFormationGoal(me); |
| 3302 | |
| 3303 | // Check if it's time to update the catchup speed |
| 3304 | if (Game_GetTime() >= memory->next_squadie_update_time) { |
| 3305 | memory->next_squadie_update_time = Game_GetTime() + ALIEN_SQUADIE_INTERVAL; |
| 3306 | |
| 3307 | // Get the distance to leader |
| 3308 | Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos); |
| 3309 | float dist = vm_VectorDistance(&my_pos, &memory->squad_goal_pos); |
| 3310 | |
| 3311 | // If squadie is in leader's path, slow down until leader passes |
| 3312 | float slowdown = 1.0f; |
| 3313 | if (dist <= ALIEN_APPROACH_DIST) { |
| 3314 | matrix leader_orient; |
| 3315 | vector dir, leader_pos; |
| 3316 | |
| 3317 | // See if we are in front of leader |
| 3318 | Obj_Value(memory->leader_handle, VF_GET, OBJV_M_ORIENT, &leader_orient); |
| 3319 | dir = my_pos - memory->squad_goal_pos; |
| 3320 | vm_VectorNormalize(&dir); |
| 3321 | float dot_prod; |
| 3322 | if ((dot_prod = leader_orient.fvec * dir) < 0.0f) { |
| 3323 | slowdown = dist / ALIEN_APPROACH_DIST; |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | // If squadie is falling behind, let him speed up so he can catch up to the squad |
| 3328 | if (dist <= ALIEN_CATCHUP_DIST) { |
| 3329 | float catchup_speed; |
| 3330 | AI_Value(memory->leader_handle, VF_GET, AIV_F_MAX_SPEED, &catchup_speed); |
| 3331 | |
| 3332 | float scaled_speed = dist / ALIEN_CATCHUP_DIST * ALIEN_CATCHUP_SPEED_MOD * catchup_speed; |
| 3333 | catchup_speed += scaled_speed; |
| 3334 | catchup_speed *= slowdown; |
| 3335 | |
| 3336 | AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &catchup_speed); |
| 3337 | } else if (dist > ALIEN_CATCHUP_DIST) { |
| 3338 | float catchup_speed; |
| 3339 | AI_Value(memory->leader_handle, VF_GET, AIV_F_MAX_SPEED, &catchup_speed); |
| 3340 | |
| 3341 | float scaled_speed = ALIEN_CATCHUP_SPEED_MOD * catchup_speed; |
| 3342 | catchup_speed += scaled_speed; |
| 3343 | catchup_speed *= slowdown; |
| 3344 | |
| 3345 | AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &catchup_speed); |
| 3346 | } |
| 3347 | } |
| 3348 | } |
| 3349 | |
| 3350 | // Processes the AI Frame Interval Event |
| 3351 | void AlienOrganism::DoFrame(int me) { |
| 3352 | vector uvec; |
| 3353 | int flags; |
| 3354 | float anim_frame; |
| 3355 | int new_mode; |
| 3356 | vector vel; |
| 3357 | float last_see_time, last_see_game_time; |
| 3358 | float last_hear_time, last_hear_game_time; |
| 3359 | float last_perceive_time; |
| 3360 | |
| 3361 | /* |
| 3362 | float shields; |
| 3363 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &shields); |
| 3364 | mprintf(0,"Shields: %.2f\n",shields); |
| 3365 | */ |
| 3366 | |
| 3367 | // Get the last see and hear time |
| 3368 | AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 3369 | AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_game_time); |
| 3370 | |
| 3371 | // Calculate the time since target was seen and heard |
| 3372 | last_hear_time = Game_GetTime() - last_hear_game_time; |
| 3373 | last_see_time = Game_GetTime() - last_see_game_time; |
| 3374 | |
| 3375 | // Perceive time is last time target was seen or heard (whichever is smalled) |
| 3376 | if (last_hear_time <= last_see_time) { |
| 3377 | last_perceive_time = last_hear_time; |
| 3378 | } else { |
| 3379 | last_perceive_time = last_see_time; |
| 3380 | } |
| 3381 | |
| 3382 | // Check if takeoff time is active |
| 3383 | if (memory->takeoff_time < ALIEN_MAX_TAKEOFF_TIME) { |
| 3384 | memory->takeoff_time += Game_GetFrameTime(); |
| 3385 | |
| 3386 | // If the time is up, clear the landing lock flags |
| 3387 | if (memory->takeoff_time >= ALIEN_MAX_TAKEOFF_TIME) { |
| 3388 | // Make sure we're in a mode that wants these flags cleared |
| 3389 | if (memory->mode != ALIEN_LANDING_AT_HOME && !IsLandedMode(memory->mode)) { |
| 3390 | // Clear wall point collision and axes lock |
| 3391 | flags = PF_LOCK_MASK | PF_POINT_COLLIDE_WALLS; |
| 3392 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 3393 | |
| 3394 | // Turn on dodging |
| 3395 | flags = AIF_DODGE; |
| 3396 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 3397 | |
| 3398 | // enable auto-leveling |
| 3399 | flags = PF_LEVELING; |
| 3400 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 3401 | |
| 3402 | // mprintf(0,"Alien landing flags cleared...\n"); |
| 3403 | } |
| 3404 | } |
| 3405 | } |
| 3406 | |
| 3407 | // If alien was hit by player, take action if necessary |
| 3408 | if (memory->hit_by_player) { |
| 3409 | // See if the mode we're in is sensitive to attacks |
| 3410 | if (ModeIsAttackSensitive(memory->mode, memory->pending_mode)) { |
| 3411 | // mprintf(0,"Sensitive to Attack!\n"); |
| 3412 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 3413 | SendCommand(me, memory->leader_handle, ALIEN_COM_I_WAS_HIT, NULL); |
| 3414 | } else { |
| 3415 | MeleeAttack(me); |
| 3416 | } |
| 3417 | } |
| 3418 | |
| 3419 | // reset the hit by player flag |
| 3420 | memory->hit_by_player = false; |
| 3421 | } |
| 3422 | |
| 3423 | // Periodically update the squad information (remove dead teammates and/or recruit new ones) |
| 3424 | if (memory->next_update_squad_time <= Game_GetTime()) { |
| 3425 | memory->next_update_squad_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f; |
| 3426 | UpdateSquad(me); |
| 3427 | } |
| 3428 | |
| 3429 | // Periodically update the squad visibility information |
| 3430 | if (memory->next_vis_check_time <= Game_GetTime()) { |
| 3431 | memory->next_vis_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 1.0f; |
| 3432 | |
| 3433 | // If we're leading, update the squad's visibility flags |
| 3434 | if (memory->squad_flags & ALIEN_LEADER) { |
| 3435 | UpdateSquadVisibility(me); |
| 3436 | } |
| 3437 | } |
| 3438 | |
| 3439 | // Update squadies |
| 3440 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 3441 | DoSquadieFrame(me); |
| 3442 | } |
| 3443 | |
| 3444 | // Get the current animation frame |
| 3445 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame); |
| 3446 | |
| 3447 | // Handle generic checks (pertains to more than 1 mode) |
| 3448 | if (memory->next_generic_check_time <= Game_GetTime()) { |
| 3449 | memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.4f + 0.6f; |
| 3450 | |
| 3451 | // If we're not already landed, or heading home to heal, see if we should |
| 3452 | if (!IsLandedMode(memory->mode) && memory->mode != ALIEN_LANDING_AT_HOME && |
| 3453 | memory->pending_mode != ALIEN_LANDED_HEALING) { |
| 3454 | float current_shields; |
| 3455 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, ¤t_shields); |
| 3456 | |
| 3457 | // If we're pretty heavily damaged, see if we should return home to heal |
| 3458 | if ((current_shields < memory->base_shields * ALIEN_HEAL_PERCENTAGE) && (rand() % 100 < 80)) { |
| 3459 | Heal(me); |
| 3460 | } |
| 3461 | } |
| 3462 | |
| 3463 | // If we're not already fleeing or going home to heal, check to see if we should flee |
| 3464 | if (memory->mode != ALIEN_FLEEING && memory->mode != ALIEN_LANDING_AT_HOME && |
| 3465 | memory->mode != ALIEN_LANDED_HEALING && memory->pending_mode != ALIEN_LANDED_HEALING) { |
| 3466 | if (IsOnFire(me)) { |
| 3467 | // If we're on fire, there's a good chance that we will try to flee |
| 3468 | if ((rand() % 100) < ALIEN_ON_FIRE_FLEE_CHANCE) |
| 3469 | Flee(me); |
| 3470 | } else if (IsNearFire(me)) { |
| 3471 | // If we're near fire, there's a chance that we will try to flee |
| 3472 | if ((rand() % 100) < ALIEN_NEAR_FIRE_FLEE_CHANCE) |
| 3473 | Flee(me); |
| 3474 | } |
| 3475 | } |
| 3476 | |
| 3477 | // If we're landed, see if we want to play the landed animation |
| 3478 | if (IsLandedMode(memory->mode) && anim_frame == 10 && (rand() % 100) < 15) { |
| 3479 | Obj_SetCustomAnim(me, 1, 10, 1, 0, -1, -1); |
| 3480 | } |
| 3481 | } |
| 3482 | |
| 3483 | // Handle mode specific operations |
| 3484 | switch (memory->mode) { |
| 3485 | case ALIEN_LANDED_RESTING: { |
| 3486 | // See if it should consider doing something spontaneously |
| 3487 | if (Game_GetTime() >= memory->next_activity_time) { |
| 3488 | // Set the next time to think about doing something (4-6 seconds) |
| 3489 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 0.5f; |
| 3490 | |
| 3491 | // If alien has a target, decide whether it should go hunt it down |
| 3492 | if (last_perceive_time < 3.0f) { |
| 3493 | int target_handle; |
| 3494 | int die_roll = 0; |
| 3495 | |
| 3496 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 3497 | if (target_handle != OBJECT_HANDLE_NONE) { |
| 3498 | die_roll = (rand() % 90) + 1; |
| 3499 | |
| 3500 | float dist; |
| 3501 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 3502 | |
| 3503 | // Adjust the random value by distance to target |
| 3504 | // (ie the closer the target, the more likely it will be attacked) |
| 3505 | if (dist > 300.0f) |
| 3506 | die_roll -= 50; |
| 3507 | else if (dist > 200.0f) |
| 3508 | die_roll -= 45; |
| 3509 | else if (dist > 100.0f) |
| 3510 | die_roll -= 40; |
| 3511 | else if (dist > 70.0f) |
| 3512 | die_roll -= 30; |
| 3513 | else if (dist > 50.0f) |
| 3514 | die_roll -= 20; |
| 3515 | else if (dist > 25.0f) |
| 3516 | die_roll += 5; |
| 3517 | else |
| 3518 | die_roll += 50; |
| 3519 | |
| 3520 | // Grant bonuses for recent seeing and hearing |
| 3521 | if (last_see_time < 3.0) |
| 3522 | die_roll += 5; |
| 3523 | |
| 3524 | if (last_hear_time < 4.0f) |
| 3525 | die_roll += 50; |
| 3526 | |
| 3527 | // mprintf(0,"hear: %.1f, see: %.1f, perceive: %.1f\n",last_hear_time,last_see_time,last_perceive_time); |
| 3528 | // mprintf(0,"Doing check...%d - %.1f\n",die_roll,dist); |
| 3529 | } |
| 3530 | |
| 3531 | if (die_roll > 70) { |
| 3532 | // If we're a squadie, lie and tell the leader we got hit (so he orders the attack) |
| 3533 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 3534 | SendCommand(me, memory->leader_handle, ALIEN_COM_I_WAS_HIT, NULL); |
| 3535 | } else { |
| 3536 | if (MeleeAttack(me)) |
| 3537 | break; |
| 3538 | } |
| 3539 | } |
| 3540 | } |
| 3541 | |
| 3542 | // If we currently have any charges, go ahead and deposit them |
| 3543 | if (memory->energy_charges > 0.0f) { |
| 3544 | // If we're a squadie, tell the leader we are leaving |
| 3545 | if (memory->squad_flags & ALIEN_SQUADIE) { |
| 3546 | LeaveLeader(me); |
| 3547 | } |
| 3548 | |
| 3549 | // If we're a leader, disperse the squad |
| 3550 | if (memory->squad_flags & ALIEN_LEADER) { |
| 3551 | DisperseSquad(me); |
| 3552 | } |
| 3553 | |
| 3554 | SetMode(me, ALIEN_LANDED_DEPOSITING); |
| 3555 | break; |
| 3556 | } |
| 3557 | |
| 3558 | /* |
| 3559 | // Only think if it's not a squadie (its leader will decide when/whether to do something) |
| 3560 | if(!(memory->squad_flags & ALIEN_SQUADIE)) |
| 3561 | { |
| 3562 | int die_roll = (rand()%100) + 1; |
| 3563 | |
| 3564 | // See what to do |
| 3565 | if(die_roll <= 20) // Go hunting |
| 3566 | { |
| 3567 | // Start hunting |
| 3568 | SetMode(me, ALIEN_HUNTING); |
| 3569 | |
| 3570 | // If it's a leader, order squad to switch to hunting mode |
| 3571 | if(memory->squad_flags & ALIEN_LEADER) { |
| 3572 | int mode=ALIEN_HUNTING; |
| 3573 | IssueSquadOrder(me, ALIEN_COM_SET_MODE, &mode); |
| 3574 | } |
| 3575 | } |
| 3576 | else if(die_roll <= 30) // Go scavenging |
| 3577 | { |
| 3578 | // Start scavenging |
| 3579 | SetMode(me, ALIEN_SCAVENGING); |
| 3580 | |
| 3581 | // If it's a leader, order squad to switch to scavenging mode |
| 3582 | if(memory->squad_flags & ALIEN_LEADER) { |
| 3583 | int mode=ALIEN_SCAVENGING; |
| 3584 | IssueSquadOrder(me, ALIEN_COM_SET_MODE, &mode); |
| 3585 | } |
| 3586 | } |
| 3587 | } |
| 3588 | */ |
| 3589 | } |
| 3590 | } break; |
| 3591 | |
| 3592 | case ALIEN_LANDED_HEALING: { |
| 3593 | // See if we should do a round of healing |
| 3594 | if (Game_GetTime() >= memory->next_activity_time) { |
| 3595 | // Set the next time to do something |
| 3596 | memory->next_activity_time = Game_GetTime() + ALIEN_LANDED_ACTION_TIME; |
| 3597 | |
| 3598 | // Restore some shields |
| 3599 | float current_shields; |
| 3600 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, ¤t_shields); |
| 3601 | current_shields += (memory->base_shields * 0.2f); |
| 3602 | |
| 3603 | bool done_healing = false; |
| 3604 | if (current_shields >= memory->base_shields) { |
| 3605 | current_shields = memory->base_shields; |
| 3606 | done_healing = true; |
| 3607 | } |
| 3608 | |
| 3609 | // Set the current shields |
| 3610 | Obj_Value(me, VF_SET, OBJV_F_SHIELDS, ¤t_shields); |
| 3611 | // mprintf(0,"Healing...\n"); |
| 3612 | |
| 3613 | // If we're all healed up, go to landed resting |
| 3614 | if (done_healing) { |
| 3615 | SetMode(me, ALIEN_LANDED_RESTING); |
| 3616 | // mprintf(0,"Done healing.\n"); |
| 3617 | } |
| 3618 | } |
| 3619 | |
| 3620 | // Handle the energy beam effects |
| 3621 | if (!memory->energy_beams_on) |
| 3622 | CalcEnergyBeamPositions(me); |
| 3623 | UpdateEnergyBeams(me); |
| 3624 | } break; |
| 3625 | |
| 3626 | case ALIEN_LANDED_DEPOSITING: { |
| 3627 | // See if we should do a round of energy depositing |
| 3628 | if (Game_GetTime() >= memory->next_activity_time) { |
| 3629 | // Set the next time to do something |
| 3630 | memory->next_activity_time = Game_GetTime() + ALIEN_LANDED_ACTION_TIME; |
| 3631 | |
| 3632 | // Deposit some charges |
| 3633 | memory->energy_charges -= (ALIEN_MAX_ENERGY_CHARGES * 0.25f); |
| 3634 | |
| 3635 | bool done_depositing = false; |
| 3636 | if (memory->energy_charges <= 0.0f) { |
| 3637 | memory->energy_charges = 0.0f; |
| 3638 | done_depositing = true; |
| 3639 | } |
| 3640 | |
| 3641 | // mprintf(0,"Depositing...\n"); |
| 3642 | |
| 3643 | // If we're all healed up, go to landed resting |
| 3644 | if (done_depositing) { |
| 3645 | SetMode(me, ALIEN_LANDED_RESTING); |
| 3646 | // mprintf(0,"Done depositing.\n"); |
| 3647 | } |
| 3648 | } |
| 3649 | |
| 3650 | // Handle the energy beam effects |
| 3651 | if (!memory->energy_beams_on) |
| 3652 | CalcEnergyBeamPositions(me); |
| 3653 | UpdateEnergyBeams(me); |
| 3654 | } break; |
| 3655 | |
| 3656 | case ALIEN_LANDED_WITHDRAWING: { |
| 3657 | // See if we should do a round of energy withdrawing |
| 3658 | if (Game_GetTime() >= memory->next_activity_time) { |
| 3659 | // Set the next time to do something |
| 3660 | memory->next_activity_time = Game_GetTime() + ALIEN_LANDED_ACTION_TIME; |
| 3661 | |
| 3662 | // Deposit some charges |
| 3663 | memory->energy_charges += (ALIEN_MAX_ENERGY_CHARGES * 0.25f); |
| 3664 | |
| 3665 | bool done_withdrawing = false; |
| 3666 | if (memory->energy_charges >= ALIEN_MAX_ENERGY_CHARGES) { |
| 3667 | memory->energy_charges = ALIEN_MAX_ENERGY_CHARGES; |
| 3668 | done_withdrawing = true; |
| 3669 | } |
| 3670 | |
| 3671 | // mprintf(0,"Withdrawing...\n"); |
| 3672 | |
| 3673 | // If we're all healed up, go to melee mode |
| 3674 | if (done_withdrawing) { |
| 3675 | memory->ok_to_deposit = false; |
| 3676 | memory->previous_mode = ALIEN_GOING_HOME; |
| 3677 | memory->pending_mode = ALIEN_LANDED_RESTING; |
| 3678 | SetMode(me, ALIEN_ATTACKING_MELEE); |
| 3679 | // mprintf(0,"Done withdrawing.\n"); |
| 3680 | } |
| 3681 | } |
| 3682 | |
| 3683 | // Handle the energy beam effects |
| 3684 | if (!memory->energy_beams_on) |
| 3685 | CalcEnergyBeamPositions(me); |
| 3686 | UpdateEnergyBeams(me); |
| 3687 | } break; |
| 3688 | |
| 3689 | case ALIEN_LANDING_AT_HOME: { |
| 3690 | // mprintf(0, "AlienOrganism Landed at Home\n"); |
| 3691 | if (memory->done_turning == true && memory->done_moving == true) { |
| 3692 | SetMode(me, ALIEN_LANDED); |
| 3693 | } |
| 3694 | } break; |
| 3695 | |
| 3696 | case ALIEN_GOING_HOME: { |
| 3697 | char type, next_type; |
| 3698 | |
| 3699 | // If we're simply going home to rest, and a target is present, attack it! |
| 3700 | if (memory->pending_mode == ALIEN_LANDED_RESTING && last_perceive_time < 3.0f) { |
| 3701 | if (MeleeAttack(me)) |
| 3702 | break; |
| 3703 | } |
| 3704 | |
| 3705 | // mprintf(0, "AlienOrganism going home\n"); |
| 3706 | |
| 3707 | // If we're in alert, or the next anim mode is alert, and we're done moving, land at home |
| 3708 | if (memory->done_moving == true) { |
| 3709 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 3710 | AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_type); |
| 3711 | |
| 3712 | if (type == AS_ALERT || type == AS_IDLE || next_type == AS_ALERT || next_type == AS_IDLE) { |
| 3713 | SetMode(me, ALIEN_LANDING_AT_HOME); |
| 3714 | } |
| 3715 | } |
| 3716 | } break; |
| 3717 | |
| 3718 | case ALIEN_FLEEING: { |
| 3719 | // See if it is time to stop running |
| 3720 | if (memory->mode_time >= memory->max_wander_time) { |
| 3721 | // Go back to melee mode for now |
| 3722 | SetMode(me, ALIEN_ATTACKING_MELEE); |
| 3723 | } |
| 3724 | } break; |
| 3725 | |
| 3726 | case ALIEN_FINDING_BIRTHPLACE: |
| 3727 | break; |
| 3728 | |
| 3729 | case ALIEN_GIVING_BIRTH: |
| 3730 | break; |
| 3731 | |
| 3732 | case ALIEN_HUNTING: { |
| 3733 | // If a target has been spotted, attack it |
| 3734 | if (!(memory->squad_flags & ALIEN_SQUADIE) && last_perceive_time < 3.0f) { |
| 3735 | if (MeleeAttack(me)) |
| 3736 | break; |
| 3737 | } |
| 3738 | |
| 3739 | // See if it is time to go home |
| 3740 | if (memory->mode_time >= memory->max_wander_time) { |
| 3741 | // Set the next max wander time |
| 3742 | memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 10.0f + 10.0f; |
| 3743 | |
| 3744 | // If not a squadie, decide to go home |
| 3745 | if (!(memory->squad_flags & ALIEN_SQUADIE)) { |
| 3746 | // If leading squad, tell squad to go home and rest |
| 3747 | if (memory->squad_flags & ALIEN_LEADER) { |
| 3748 | int pending_mode = ALIEN_LANDED_RESTING; |
| 3749 | IssueSquadOrder(me, ALIEN_COM_SET_PENDING_MODE, &pending_mode); |
| 3750 | |
| 3751 | int mode = ALIEN_GOING_HOME; |
| 3752 | DisperseSquadToMode(me, mode); |
| 3753 | } |
| 3754 | |
| 3755 | // Go home and rest |
| 3756 | memory->pending_mode = ALIEN_LANDED_RESTING; |
| 3757 | SetMode(me, ALIEN_GOING_HOME); |
| 3758 | break; |
| 3759 | } |
| 3760 | } |
| 3761 | } break; |
| 3762 | |
| 3763 | case ALIEN_SCAVENGING: { |
| 3764 | // See if it is time to go home |
| 3765 | if (memory->mode_time >= memory->max_wander_time) { |
| 3766 | // Set the next max wander time |
| 3767 | memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 10.0f + 10.0f; |
| 3768 | |
| 3769 | // If not a squadie, decide to go home |
| 3770 | if (!(memory->squad_flags & ALIEN_SQUADIE)) { |
| 3771 | // If leading squad, tell squad to go home and rest |
| 3772 | if (memory->squad_flags & ALIEN_LEADER) { |
| 3773 | int pending_mode = ALIEN_LANDED_RESTING; |
| 3774 | IssueSquadOrder(me, ALIEN_COM_SET_PENDING_MODE, &pending_mode); |
| 3775 | |
| 3776 | int mode = ALIEN_GOING_HOME; |
| 3777 | DisperseSquadToMode(me, mode); |
| 3778 | } |
| 3779 | |
| 3780 | // Go home and rest |
| 3781 | memory->pending_mode = ALIEN_LANDED_RESTING; |
| 3782 | SetMode(me, ALIEN_GOING_HOME); |
| 3783 | break; |
| 3784 | } |
| 3785 | } |
| 3786 | } break; |
| 3787 | |
| 3788 | case ALIEN_ATTACKING_MELEE: { |
| 3789 | // If a target hasn't been spotted for a while, return to previous task |
| 3790 | if (!(memory->squad_flags & ALIEN_SQUADIE) && last_perceive_time > 7.0f) { |
| 3791 | int mode = memory->previous_mode; |
| 3792 | |
| 3793 | // If leading squad, tell squad to return to previous task's mode |
| 3794 | if (memory->squad_flags & ALIEN_LEADER) { |
| 3795 | // If leader is going home, disperse the squad |
| 3796 | if (mode == ALIEN_GOING_HOME) { |
| 3797 | int pending_mode = ALIEN_LANDED_RESTING; |
| 3798 | IssueSquadOrder(me, ALIEN_COM_SET_PENDING_MODE, &pending_mode); |
| 3799 | DisperseSquadToMode(me, mode); |
| 3800 | } else { |
| 3801 | // Otherwise just tell them to switch to the new mode (hunt or scavenge) |
| 3802 | IssueSquadOrder(me, ALIEN_COM_SET_MODE, &mode); |
| 3803 | } |
| 3804 | } |
| 3805 | |
| 3806 | // Return to previous mode |
| 3807 | SetMode(me, mode); |
| 3808 | break; |
| 3809 | } |
| 3810 | |
| 3811 | // If leading, check target distance for grouping orders |
| 3812 | if (memory->squad_flags & ALIEN_LEADER) { |
| 3813 | int target_handle; |
| 3814 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 3815 | if (target_handle != OBJECT_HANDLE_NONE) { |
| 3816 | float dist; |
| 3817 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 3818 | |
| 3819 | // See if we need to regroup or break up and attack |
| 3820 | if ((dist >= ALIEN_REGROUP_DIST) && (memory->squad_flags & ALIEN_BROKEN)) { |
| 3821 | // Tell Squad to regroup |
| 3822 | IssueSquadOrder(me, ALIEN_COM_REGROUP, NULL); |
| 3823 | |
| 3824 | // Set up leader for regrouping |
| 3825 | memory->squad_flags &= ~ALIEN_BROKEN; |
| 3826 | SetMode(me, memory->mode); |
| 3827 | break; |
| 3828 | } else if ((dist <= ALIEN_BREAKUP_DIST) && !(memory->squad_flags & ALIEN_BROKEN)) { |
| 3829 | // Tell Squad to breakup and attack! |
| 3830 | IssueSquadOrder(me, ALIEN_COM_BREAK_AND_ATTACK, NULL); |
| 3831 | |
| 3832 | // Set up leader for regrouping |
| 3833 | memory->squad_flags |= ALIEN_BROKEN; |
| 3834 | SetMode(me, memory->mode); |
| 3835 | break; |
| 3836 | } |
| 3837 | } |
| 3838 | } |
| 3839 | |
| 3840 | /* |
| 3841 | // If we're a non-broken squadie, and target is closer than leader, break on our own |
| 3842 | if(memory->squad_flags & ALIEN_SQUADIE && !(memory->squad_flags & ALIEN_BROKEN)) |
| 3843 | { |
| 3844 | int target_handle; |
| 3845 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 3846 | if(target_handle != OBJECT_HANDLE_NONE) |
| 3847 | { |
| 3848 | } |
| 3849 | } |
| 3850 | */ |
| 3851 | |
| 3852 | // See if we should decide whether to do any charge related activities |
| 3853 | if (Game_GetTime() >= memory->next_activity_time) { |
| 3854 | // Set the next time to do something |
| 3855 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 0.6f + 0.8f; |
| 3856 | |
| 3857 | // If we have some charges, see if we should do something with it |
| 3858 | if (memory->energy_charges > 0.0f) { |
| 3859 | int die_roll = rand() % 100; |
| 3860 | if (die_roll < 70) { |
| 3861 | // Switch to ranged mode |
| 3862 | RangedAttack(me); |
| 3863 | break; |
| 3864 | } else if (die_roll < 90 && memory->ok_to_deposit) { |
| 3865 | // Return home and deposit it |
| 3866 | Deposit(me); |
| 3867 | break; |
| 3868 | } |
| 3869 | } else { |
| 3870 | // See if we want to return home and withdrawal some |
| 3871 | int die_roll = rand() % 1000; |
| 3872 | // mprintf(0,"Doing withdrawal check... %d\n",die_roll); |
| 3873 | if (die_roll < 5) // 0.5% chance |
| 3874 | { |
| 3875 | // Possibly factor in a distance to home check here? |
| 3876 | |
| 3877 | Withdraw(me); |
| 3878 | break; |
| 3879 | } |
| 3880 | } |
| 3881 | } |
| 3882 | } break; |
| 3883 | |
| 3884 | case ALIEN_ATTACKING_RANGED: { |
| 3885 | // If we've lost target, or if we're out of charges, go back to melee mode |
| 3886 | if (last_perceive_time > 6.0f || memory->energy_charges <= 0.0f) { |
| 3887 | // Return to melee mode |
| 3888 | SetMode(me, ALIEN_ATTACKING_MELEE); |
| 3889 | break; |
| 3890 | } |
| 3891 | } break; |
| 3892 | } |
| 3893 | |
| 3894 | // Update the energy effect |
| 3895 | UpdateEnergyEffect(me); |
| 3896 | |
| 3897 | // Increment the current mode time |
| 3898 | memory->mode_time += Game_GetFrameTime(); |
| 3899 | |
| 3900 | /* |
| 3901 | char type, next_type; |
| 3902 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 3903 | AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_type); |
| 3904 | mprintf(0,"Curr anim type: %d, Next anim type: %d\n",type,next_type); |
| 3905 | if(next_type==AS_CUSTOM) mprintf(0,"NEXT TYPE IS CUSTOM!\n\n\n\n\n\n\n"); |
| 3906 | */ |
| 3907 | } |
| 3908 | |
| 3909 | // Process all AI Notify events |
| 3910 | bool AlienOrganism::DoNotify(int me, tOSIRISEventInfo *data) { |
| 3911 | if (IsGoalFinishedNotify(data->evt_ai_notify.notify_type)) { |
| 3912 | // Handle goal complete events |
| 3913 | switch (data->evt_ai_notify.goal_uid) { |
| 3914 | case ALIEN_GUID_GOT_HOME: |
| 3915 | memory->done_moving = true; |
| 3916 | break; |
| 3917 | case ALIEN_GUID_LANDED: |
| 3918 | memory->done_moving = true; |
| 3919 | break; |
| 3920 | case ALIEN_GUID_GOT_TO_DEST_OBJ: |
| 3921 | memory->dest_object_handle = OBJECT_HANDLE_NONE; |
| 3922 | SetMode(me, memory->mode); |
| 3923 | mprintf(0, "Alien got to destination object.\n"); |
| 3924 | break; |
| 3925 | } |
| 3926 | } else if (data->evt_ai_notify.notify_type == AIN_SCRIPTED_ORIENT) { |
| 3927 | // Handle custom orientation events |
| 3928 | if (memory->mode == ALIEN_LANDING_AT_HOME) { |
| 3929 | memory->done_turning = (AI_TurnTowardsVectors(me, &memory->home_fvec, &memory->home_uvec) != 0); |
| 3930 | } |
| 3931 | } else if (data->evt_ai_notify.notify_type == AIN_FIRED_WEAPON) { |
| 3932 | mprintf(0, "Energy weapon fired...\n"); |
| 3933 | |
| 3934 | // Subtract energy it took to fire energy bolt |
| 3935 | memory->energy_charges -= ALIEN_ENERGY_BOLT_COST; |
| 3936 | if (memory->energy_charges < 0.0f) |
| 3937 | memory->energy_charges = 0.0f; |
| 3938 | } else if (data->evt_ai_notify.notify_type == AIN_SCRIPTED_GOAL) { |
| 3939 | // mprintf(0,"Custom goal called.\n"); |
| 3940 | vector my_pos, dir; |
| 3941 | |
| 3942 | Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos); |
| 3943 | SendCommand(me, memory->leader_handle, ALIEN_COM_GET_GOAL_POS, &memory->squad_goal_pos); |
| 3944 | dir = memory->squad_goal_pos - my_pos; |
| 3945 | vm_VectorNormalize(&dir); |
| 3946 | |
| 3947 | AI_Value(me, VF_SET, AIV_V_MOVEMENT_DIR, &dir); |
| 3948 | } else if (data->evt_ai_notify.notify_type == AIN_SCRIPTED_ENABLER) { |
| 3949 | // mprintf(0,"Custom enabler called.\n"); |
| 3950 | bool is_visible; |
| 3951 | |
| 3952 | // Ask leader if he can see me |
| 3953 | SendCommand(me, memory->leader_handle, ALIEN_COM_CAN_YOU_SEE_ME, &is_visible); |
| 3954 | |
| 3955 | // If I'm visible, do straight line to position, otherwise deactivate this goal |
| 3956 | return is_visible; |
| 3957 | } else if (data->evt_ai_notify.notify_type == AIN_MELEE_HIT) { |
| 3958 | // Make sure we are doing the energy suck attack |
| 3959 | if (data->evt_ai_notify.attack_num == 0) { |
| 3960 | int target = data->evt_ai_notify.it_handle; |
| 3961 | |
| 3962 | // Check if target has energy (if not a player, assume it does have energy) |
| 3963 | bool target_has_energy = true; |
| 3964 | int type; |
| 3965 | Obj_Value(target, VF_GET, OBJV_I_TYPE, &type); |
| 3966 | if (type == OBJ_PLAYER) { |
| 3967 | if (qObjEnergy(target) <= 0.0f) { |
| 3968 | target_has_energy = false; |
| 3969 | } |
| 3970 | } |
| 3971 | |
| 3972 | // If target still has energy, give alien an energy charge |
| 3973 | if (target_has_energy && memory->energy_charges < ALIEN_MAX_ENERGY_CHARGES) { |
| 3974 | memory->energy_charges += ALIEN_ENERGY_SUCK_CHARGE; |
| 3975 | if (memory->energy_charges > ALIEN_MAX_ENERGY_CHARGES) { |
| 3976 | memory->energy_charges = ALIEN_MAX_ENERGY_CHARGES; |
| 3977 | } |
| 3978 | memory->ok_to_deposit = true; |
| 3979 | } |
| 3980 | } |
| 3981 | } else if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) { |
| 3982 | bot_com *com = (bot_com *)data->extra_info; |
| 3983 | |
| 3984 | return ReceiveCommand(me, data->evt_ai_notify.it_handle, com->action, com->ptr); |
| 3985 | } |
| 3986 | |
| 3987 | return true; |
| 3988 | } |
| 3989 | |
| 3990 | // Handles application of damage to an alien |
| 3991 | void AlienOrganism::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) { |
| 3992 | /* |
| 3993 | int wpn_handle=damage_data->weapon_handle; |
| 3994 | int type; |
| 3995 | uint16_t id; |
| 3996 | |
| 3997 | wpn_handle=damage_data->weapon_handle; |
| 3998 | Obj_Value(wpn_handle, VF_GET, OBJV_US_ID, &id); |
| 3999 | Obj_Value(wpn_handle, VF_GET, OBJV_I_TYPE, &type); |
| 4000 | |
| 4001 | if(type == OBJ_WEAPON && (id == Wpn_FindID("Napalm") || id == Wpn_FindID("NapalmBlob"))) |
| 4002 | */ |
| 4003 | |
| 4004 | // Handle fire damage |
| 4005 | if (damage_data->damage_type == GD_FIRE) { |
| 4006 | damage_data->damage *= 0.7f; |
| 4007 | // mprintf(0, "Damaged by fire!\n"); |
| 4008 | |
| 4009 | return; |
| 4010 | } |
| 4011 | |
| 4012 | // Handle damage by matter weapons |
| 4013 | if (damage_data->damage_type == GD_MATTER) { |
| 4014 | damage_data->damage *= 0.9f; |
| 4015 | |
| 4016 | if (Game_GetTime() >= memory->next_special_damage_time) { |
| 4017 | memory->next_special_damage_time = Game_GetTime() + 0.8f + ((float)rand() / (float)D3_RAND_MAX) * 0.5f; |
| 4018 | |
| 4019 | // Create a frag burst effect |
| 4020 | vector pos; |
| 4021 | int room; |
| 4022 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 4023 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 4024 | Obj_Create(OBJ_WEAPON, frag_burst_effect_id, room, &pos, NULL, me); |
| 4025 | } |
| 4026 | |
| 4027 | return; |
| 4028 | } |
| 4029 | |
| 4030 | // Handle damage by energy weapons |
| 4031 | if ((damage_data->damage_type == GD_ENERGY || damage_data->damage_type == GD_ELECTRIC) && |
| 4032 | Game_GetTime() >= memory->next_special_damage_time) { |
| 4033 | // Check if we're currently doing energy transfer or healing |
| 4034 | if (IsEnergyRelatedLandedMode(memory->mode)) { |
| 4035 | memory->next_special_damage_time = Game_GetTime() + 0.1f + ((float)rand() / (float)D3_RAND_MAX) * 0.2f; |
| 4036 | |
| 4037 | // Do double damage |
| 4038 | damage_data->damage *= 3.0f; |
| 4039 | |
| 4040 | // Create sparks |
| 4041 | int room; |
| 4042 | vector pos; |
| 4043 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 4044 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 4045 | Game_CreateRandomSparks(30 + int(((float)rand() / (float)D3_RAND_MAX) * 10.0f), &pos, room); |
| 4046 | |
| 4047 | return; |
| 4048 | } |
| 4049 | } |
| 4050 | |
| 4051 | // Just make it do little damage |
| 4052 | damage_data->damage *= 0.15f; |
| 4053 | // mprintf(0, "Not damaged!\n"); |
| 4054 | } |
| 4055 | |
| 4056 | // Handles attacks on aliens |
| 4057 | void AlienOrganism::DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data) { |
| 4058 | // See if it's a player or player weapon that hit us |
| 4059 | if (qObjIsPlayerOrPlayerWeapon(collide_data->it_handle)) { |
| 4060 | // mprintf(0,"Hit by player!\n"); |
| 4061 | memory->hit_by_player = true; |
| 4062 | } |
| 4063 | } |
| 4064 | |
| 4065 | // Receives all basic events and calls processesing functions |
| 4066 | int16_t AlienOrganism::CallEvent(int event, tOSIRISEventInfo *data) { |
| 4067 | switch (event) { |
| 4068 | case EVT_AI_INIT: |
| 4069 | DoInit(data->me_handle); |
| 4070 | break; |
| 4071 | case EVT_AI_FRAME: |
| 4072 | DoFrame(data->me_handle); |
| 4073 | break; |
| 4074 | case EVT_AI_NOTIFY: |
| 4075 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 4076 | break; |
| 4077 | case EVT_DAMAGED: |
| 4078 | DoDamage(data->me_handle, &data->evt_damaged); |
| 4079 | break; |
| 4080 | case EVT_DESTROY: |
| 4081 | msafe_struct mo; |
| 4082 | mo.objhandle = memory->pos1_handle; |
| 4083 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 4084 | mo.objhandle = memory->pos2_handle; |
| 4085 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 4086 | mo.objhandle = memory->pos3_handle; |
| 4087 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 4088 | break; |
| 4089 | case EVT_COLLIDE: |
| 4090 | DoCollide(data->me_handle, &data->evt_collide); |
| 4091 | break; |
| 4092 | case EVT_MEMRESTORE: |
| 4093 | memory = (alienorganism_data *)data->evt_memrestore.memory_ptr; |
| 4094 | break; |
| 4095 | } |
| 4096 | |
| 4097 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 4098 | } |
| 4099 | |
| 4100 | //--------------------- |
| 4101 | // Heavy Trooper class |
| 4102 | //--------------------- |
| 4103 | |
| 4104 | // Sets the trooper's max speed |
| 4105 | void HeavyTrooper::SetMaxSpeed(int me, float speed, bool accel_faster /*=false*/) { |
| 4106 | AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed); |
| 4107 | |
| 4108 | float delta_speed = memory->base_delta_speed; |
| 4109 | float turn_rate = memory->base_turn_rate; |
| 4110 | float delta_turn_rate = memory->base_delta_turn_rate; |
| 4111 | if (accel_faster) { |
| 4112 | delta_speed *= HT_RAMMING_DELTA_SPEED_MOD; |
| 4113 | turn_rate *= HT_RAMMING_TURN_RATE_MOD; |
| 4114 | delta_turn_rate *= HT_RAMMING_DELTA_TURN_RATE_MOD; |
| 4115 | } |
| 4116 | AI_Value(me, VF_SET, AIV_F_MAX_DELTA_SPEED, &delta_speed); |
| 4117 | AI_Value(me, VF_SET, AIV_F_MAX_TURN_RATE, &turn_rate); |
| 4118 | AI_Value(me, VF_SET, AIV_F_MAX_DELTA_TURN_RATE, &delta_turn_rate); |
| 4119 | } |
| 4120 | |
| 4121 | // Enable the trooper's gun attack |
| 4122 | void HeavyTrooper::EnableGunAttack(int me, bool enable /*=true*/) { |
| 4123 | int flags = AIF_DISABLE_FIRING; |
| 4124 | if (enable) { |
| 4125 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 4126 | } else { |
| 4127 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | // Launches a grenade |
| 4132 | void HeavyTrooper::LaunchGrenade(int me) { |
| 4133 | msafe_struct mstruct; |
| 4134 | |
| 4135 | mstruct.objhandle = me; |
| 4136 | mstruct.index = ht_grenade_id; |
| 4137 | if (mstruct.index == -1) |
| 4138 | return; |
| 4139 | mstruct.gunpoint = HT_GRENADE_GUNPOINT; |
| 4140 | MSafe_CallFunction(MSAFE_OBJECT_FIRE_WEAPON, &mstruct); |
| 4141 | |
| 4142 | // Play the impact mortar launch sound |
| 4143 | aSoundPlayObject(ht_grenade_sound_id, me, 1.0f); |
| 4144 | |
| 4145 | /* |
| 4146 | // Create blast effect |
| 4147 | vector pos; |
| 4148 | int room; |
| 4149 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 4150 | Obj_GetGunPos(me, HT_GRENADE_GUNPOINT, &pos); |
| 4151 | Obj_Create(OBJ_WEAPON, ht_grenade_effect_id, room, &pos, NULL, me); |
| 4152 | */ |
| 4153 | |
| 4154 | // Create smoke spew |
| 4155 | TurnOnSpew(me, 2, 7, 0.0f, 0.0f, 65536, false, 0.5f, 0.1f, 0.7f, 1.0f, 15.0f, true); |
| 4156 | TurnOnSpew(me, 2, 3, 0.0f, 0.0f, 65536, false, 0.2f, 0.05f, 0.3f, 2.0f, 40.0f, true); |
| 4157 | } |
| 4158 | |
| 4159 | // Checks whether the trooper has a clear shot |
| 4160 | bool HeavyTrooper::HasAClearGrenadeShot(int me, bool use_grenade_gunpoint /*=false*/) { |
| 4161 | vector pos, dir; |
| 4162 | matrix orient; |
| 4163 | int room; |
| 4164 | |
| 4165 | // Get the current object's room number |
| 4166 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 4167 | |
| 4168 | // See where we should aim from |
| 4169 | if (use_grenade_gunpoint) { |
| 4170 | // aim directly from the grenade launcher's gunpoint |
| 4171 | Obj_GetGunPos(me, HT_GRENADE_GUNPOINT, &pos, &dir); |
| 4172 | } else { |
| 4173 | // since we don't want to aim with the gunpoint, just use the forward vector |
| 4174 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 4175 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 4176 | dir = orient.fvec; |
| 4177 | } |
| 4178 | |
| 4179 | // See if should check for a clear shot |
| 4180 | tShotData shot_data; |
| 4181 | |
| 4182 | shot_data.object_handle = me; |
| 4183 | shot_data.danger_radius = 20.0f; |
| 4184 | shot_data.radius_inc = 1.2f; |
| 4185 | shot_data.max_dist = 120.0f; |
| 4186 | shot_data.risk_factor = 0.0f; |
| 4187 | shot_data.start_point = pos; |
| 4188 | shot_data.start_room = room; |
| 4189 | shot_data.dir = dir; |
| 4190 | shot_data.shot_radius = 5.0f; |
| 4191 | |
| 4192 | /* |
| 4193 | // If we're not checking during actual launch, make check a little bigger |
| 4194 | if(!use_grenade_gunpoint) |
| 4195 | { |
| 4196 | shot_data.danger_radius *= 1.3f; |
| 4197 | } |
| 4198 | */ |
| 4199 | |
| 4200 | int result = HasClearShot(&shot_data); |
| 4201 | |
| 4202 | if (result == CS_ALL_CLEAR) { |
| 4203 | return true; |
| 4204 | } else { |
| 4205 | mprintf(0, "Didn't shoot because: %d\n", result); |
| 4206 | return false; |
| 4207 | } |
| 4208 | } |
| 4209 | |
| 4210 | // Sets the Current Mode |
| 4211 | void HeavyTrooper::SetMode(int me, char mode) { |
| 4212 | int flags; |
| 4213 | |
| 4214 | // mprintf(0, "From mode %d, ",memory->mode); |
| 4215 | |
| 4216 | // Clear out any non-Dallas assigned goals |
| 4217 | AI_SafeSetType(me, AIT_AIS); |
| 4218 | |
| 4219 | // Turn on dodging (only off when curled up) |
| 4220 | flags = AIF_DODGE; |
| 4221 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 4222 | |
| 4223 | // Do mode specific setups |
| 4224 | switch (mode) { |
| 4225 | case HT_ATTACK_NORMAL: { |
| 4226 | mprintf(0, "Normal attack mode set.\n"); |
| 4227 | |
| 4228 | // Set firing capabilities |
| 4229 | EnableGunAttack(me); |
| 4230 | |
| 4231 | // Set speed |
| 4232 | SetMaxSpeed(me, memory->base_speed); |
| 4233 | |
| 4234 | // Set to default ranged attack goals |
| 4235 | AI_SafeSetType(me, AIT_EVADER1); |
| 4236 | } break; |
| 4237 | |
| 4238 | case HT_PREPARING_GRENADE: { |
| 4239 | mprintf(0, "Preparing grenade mode set.\n"); |
| 4240 | |
| 4241 | // Disable firing capabilities |
| 4242 | EnableGunAttack(me, false); |
| 4243 | |
| 4244 | // Set speed |
| 4245 | SetMaxSpeed(me, memory->base_speed * HT_GRENADE_AIMING_SPEED_MOD); |
| 4246 | |
| 4247 | // Set to default ranged attack goals |
| 4248 | AI_SafeSetType(me, AIT_EVADER1); |
| 4249 | } break; |
| 4250 | |
| 4251 | case HT_FIRING_GRENADE: { |
| 4252 | mprintf(0, "Firing grenade mode set.\n"); |
| 4253 | |
| 4254 | // Disable firing capabilities |
| 4255 | EnableGunAttack(me, false); |
| 4256 | |
| 4257 | // Set speed |
| 4258 | SetMaxSpeed(me, memory->base_speed * HT_GRENADE_FIRING_SPEED_MOD); |
| 4259 | |
| 4260 | // Set to default ranged attack goals |
| 4261 | AI_SafeSetType(me, AIT_EVADER1); |
| 4262 | |
| 4263 | // Play the fire grenade anim |
| 4264 | Obj_SetCustomAnim(me, HT_GRENADE_START_FRAME, HT_GRENADE_FIRE_FRAME, HT_GRENADE_FIRE_ANIM_TIME, 0, -1, -1); |
| 4265 | } break; |
| 4266 | |
| 4267 | case HT_RECOVERING: { |
| 4268 | mprintf(0, "Recovering mode set.\n"); |
| 4269 | |
| 4270 | // Disable firing capabilities |
| 4271 | EnableGunAttack(me, false); |
| 4272 | |
| 4273 | // Set speed |
| 4274 | SetMaxSpeed(me, memory->base_speed * HT_GRENADE_AIMING_SPEED_MOD); |
| 4275 | |
| 4276 | // Set to default ranged attack goals |
| 4277 | AI_SafeSetType(me, AIT_EVADER1); |
| 4278 | } break; |
| 4279 | |
| 4280 | case HT_PREPARING_FOR_CURL: { |
| 4281 | mprintf(0, "Preparing for curl mode set.\n"); |
| 4282 | |
| 4283 | // Disable firing capabilities |
| 4284 | EnableGunAttack(me, false); |
| 4285 | |
| 4286 | // Set speed |
| 4287 | SetMaxSpeed(me, memory->base_speed * HT_CURLING_SPEED_MOD); |
| 4288 | |
| 4289 | // Set to default ranged attack goals |
| 4290 | AI_SafeSetType(me, AIT_EVADER1); |
| 4291 | } break; |
| 4292 | |
| 4293 | case HT_CURLING_UP: { |
| 4294 | mprintf(0, "Curling up mode set.\n"); |
| 4295 | |
| 4296 | // Disable firing capabilities |
| 4297 | EnableGunAttack(me, false); |
| 4298 | |
| 4299 | // Set speed |
| 4300 | SetMaxSpeed(me, memory->base_speed * HT_CURLING_SPEED_MOD); |
| 4301 | |
| 4302 | // Play the curling up animation |
| 4303 | Obj_SetCustomAnim(me, HT_CURLUP_START_FRAME, HT_CURLUP_END_FRAME, HT_CURLUP_ANIM_TIME, 0, -1, -1); |
| 4304 | |
| 4305 | // Set to default ranged attack goals |
| 4306 | AI_SafeSetType(me, AIT_EVADER1); |
| 4307 | } break; |
| 4308 | |
| 4309 | case HT_UNCURLING: { |
| 4310 | mprintf(0, "Uncurling mode set.\n"); |
| 4311 | |
| 4312 | // Disable firing capabilities |
| 4313 | EnableGunAttack(me, false); |
| 4314 | |
| 4315 | // Set speed |
| 4316 | SetMaxSpeed(me, memory->base_speed * HT_CURLING_SPEED_MOD); |
| 4317 | |
| 4318 | // Play the uncurling animation and then switch back to alert |
| 4319 | Obj_SetCustomAnim(me, HT_UNCURL_START_FRAME, HT_UNCURL_END_FRAME, HT_UNCURL_ANIM_TIME, AIAF_NOTIFY, -1, AS_ALERT); |
| 4320 | |
| 4321 | // Set to default ranged attack goals |
| 4322 | AI_SafeSetType(me, AIT_EVADER1); |
| 4323 | } break; |
| 4324 | |
| 4325 | case HT_ARMORED_ATTACK: { |
| 4326 | mprintf(0, "Armored mode set.\n"); |
| 4327 | |
| 4328 | // Disable firing capabilities |
| 4329 | EnableGunAttack(me, false); |
| 4330 | |
| 4331 | // Turn off dodging |
| 4332 | flags = AIF_DODGE; |
| 4333 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 4334 | |
| 4335 | // Set speed |
| 4336 | SetMaxSpeed(me, memory->base_speed * HT_RAMMING_SPEED_MOD, true); |
| 4337 | |
| 4338 | // Set goal to ram into player |
| 4339 | AI_AddGoal(me, AIG_GET_TO_OBJ, 1, 1.0f, -1, |
| 4340 | GF_ORIENT_VELOCITY | GF_OBJ_IS_TARGET | GF_USE_BLINE_IF_SEES_GOAL | GF_KEEP_AT_COMPLETION | |
| 4341 | GF_NONFLUSHABLE, |
| 4342 | OBJECT_HANDLE_NONE); |
| 4343 | AI_SetGoalCircleDist(me, 1, 0.1f); |
| 4344 | } break; |
| 4345 | |
| 4346 | case HT_ARMORED_CIRCLE_BACK: { |
| 4347 | mprintf(0, "Armored circle-back mode set.\n"); |
| 4348 | |
| 4349 | vector pos; |
| 4350 | int room; |
| 4351 | |
| 4352 | // Disable firing capabilities |
| 4353 | EnableGunAttack(me, false); |
| 4354 | |
| 4355 | // Turn off dodging |
| 4356 | flags = AIF_DODGE; |
| 4357 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 4358 | |
| 4359 | // Set speed |
| 4360 | SetMaxSpeed(me, memory->base_speed * HT_CIRCLE_BACK_SPEED_MOD, true); |
| 4361 | |
| 4362 | // Set the goal to wander away for a few seconds |
| 4363 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 4364 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 4365 | |
| 4366 | float dist = 10.0f; |
| 4367 | |
| 4368 | AI_AddGoal(me, AIG_WANDER_AROUND, 1, 1.0f, -1, GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, &pos, room); |
| 4369 | AI_GoalValue(me, 1, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 4370 | |
| 4371 | int g_index = AI_AddGoal(me, AIG_GET_AROUND_OBJ, ACTIVATION_BLEND_LEVEL, 1.0f, -1, |
| 4372 | GF_OBJ_IS_TARGET | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, OBJECT_HANDLE_NONE); |
| 4373 | AI_GoalValue(me, g_index, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 4374 | } break; |
| 4375 | |
| 4376 | default: |
| 4377 | mprintf(0, "Heavy Trooper is all messed up!\n"); |
| 4378 | break; |
| 4379 | } |
| 4380 | |
| 4381 | // Set the current mode and reset the mode time |
| 4382 | memory->mode = mode; |
| 4383 | memory->mode_time = 0.0f; |
| 4384 | } |
| 4385 | |
| 4386 | // Processes the AI Initialize event |
| 4387 | void HeavyTrooper::DoInit(int me) { |
| 4388 | // Setup memory data |
| 4389 | tOSIRISMEMCHUNK ch; |
| 4390 | ch.id = HT_MEMORY_ID; |
| 4391 | ch.size = sizeof(heavytrooper_data); |
| 4392 | ch.my_id.type = OBJECT_SCRIPT; |
| 4393 | ch.my_id.objhandle = me; |
| 4394 | |
| 4395 | memory = (heavytrooper_data *)Scrpt_MemAlloc(&ch); |
| 4396 | |
| 4397 | // Init base values |
| 4398 | AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed); |
| 4399 | AI_Value(me, VF_GET, AIV_F_MAX_DELTA_SPEED, &memory->base_delta_speed); |
| 4400 | AI_Value(me, VF_GET, AIV_F_MAX_TURN_RATE, &memory->base_turn_rate); |
| 4401 | AI_Value(me, VF_GET, AIV_F_MAX_DELTA_TURN_RATE, &memory->base_delta_turn_rate); |
| 4402 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &memory->base_shields); |
| 4403 | |
| 4404 | // Init to no charge |
| 4405 | memory->charge = 0.0f; |
| 4406 | |
| 4407 | memory->max_charge = HT_MAX_CHARGE + ((float)rand() / (float)D3_RAND_MAX) * HT_MAX_CHARGE_VARIANCE; |
| 4408 | memory->curlup_dist = HT_CURLUP_DIST + ((float)rand() / (float)D3_RAND_MAX) * HT_CURLUP_DIST_VARIANCE; |
| 4409 | |
| 4410 | // Check for a grenade shot as soon as possible |
| 4411 | memory->next_grenade_check_time = Game_GetTime(); |
| 4412 | memory->last_grenade_time = Game_GetTime(); |
| 4413 | |
| 4414 | memory->next_charge_time = Game_GetTime(); |
| 4415 | memory->next_blast_time = Game_GetTime(); |
| 4416 | |
| 4417 | // Do next particle effect as soon as possible |
| 4418 | memory->next_particle_time = Game_GetTime(); |
| 4419 | |
| 4420 | // Start out in normal attack mode |
| 4421 | SetMode(me, HT_ATTACK_NORMAL); |
| 4422 | } |
| 4423 | |
| 4424 | // Processes the AI Frame Interval Event |
| 4425 | void HeavyTrooper::DoFrame(int me) { |
| 4426 | float last_see_time, last_see_game_time; |
| 4427 | float last_hear_time, last_hear_game_time; |
| 4428 | float curr_anim_frame; |
| 4429 | |
| 4430 | // Get the last see and hear time |
| 4431 | AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 4432 | AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_game_time); |
| 4433 | |
| 4434 | // Calculate the time since target was seen or heard |
| 4435 | last_hear_time = Game_GetTime() - last_hear_game_time; |
| 4436 | last_see_time = Game_GetTime() - last_see_game_time; |
| 4437 | |
| 4438 | // Get the current animation frame |
| 4439 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &curr_anim_frame); |
| 4440 | |
| 4441 | // Handle charge increase and decrease |
| 4442 | if (memory->mode == HT_ATTACK_NORMAL || memory->mode == HT_PREPARING_GRENADE || memory->mode == HT_FIRING_GRENADE || |
| 4443 | memory->mode == HT_RECOVERING) { |
| 4444 | if (Game_GetTime() >= memory->next_charge_time) { |
| 4445 | // Set the next recharge time |
| 4446 | memory->next_charge_time = Game_GetTime() + HT_RECHARGE_TIME; |
| 4447 | |
| 4448 | // Increment the charge |
| 4449 | memory->charge += HT_CHARGE_INC; |
| 4450 | if (memory->charge > memory->max_charge) { |
| 4451 | memory->charge = memory->max_charge; |
| 4452 | } |
| 4453 | } |
| 4454 | } else if (memory->mode == HT_ARMORED_ATTACK || memory->mode == HT_ARMORED_CIRCLE_BACK) { |
| 4455 | if (Game_GetTime() >= memory->next_charge_time) { |
| 4456 | // Set the next decharge time |
| 4457 | memory->next_charge_time = Game_GetTime() + HT_DECHARGE_TIME; |
| 4458 | |
| 4459 | // Decrement the charge |
| 4460 | memory->charge -= HT_CHARGE_INC; |
| 4461 | if (memory->charge < 0.0f) { |
| 4462 | memory->charge = 0.0f; |
| 4463 | } |
| 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | // mprintf(0,"Charge: %.1f\n",memory->charge); |
| 4468 | |
| 4469 | // Do mode specific checks |
| 4470 | switch (memory->mode) { |
| 4471 | case HT_ATTACK_NORMAL: { |
| 4472 | // Get the current target handle |
| 4473 | int target_handle; |
| 4474 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 4475 | |
| 4476 | ///* |
| 4477 | // If we are fully charged, decide if we should curl up |
| 4478 | if (memory->charge >= memory->max_charge) { |
| 4479 | // If low on hitpoints |
| 4480 | float shields; |
| 4481 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &shields); |
| 4482 | if (shields < (memory->base_shields * HT_CURLUP_DAMAGE)) { |
| 4483 | SetMode(me, HT_PREPARING_FOR_CURL); |
| 4484 | break; |
| 4485 | } |
| 4486 | |
| 4487 | // If close to target |
| 4488 | if (target_handle != OBJECT_HANDLE_NONE) { |
| 4489 | float dist; |
| 4490 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 4491 | if (dist < memory->curlup_dist) { |
| 4492 | SetMode(me, HT_PREPARING_FOR_CURL); |
| 4493 | break; |
| 4494 | } |
| 4495 | } |
| 4496 | } |
| 4497 | //*/ |
| 4498 | |
| 4499 | // Decide if we should switch into grenade mode |
| 4500 | if (Game_GetTime() >= memory->next_grenade_check_time) { |
| 4501 | memory->next_grenade_check_time = |
| 4502 | Game_GetTime() + HT_GRENADE_CHECK_INTERVAL + ((float)rand() / (float)D3_RAND_MAX) * HT_GRENADE_CHECK_VARIANCE; |
| 4503 | |
| 4504 | // Make sure enough time has gone by since we last fired |
| 4505 | if ((Game_GetTime() - memory->last_grenade_time) >= HT_GRENADE_RELOAD_TIME) { |
| 4506 | // Make sure we have a target |
| 4507 | if (target_handle != OBJECT_HANDLE_NONE) { |
| 4508 | float dist; |
| 4509 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 4510 | |
| 4511 | // Make sure the target is within range |
| 4512 | if (dist > HT_GRENADE_DIST && dist < HT_GRENADE_DIST_MAX) { |
| 4513 | // Make sure we currently have a clear shot |
| 4514 | if (HasAClearGrenadeShot(me, false)) { |
| 4515 | SetMode(me, HT_PREPARING_GRENADE); |
| 4516 | break; |
| 4517 | } |
| 4518 | } |
| 4519 | } |
| 4520 | } |
| 4521 | } |
| 4522 | |
| 4523 | // See if we're currently in the firing animation |
| 4524 | if (curr_anim_frame > HT_GUNFIRE_START_FRAME && curr_anim_frame < HT_GUNFIRE_END_FRAME) { |
| 4525 | // Check the time to see if we need to generate a new particle spew |
| 4526 | if (Game_GetTime() >= memory->next_particle_time) { |
| 4527 | memory->next_particle_time = Game_GetTime() + HT_MAX_PARTICLE_TIME; |
| 4528 | |
| 4529 | // Create the casing particle effect |
| 4530 | TurnOnSpew(me, 3, 15, 2.0f, 0.0f, 65536 | 128, false, 0.1f, 0.15f, HT_PARTICLE_SPEW_TIME, 0.2f, 50, true); |
| 4531 | |
| 4532 | /* |
| 4533 | msafe_struct mstruct; |
| 4534 | mstruct.objhandle = me; |
| 4535 | mstruct.index = Wpn_FindID("ChaffSpark") ; |
| 4536 | if (mstruct.index == -1) |
| 4537 | return; |
| 4538 | mstruct.gunpoint = 3; |
| 4539 | MSafe_CallFunction(MSAFE_OBJECT_FIRE_WEAPON,&mstruct); |
| 4540 | */ |
| 4541 | } |
| 4542 | } |
| 4543 | } break; |
| 4544 | |
| 4545 | case HT_PREPARING_GRENADE: { |
| 4546 | char type, next_type; |
| 4547 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 4548 | AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_type); |
| 4549 | |
| 4550 | // Wait until the current or next anim type is alert, then try and fire grenade |
| 4551 | if (type == AS_ALERT || next_type == AS_ALERT) { |
| 4552 | SetMode(me, HT_FIRING_GRENADE); |
| 4553 | break; |
| 4554 | } |
| 4555 | } break; |
| 4556 | |
| 4557 | case HT_FIRING_GRENADE: { |
| 4558 | // Wait until the fire frame is up |
| 4559 | if (curr_anim_frame == HT_GRENADE_FIRE_FRAME) { |
| 4560 | float anim_time; |
| 4561 | |
| 4562 | // Start the last grenade time count now |
| 4563 | memory->last_grenade_time = Game_GetTime(); |
| 4564 | |
| 4565 | // Do another aim check, but this time from the actual grenade gunpoint |
| 4566 | if (HasAClearGrenadeShot(me, true)) { |
| 4567 | // Fire grenade from gunpoint |
| 4568 | LaunchGrenade(me); |
| 4569 | |
| 4570 | // Set anim time to recoil |
| 4571 | anim_time = HT_GRENADE_RECOIL_ANIM_TIME; |
| 4572 | } else { |
| 4573 | // Set time to misfire |
| 4574 | anim_time = HT_GRENADE_MISFIRE_ANIM_TIME; |
| 4575 | } |
| 4576 | |
| 4577 | // Play the recover animation |
| 4578 | Obj_SetCustomAnim(me, HT_GRENADE_FIRE_FRAME, HT_GRENADE_END_FRAME, anim_time, AIAF_NOTIFY, -1, AS_ALERT); |
| 4579 | |
| 4580 | // Go to recover mode |
| 4581 | SetMode(me, HT_RECOVERING); |
| 4582 | break; |
| 4583 | } |
| 4584 | } break; |
| 4585 | |
| 4586 | case HT_RECOVERING: { |
| 4587 | char type; |
| 4588 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 4589 | |
| 4590 | // Wait until the current anim type is alert, then return to normal |
| 4591 | if (type == AS_ALERT) { |
| 4592 | SetMode(me, HT_ATTACK_NORMAL); |
| 4593 | break; |
| 4594 | } |
| 4595 | } break; |
| 4596 | |
| 4597 | case HT_PREPARING_FOR_CURL: { |
| 4598 | char type, next_type; |
| 4599 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 4600 | AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_type); |
| 4601 | |
| 4602 | // Wait until the current or next anim type is alert, then curl up |
| 4603 | if (type == AS_ALERT || next_type == AS_ALERT) { |
| 4604 | SetMode(me, HT_CURLING_UP); |
| 4605 | break; |
| 4606 | } |
| 4607 | } break; |
| 4608 | |
| 4609 | case HT_CURLING_UP: { |
| 4610 | // If we're done curling up, switch into armored attack mode |
| 4611 | if (curr_anim_frame == HT_CURLUP_END_FRAME) { |
| 4612 | Obj_SetCustomAnim(me, HT_ROLL_START_FRAME, HT_ROLL_END_FRAME, HT_ROLL_ANIM_TIME, AIAF_LOOPING, -1, -1); |
| 4613 | SetMode(me, HT_ARMORED_ATTACK); |
| 4614 | break; |
| 4615 | } |
| 4616 | } break; |
| 4617 | |
| 4618 | case HT_UNCURLING: { |
| 4619 | char type; |
| 4620 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 4621 | |
| 4622 | // Wait until the current anim type is alert, then return to normal |
| 4623 | if (type == AS_ALERT) { |
| 4624 | SetMode(me, HT_ATTACK_NORMAL); |
| 4625 | break; |
| 4626 | } |
| 4627 | } break; |
| 4628 | |
| 4629 | case HT_ARMORED_ATTACK: { |
| 4630 | // If we're out of charge time to uncurl |
| 4631 | if (memory->charge <= 0.0f) { |
| 4632 | SetMode(me, HT_UNCURLING); |
| 4633 | break; |
| 4634 | } |
| 4635 | } break; |
| 4636 | |
| 4637 | case HT_ARMORED_CIRCLE_BACK: { |
| 4638 | // If we're out of charge or have circled back long enough, get outta here |
| 4639 | if (memory->charge <= 0.0f || memory->mode_time >= HT_CIRCLE_BACK_TIME) { |
| 4640 | SetMode(me, HT_ARMORED_ATTACK); |
| 4641 | break; |
| 4642 | } |
| 4643 | } break; |
| 4644 | |
| 4645 | default: |
| 4646 | mprintf(0, "Heavy Trooper is all messed up!\n"); |
| 4647 | break; |
| 4648 | } |
| 4649 | |
| 4650 | // Increment the current mode time |
| 4651 | memory->mode_time += Game_GetFrameTime(); |
| 4652 | } |
| 4653 | |
| 4654 | // Process all AI Notify events |
| 4655 | bool HeavyTrooper::DoNotify(int me, tOSIRISEventInfo *data) { return true; } |
| 4656 | |
| 4657 | // Processes incoming damage reports |
| 4658 | void HeavyTrooper::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) { |
| 4659 | // If trooper is currently in armored mode, reduce damage significantly |
| 4660 | if (memory->mode == HT_ARMORED_ATTACK || memory->mode == HT_ARMORED_CIRCLE_BACK) { |
| 4661 | damage_data->damage *= HT_ARMOR_DAMAGED_MOD; |
| 4662 | } else if (memory->mode == HT_CURLING_UP || memory->mode == HT_UNCURLING) { |
| 4663 | damage_data->damage *= HT_CURLING_DAMAGED_MOD; |
| 4664 | } |
| 4665 | } |
| 4666 | |
| 4667 | // Handle smashing into target in armored mode |
| 4668 | void HeavyTrooper::DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data) { |
| 4669 | vector pos; |
| 4670 | int room; |
| 4671 | |
| 4672 | // Make sure we're in armored attack mode and still have charge left |
| 4673 | if (memory->mode == HT_ARMORED_ATTACK && memory->charge > 0.0f) { |
| 4674 | // Make sure it's ok to create the attack if necessary |
| 4675 | if (Game_GetTime() >= memory->next_blast_time) { |
| 4676 | // Make sure we have a target |
| 4677 | int target_handle; |
| 4678 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 4679 | if (target_handle != OBJECT_HANDLE_NONE) { |
| 4680 | // See if the object we collided with is the target |
| 4681 | if (collide_data->it_handle == target_handle) { |
| 4682 | // Create the shield blast |
| 4683 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 4684 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 4685 | Obj_Create(OBJ_WEAPON, shield_blast_id, room, &pos, NULL, me); |
| 4686 | |
| 4687 | // Set the next valid shield blast time |
| 4688 | memory->next_blast_time = Game_GetTime() + HT_SHIELD_BLAST_DELAY; |
| 4689 | |
| 4690 | // Tell him to run away |
| 4691 | SetMode(me, HT_ARMORED_CIRCLE_BACK); |
| 4692 | } |
| 4693 | } |
| 4694 | } |
| 4695 | } |
| 4696 | } |
| 4697 | |
| 4698 | // Receives all basic events and calls processesing functions |
| 4699 | int16_t HeavyTrooper::CallEvent(int event, tOSIRISEventInfo *data) { |
| 4700 | switch (event) { |
| 4701 | case EVT_AI_INIT: |
| 4702 | DoInit(data->me_handle); |
| 4703 | break; |
| 4704 | case EVT_AI_FRAME: |
| 4705 | DoFrame(data->me_handle); |
| 4706 | break; |
| 4707 | case EVT_AI_NOTIFY: |
| 4708 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 4709 | break; |
| 4710 | case EVT_DAMAGED: |
| 4711 | DoDamage(data->me_handle, &data->evt_damaged); |
| 4712 | break; |
| 4713 | case EVT_DESTROY: |
| 4714 | break; |
| 4715 | case EVT_COLLIDE: |
| 4716 | DoCollide(data->me_handle, &data->evt_collide); |
| 4717 | break; |
| 4718 | case EVT_MEMRESTORE: |
| 4719 | memory = (heavytrooper_data *)data->evt_memrestore.memory_ptr; |
| 4720 | break; |
| 4721 | } |
| 4722 | |
| 4723 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 4724 | } |
| 4725 | |
| 4726 | //-------------- |
| 4727 | // Lifter class |
| 4728 | //-------------- |
| 4729 | |
| 4730 | // Sets the trooper's max speed |
| 4731 | void Lifter::SetMaxSpeed(int me, float speed) { AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed); } |
| 4732 | |
| 4733 | // Checks to see if tractor beam pulling can commence/continue |
| 4734 | bool Lifter::OkToPull(int me, bool initial_check /*=true*/) { |
| 4735 | matrix orient; |
| 4736 | vector vec_to_target; |
| 4737 | int target_handle; |
| 4738 | float fov_angle; |
| 4739 | |
| 4740 | // If it's the initial check, make sure we're in alert mode |
| 4741 | if (initial_check) { |
| 4742 | char type; |
| 4743 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 4744 | |
| 4745 | // Wait until the current anim type is alert, then return to normal |
| 4746 | if (type != AS_ALERT) |
| 4747 | return false; |
| 4748 | } |
| 4749 | |
| 4750 | // Make sure we still have a target |
| 4751 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 4752 | if (target_handle == OBJECT_HANDLE_NONE) |
| 4753 | return false; |
| 4754 | |
| 4755 | // Make sure it's a pullable target |
| 4756 | int type; |
| 4757 | Obj_Value(target_handle, VF_GET, OBJV_I_TYPE, &type); |
| 4758 | if (type != OBJ_PLAYER) |
| 4759 | return false; |
| 4760 | |
| 4761 | // If it's not the initial pull, make sure the target hasn't changed |
| 4762 | if (!initial_check && target_handle != memory->pull_target) |
| 4763 | return false; |
| 4764 | |
| 4765 | // Make sure the target isn't cloaked |
| 4766 | if (qObjectCloakTime(target_handle) != 0.0f) |
| 4767 | return false; |
| 4768 | |
| 4769 | // check distance to target |
| 4770 | float dist; |
| 4771 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 4772 | if (dist > LIFTER_MAX_PULLING_DIST) |
| 4773 | return false; |
| 4774 | |
| 4775 | // Only check min distance if it's the initial decision check (whether to start pulling) |
| 4776 | if (initial_check && dist < LIFTER_MIN_PULLING_DIST) |
| 4777 | return false; |
| 4778 | |
| 4779 | // check FOV position of target (greater than 45 degrees is too much) |
| 4780 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 4781 | |
| 4782 | // NOTE: do my own vec to target here! (chris' doesn't update quick enough) |
| 4783 | AI_Value(me, VF_GET, AIV_V_VEC_TO_TARGET, &vec_to_target); |
| 4784 | vm_VectorNormalize(&vec_to_target); |
| 4785 | fov_angle = orient.fvec * vec_to_target; |
| 4786 | if (fov_angle < 0.7f) |
| 4787 | return false; |
| 4788 | |
| 4789 | // see if anything is in the way |
| 4790 | ray_info ray; |
| 4791 | int flags, fate; |
| 4792 | vector start_pos, end_pos, landing_pos; |
| 4793 | int start_room, landing_room; |
| 4794 | float target_size; |
| 4795 | |
| 4796 | Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos); |
| 4797 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room); |
| 4798 | Obj_Value(target_handle, VF_GET, OBJV_V_POS, &end_pos); |
| 4799 | Obj_Value(target_handle, VF_GET, OBJV_F_SIZE, &target_size); |
| 4800 | |
| 4801 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 4802 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 4803 | fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, target_size, flags, &ray); |
| 4804 | if (fate != HIT_NONE) |
| 4805 | return false; |
| 4806 | |
| 4807 | return true; |
| 4808 | } |
| 4809 | |
| 4810 | // Attempts to pull the target towards us |
| 4811 | void Lifter::PullTarget(int me) { |
| 4812 | // see if anything is in the way |
| 4813 | ray_info ray; |
| 4814 | int flags, fate; |
| 4815 | vector dir, start_pos, my_pos, end_pos, landing_pos; |
| 4816 | int start_room, landing_room; |
| 4817 | float target_size, dist; |
| 4818 | int target_handle; |
| 4819 | matrix target_orient; |
| 4820 | msafe_struct mstruct; |
| 4821 | |
| 4822 | // Make sure we still have a target |
| 4823 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 4824 | if (target_handle == OBJECT_HANDLE_NONE || target_handle != memory->pull_target) |
| 4825 | return; |
| 4826 | |
| 4827 | // get the target's info |
| 4828 | Obj_Value(target_handle, VF_GET, OBJV_V_POS, &start_pos); |
| 4829 | Obj_Value(target_handle, VF_GET, OBJV_I_ROOMNUM, &start_room); |
| 4830 | Obj_Value(target_handle, VF_GET, OBJV_M_ORIENT, &target_orient); |
| 4831 | Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos); |
| 4832 | Obj_Value(target_handle, VF_GET, OBJV_F_SIZE, &target_size); |
| 4833 | |
| 4834 | // Calc the direction to pull the target |
| 4835 | dir = my_pos - start_pos; |
| 4836 | vm_VectorNormalize(&dir); |
| 4837 | |
| 4838 | // Calc the distance to pull the target |
| 4839 | dist = (Game_GetTime() - memory->last_target_pull_time) * LIFTER_TARGET_PULL_SPEED; |
| 4840 | |
| 4841 | // Calc the point to move to |
| 4842 | end_pos = start_pos + (dir * dist); |
| 4843 | |
| 4844 | // See where it is safe to move to |
| 4845 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS; |
| 4846 | fate = FVI_RayCast(target_handle, &start_pos, &end_pos, start_room, target_size, flags, &ray); |
| 4847 | landing_pos = ray.hit_point; |
| 4848 | landing_room = ray.hit_room; |
| 4849 | |
| 4850 | // Now move the target to this position |
| 4851 | mstruct.objhandle = target_handle; |
| 4852 | mstruct.pos = landing_pos; |
| 4853 | mstruct.orient = target_orient; |
| 4854 | mstruct.roomnum = landing_room; |
| 4855 | MSafe_CallFunction(MSAFE_OBJECT_WORLD_POSITION, &mstruct); |
| 4856 | |
| 4857 | // Move the invisible target powerup to its appropriate position |
| 4858 | MoveTargetProp(target_handle); |
| 4859 | |
| 4860 | // Set the last pull time |
| 4861 | memory->last_target_pull_time = Game_GetTime(); |
| 4862 | } |
| 4863 | |
| 4864 | // Moves the target prop to the appropriate |
| 4865 | void Lifter::MoveTargetProp(int target_handle) { |
| 4866 | vector target_pos; |
| 4867 | int target_room; |
| 4868 | matrix target_orient; |
| 4869 | msafe_struct mstruct; |
| 4870 | |
| 4871 | Obj_Value(target_handle, VF_GET, OBJV_V_POS, &target_pos); |
| 4872 | Obj_Value(target_handle, VF_GET, OBJV_I_ROOMNUM, &target_room); |
| 4873 | Obj_Value(target_handle, VF_GET, OBJV_M_ORIENT, &target_orient); |
| 4874 | |
| 4875 | mstruct.objhandle = memory->pull_target_prop; |
| 4876 | mstruct.pos = target_pos - (target_orient.uvec * 1.4f); |
| 4877 | mstruct.orient = target_orient; |
| 4878 | mstruct.roomnum = target_room; |
| 4879 | MSafe_CallFunction(MSAFE_OBJECT_WORLD_POSITION, &mstruct); |
| 4880 | } |
| 4881 | |
| 4882 | // Creates the beam between me and the target |
| 4883 | void Lifter::UpdateTractorBeam(int me) { |
| 4884 | float next_duration = LIFTER_PULL_VALIDATE_INTERVAL; |
| 4885 | aLightningCreate(memory->pull_source_prop, memory->pull_target_prop, next_duration, 1.0f, 4, tractor_beam_effect_id, |
| 4886 | next_duration, 1, 255, 255, 255, false); |
| 4887 | } |
| 4888 | |
| 4889 | // All the controls that will be taken away while being force pulled |
| 4890 | #define PLAYER_CONTROL_MASK \ |
| 4891 | (PLYV_CMASK_FORWARD | PLYV_CMASK_REVERSE | PLYV_CMASK_LEFT | PLYV_CMASK_RIGHT | PLYV_CMASK_UP | PLYV_CMASK_DOWN | \ |
| 4892 | PLYV_CMASK_AFTERBURNER) |
| 4893 | |
| 4894 | // Takes away the target's movement |
| 4895 | void Lifter::ConfineTarget(int me) { |
| 4896 | int target_handle; |
| 4897 | |
| 4898 | // Make sure we still have a target |
| 4899 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 4900 | if (target_handle == OBJECT_HANDLE_NONE) |
| 4901 | return; |
| 4902 | |
| 4903 | // Save the current target handle |
| 4904 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &memory->pull_target); |
| 4905 | |
| 4906 | // Make sure it's a pullable target |
| 4907 | int type; |
| 4908 | Obj_Value(target_handle, VF_GET, OBJV_I_TYPE, &type); |
| 4909 | if (type == OBJ_PLAYER) { |
| 4910 | aTogglePlayerObjControl(0, PLAYER_CONTROL_MASK, memory->pull_target); |
| 4911 | } |
| 4912 | |
| 4913 | // Store our start-of-pull shield level |
| 4914 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &memory->shields_at_pull_start); |
| 4915 | |
| 4916 | // Clear the next pull check time |
| 4917 | memory->next_pull_check_time = Game_GetTime(); |
| 4918 | |
| 4919 | mprintf(0, "Target confined...\n"); |
| 4920 | } |
| 4921 | |
| 4922 | // Restores the target's movement |
| 4923 | void Lifter::ReleaseTarget(int me) { |
| 4924 | // Make sure we still have a target |
| 4925 | if (memory->pull_target != OBJECT_HANDLE_NONE && qObjExists(memory->pull_target)) { |
| 4926 | // Check the type |
| 4927 | int type; |
| 4928 | Obj_Value(memory->pull_target, VF_GET, OBJV_I_TYPE, &type); |
| 4929 | if (type == OBJ_PLAYER) { |
| 4930 | aTogglePlayerObjControl(1, PLAYER_CONTROL_MASK, memory->pull_target); |
| 4931 | } |
| 4932 | } |
| 4933 | |
| 4934 | // Release the pull target |
| 4935 | memory->pull_target = OBJECT_HANDLE_NONE; |
| 4936 | |
| 4937 | // Set the next pull check time for a nice delay |
| 4938 | memory->next_pull_check_time = |
| 4939 | Game_GetTime() + LIFTER_NEXT_PULL_DELAY + (((float)rand() / (float)D3_RAND_MAX) * LIFTER_NEXT_PULL_VARIANCE); |
| 4940 | |
| 4941 | mprintf(0, "Target released.\n"); |
| 4942 | } |
| 4943 | |
| 4944 | // Stops pulling and returns to hostile mode |
| 4945 | void Lifter::StopPulling(int me) { |
| 4946 | ReleaseTarget(me); |
| 4947 | SetMode(me, LIFTER_HOSTILE); |
| 4948 | } |
| 4949 | |
| 4950 | // Switches lifter to alert animation from idle |
| 4951 | void Lifter::SwitchToAlert(int me) { Obj_SetCustomAnim(me, 10, 12, 0.3f, AIAF_NOTIFY, -1, AS_ALERT); } |
| 4952 | |
| 4953 | // Sets the Current Mode |
| 4954 | void Lifter::SetMode(int me, char mode) { |
| 4955 | int flags; |
| 4956 | |
| 4957 | // mprintf(0, "From mode %d, ",memory->mode); |
| 4958 | |
| 4959 | // Clear out any non-Dallas assigned goals |
| 4960 | AI_SafeSetType(me, AIT_AIS); |
| 4961 | |
| 4962 | // Do mode specific setups |
| 4963 | switch (mode) { |
| 4964 | case LIFTER_PASSIVE: { |
| 4965 | mprintf(0, "Passive mode set.\n"); |
| 4966 | |
| 4967 | // Disable auto-targeting |
| 4968 | flags = AIF_DETERMINE_TARGET; |
| 4969 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 4970 | |
| 4971 | // Set to team neutral |
| 4972 | aAISetTeam(AIF_TEAM_NEUTRAL, me); |
| 4973 | |
| 4974 | // Set speed for this mode |
| 4975 | SetMaxSpeed(me, memory->base_speed); |
| 4976 | |
| 4977 | // Play the looping idle animation |
| 4978 | Obj_SetCustomAnim(me, 1, 10, 1.6f, AIAF_LOOPING, lifter_amb_sound_id, -1); |
| 4979 | } break; |
| 4980 | |
| 4981 | case LIFTER_AGITATED: { |
| 4982 | mprintf(0, "Agitated mode set.\n"); |
| 4983 | |
| 4984 | // Disable auto-targeting |
| 4985 | flags = AIF_DETERMINE_TARGET; |
| 4986 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 4987 | |
| 4988 | // Set to team neutral |
| 4989 | aAISetTeam(AIF_TEAM_NEUTRAL, me); |
| 4990 | |
| 4991 | // Set speed for this mode |
| 4992 | SetMaxSpeed(me, memory->base_speed * LIFTER_AGITATED_SPEED_MOD); |
| 4993 | } break; |
| 4994 | |
| 4995 | case LIFTER_HOSTILE: { |
| 4996 | mprintf(0, "Hostile mode set.\n"); |
| 4997 | |
| 4998 | // Set hostile melee attack |
| 4999 | flags = AIF_MELEE1; |
| 5000 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5001 | flags = AIF_MELEE2; |
| 5002 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5003 | |
| 5004 | // Enable auto-targeting |
| 5005 | flags = AIF_DETERMINE_TARGET; |
| 5006 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5007 | |
| 5008 | // Set to team PTMC |
| 5009 | aAISetTeam(AIF_TEAM_PTMC, me); |
| 5010 | |
| 5011 | // Set melee mode |
| 5012 | AI_SafeSetType(me, AIT_MELEE1); |
| 5013 | |
| 5014 | // Set speed for this mode |
| 5015 | SetMaxSpeed(me, memory->base_speed * LIFTER_HOSTILE_SPEED_MOD); |
| 5016 | |
| 5017 | // Set the hostile flag |
| 5018 | memory->not_hostile_yet = false; |
| 5019 | } break; |
| 5020 | |
| 5021 | case LIFTER_PULLING: { |
| 5022 | mprintf(0, "Pulling mode set.\n"); |
| 5023 | |
| 5024 | // Set pull melee attack |
| 5025 | flags = AIF_MELEE2; |
| 5026 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5027 | flags = AIF_MELEE1; |
| 5028 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5029 | |
| 5030 | // Disable auto-targeting so it can't acquire a new target |
| 5031 | flags = AIF_DETERMINE_TARGET; |
| 5032 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5033 | |
| 5034 | // NOTE: don't change teams here (needs to keep current target)! |
| 5035 | |
| 5036 | // Set melee mode |
| 5037 | AI_SafeSetType(me, AIT_MELEE1); |
| 5038 | |
| 5039 | // Set speed for this mode |
| 5040 | SetMaxSpeed(me, memory->base_speed * LIFTER_PULLING_SPEED_MOD); |
| 5041 | |
| 5042 | // Confine the target's movement |
| 5043 | ConfineTarget(me); |
| 5044 | |
| 5045 | // Move the target prop |
| 5046 | MoveTargetProp(memory->pull_target); |
| 5047 | |
| 5048 | // Clear the last pull time |
| 5049 | memory->last_target_pull_time = Game_GetTime(); |
| 5050 | } break; |
| 5051 | |
| 5052 | case LIFTER_PASSIFYING: { |
| 5053 | mprintf(0, "Passifying mode set.\n"); |
| 5054 | |
| 5055 | // Disable auto-targeting |
| 5056 | flags = AIF_DETERMINE_TARGET; |
| 5057 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5058 | |
| 5059 | // Set to team neutral |
| 5060 | aAISetTeam(AIF_TEAM_NEUTRAL, me); |
| 5061 | |
| 5062 | // Set speed for this mode |
| 5063 | SetMaxSpeed(me, memory->base_speed); |
| 5064 | |
| 5065 | // Play the to idle animation |
| 5066 | Obj_SetCustomAnim(me, 50, 52, 1.0f, 0, -1, -1); |
| 5067 | } break; |
| 5068 | |
| 5069 | default: |
| 5070 | mprintf(0, "Lifter is all messed up!\n"); |
| 5071 | break; |
| 5072 | } |
| 5073 | |
| 5074 | // Set the current mode and reset the mode time |
| 5075 | memory->mode = mode; |
| 5076 | memory->mode_time = 0.0f; |
| 5077 | } |
| 5078 | |
| 5079 | // Processes the AI Initialize event |
| 5080 | void Lifter::DoInit(int me) { |
| 5081 | // Setup memory data |
| 5082 | tOSIRISMEMCHUNK ch; |
| 5083 | ch.id = HT_MEMORY_ID; |
| 5084 | ch.size = sizeof(lifter_data); |
| 5085 | ch.my_id.type = OBJECT_SCRIPT; |
| 5086 | ch.my_id.objhandle = me; |
| 5087 | |
| 5088 | memory = (lifter_data *)Scrpt_MemAlloc(&ch); |
| 5089 | |
| 5090 | // Init base values |
| 5091 | AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed); |
| 5092 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &memory->base_shields); |
| 5093 | memory->shield_loss_margin = memory->base_shields * LIFTER_LOSE_PULL_SHIELD_PERCENT; |
| 5094 | |
| 5095 | memory->pull_target = OBJECT_HANDLE_NONE; |
| 5096 | |
| 5097 | // Create and setup the beam pulling target prop object |
| 5098 | msafe_struct mstruct; |
| 5099 | vector pos; |
| 5100 | int room; |
| 5101 | |
| 5102 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 5103 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 5104 | |
| 5105 | memory->pull_target_prop = Obj_Create(OBJ_POWERUP, powerup_id, room, &pos, NULL, me); |
| 5106 | mstruct.objhandle = memory->pull_target_prop; |
| 5107 | MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct); |
| 5108 | |
| 5109 | // Create the source tractor beam prop |
| 5110 | memory->pull_source_prop = CreateAndAttach(me, "STEmitter", OBJ_ROBOT, 1, 0, true, true); |
| 5111 | |
| 5112 | // Init time values |
| 5113 | memory->last_damaged_time = Game_GetTime(); |
| 5114 | memory->next_pull_check_time = Game_GetTime(); |
| 5115 | memory->last_target_pull_time = Game_GetTime(); |
| 5116 | memory->next_lift_beam_time = Game_GetTime(); |
| 5117 | |
| 5118 | // Set the attacked flag |
| 5119 | memory->not_hostile_yet = true; |
| 5120 | |
| 5121 | // Create the lifter's stick effect |
| 5122 | aLightningCreateGunpoints(0, 1, me, 1000000000.0f, 2.0f, 2, lifter_stick_effect_id, 0.5f, 1, 255, 255, 255, false); |
| 5123 | |
| 5124 | // Start out in normal attack mode |
| 5125 | SetMode(me, LIFTER_PASSIVE); |
| 5126 | } |
| 5127 | |
| 5128 | // Process all AI Notify events |
| 5129 | bool Lifter::DoNotify(int me, tOSIRISEventInfo *data) { |
| 5130 | if (data->evt_ai_notify.notify_type == AIN_TARGET_DIED) { |
| 5131 | if (memory->mode == LIFTER_PULLING) { |
| 5132 | StopPulling(me); |
| 5133 | } |
| 5134 | } else if (data->evt_ai_notify.notify_type == AIN_MELEE_HIT) { |
| 5135 | // If we are pulling |
| 5136 | if (memory->mode == LIFTER_PULLING) { |
| 5137 | // Create hit sparks |
| 5138 | int room; |
| 5139 | vector pos; |
| 5140 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 5141 | Obj_GetGunPos(me, 1, &pos); |
| 5142 | Game_CreateRandomSparks(20, &pos, room); |
| 5143 | |
| 5144 | // Stop pulling |
| 5145 | StopPulling(me); |
| 5146 | |
| 5147 | // Create the concussive hit blast |
| 5148 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 5149 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 5150 | // Obj_GetGunPos(me, 2, &pos); |
| 5151 | Obj_Create(OBJ_WEAPON, lifter_blast_effect_id, room, &pos, NULL, me); |
| 5152 | } |
| 5153 | } |
| 5154 | |
| 5155 | return true; |
| 5156 | } |
| 5157 | |
| 5158 | // Processes the AI Frame Interval Event |
| 5159 | void Lifter::DoFrame(int me) { |
| 5160 | float last_see_time, last_see_game_time; |
| 5161 | float last_hear_time, last_hear_game_time; |
| 5162 | float last_perceive_time; |
| 5163 | float curr_anim_frame; |
| 5164 | |
| 5165 | // Get the last see and hear time |
| 5166 | AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 5167 | AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_game_time); |
| 5168 | |
| 5169 | // Calculate the time since target was seen or heard |
| 5170 | last_hear_time = Game_GetTime() - last_hear_game_time; |
| 5171 | last_see_time = Game_GetTime() - last_see_game_time; |
| 5172 | |
| 5173 | // Perceive time is last time target was seen or heard (whichever is smalled) |
| 5174 | if (last_hear_time <= last_see_time) { |
| 5175 | last_perceive_time = last_hear_time; |
| 5176 | } else { |
| 5177 | last_perceive_time = last_see_time; |
| 5178 | } |
| 5179 | |
| 5180 | // Get the current animation frame |
| 5181 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &curr_anim_frame); |
| 5182 | |
| 5183 | // Do mode specific checks |
| 5184 | switch (memory->mode) { |
| 5185 | case LIFTER_PASSIVE: { |
| 5186 | } break; |
| 5187 | |
| 5188 | case LIFTER_AGITATED: { |
| 5189 | // If we've been agitated for a little while, and are damaged enough, switch to hostile |
| 5190 | if (memory->mode_time > LIFTER_MIN_AGITATED_MODE_TIME) { |
| 5191 | float curr_shields; |
| 5192 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &curr_shields); |
| 5193 | if (curr_shields < (memory->base_shields * LIFTER_HOSTILE_SHIELD_PERCENT)) { |
| 5194 | SetMode(me, LIFTER_HOSTILE); |
| 5195 | break; |
| 5196 | } |
| 5197 | |
| 5198 | // If we haven't been damaged in a while, become passive again |
| 5199 | float time_since_damaged; |
| 5200 | time_since_damaged = Game_GetTime() - memory->last_damaged_time; |
| 5201 | if (time_since_damaged >= LIFTER_AGITATED_INTEREST_TIME) { |
| 5202 | SetMode(me, LIFTER_PASSIFYING); |
| 5203 | break; |
| 5204 | } |
| 5205 | } |
| 5206 | } break; |
| 5207 | |
| 5208 | case LIFTER_HOSTILE: { |
| 5209 | // If hostile for a while, and haven't been damaged in a while, become passive |
| 5210 | if (memory->mode_time > LIFTER_MIN_HOSTILE_MODE_TIME) { |
| 5211 | float time_since_damaged; |
| 5212 | |
| 5213 | time_since_damaged = Game_GetTime() - memory->last_damaged_time; |
| 5214 | if (time_since_damaged >= LIFTER_HOSTILE_INTEREST_TIME) { |
| 5215 | char type; |
| 5216 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 5217 | |
| 5218 | // Wait until the current anim type is alert, then return to passive |
| 5219 | if (type == AS_ALERT) { |
| 5220 | SetMode(me, LIFTER_PASSIFYING); |
| 5221 | break; |
| 5222 | } |
| 5223 | } |
| 5224 | } |
| 5225 | |
| 5226 | // See if we should do a tractor beam pull |
| 5227 | if (Game_GetTime() >= memory->next_pull_check_time) { |
| 5228 | memory->next_pull_check_time = Game_GetTime() + LIFTER_PULL_CHECK_INTERVAL; |
| 5229 | |
| 5230 | // See if it's possible to start pulling target |
| 5231 | if (OkToPull(me)) { |
| 5232 | aSoundPlayObject(lifter_pull_sound_id, me, 1.0f); |
| 5233 | |
| 5234 | // Switch to pulling mode |
| 5235 | SetMode(me, LIFTER_PULLING); |
| 5236 | break; |
| 5237 | } |
| 5238 | } |
| 5239 | } break; |
| 5240 | |
| 5241 | case LIFTER_PULLING: { |
| 5242 | // See if we should update the tractor beam and validate the current pull situation |
| 5243 | if (Game_GetTime() >= memory->next_pull_check_time) { |
| 5244 | memory->next_pull_check_time = Game_GetTime() + LIFTER_PULL_VALIDATE_INTERVAL; |
| 5245 | |
| 5246 | // See if the pulling operation is still valid |
| 5247 | if (OkToPull(me, false)) { |
| 5248 | UpdateTractorBeam(me); |
| 5249 | } else { |
| 5250 | // Otherwise, quit pulling |
| 5251 | StopPulling(me); |
| 5252 | break; |
| 5253 | } |
| 5254 | } |
| 5255 | |
| 5256 | // Pull the target forward |
| 5257 | bool not_multiplayer = true; |
| 5258 | if (not_multiplayer || (Game_GetTime() - memory->last_target_pull_time) >= LIFTER_PULL_TARGET_INTERVAL) { |
| 5259 | PullTarget(me); |
| 5260 | } |
| 5261 | |
| 5262 | // Have we reached the maximum pulling time? |
| 5263 | if (memory->mode_time > LIFTER_MAX_PULL_TIME) { |
| 5264 | StopPulling(me); |
| 5265 | break; |
| 5266 | } |
| 5267 | } break; |
| 5268 | |
| 5269 | case LIFTER_PASSIFYING: { |
| 5270 | float curr_anim_frame; |
| 5271 | |
| 5272 | // Get the current animation frame |
| 5273 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &curr_anim_frame); |
| 5274 | |
| 5275 | // See if we can return to passive yet |
| 5276 | if (curr_anim_frame == 52) { |
| 5277 | SetMode(me, LIFTER_PASSIVE); |
| 5278 | break; |
| 5279 | } |
| 5280 | } break; |
| 5281 | |
| 5282 | default: |
| 5283 | mprintf(0, "Lifter is all messed up!\n"); |
| 5284 | break; |
| 5285 | } |
| 5286 | |
| 5287 | // If we're carrying anything, display the carry beam |
| 5288 | UpdateLiftBeam(me); |
| 5289 | |
| 5290 | // Increment the current mode time |
| 5291 | memory->mode_time += Game_GetFrameTime(); |
| 5292 | } |
| 5293 | |
| 5294 | // Handles the healing effects |
| 5295 | void Lifter::UpdateLiftBeam(int me) { |
| 5296 | // See if it's time to create the next energy effect |
| 5297 | if (memory->next_lift_beam_time <= Game_GetTime()) { |
| 5298 | float next_duration = LIFTER_LIFT_BEAM_UPDATE_TIME; |
| 5299 | |
| 5300 | memory->next_lift_beam_time = Game_GetTime() + next_duration; |
| 5301 | |
| 5302 | // See if we're carrying an object |
| 5303 | int attached_handle = Obj_GetAttachChildHandle(me, 0); |
| 5304 | if (attached_handle != OBJECT_HANDLE_NONE) { |
| 5305 | aLightningCreate(me, attached_handle, next_duration, 2.0f, 2, boss_heal_effect_id, next_duration, 1, 255, 255, |
| 5306 | 255, false); |
| 5307 | } |
| 5308 | } |
| 5309 | } |
| 5310 | |
| 5311 | // Processes incoming damage reports |
| 5312 | void Lifter::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) { |
| 5313 | memory->last_damaged_time = Game_GetTime(); |
| 5314 | |
| 5315 | if (memory->mode == LIFTER_PASSIVE) { |
| 5316 | if (memory->not_hostile_yet) { |
| 5317 | // If not hostile yet, check to see if we should be agitated |
| 5318 | float curr_shields; |
| 5319 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &curr_shields); |
| 5320 | if (curr_shields < (memory->base_shields * LIFTER_AGITATED_SHIELD_PERCENT)) { |
| 5321 | SwitchToAlert(me); |
| 5322 | SetMode(me, LIFTER_AGITATED); |
| 5323 | return; |
| 5324 | } |
| 5325 | } else { |
| 5326 | // If we've been hostile already, just switch right back into hostile mode |
| 5327 | SwitchToAlert(me); |
| 5328 | SetMode(me, LIFTER_HOSTILE); |
| 5329 | return; |
| 5330 | } |
| 5331 | } else if (memory->mode == LIFTER_PULLING) { |
| 5332 | float curr_shields, damage_done_during_pull; |
| 5333 | |
| 5334 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &curr_shields); |
| 5335 | damage_done_during_pull = memory->shields_at_pull_start - curr_shields; |
| 5336 | if (damage_done_during_pull >= memory->shield_loss_margin) { |
| 5337 | // Create tractor beam device sparks |
| 5338 | int room; |
| 5339 | vector pos; |
| 5340 | Obj_Value(memory->pull_source_prop, VF_GET, OBJV_I_ROOMNUM, &room); |
| 5341 | Obj_Value(memory->pull_source_prop, VF_GET, OBJV_V_POS, &pos); |
| 5342 | Game_CreateRandomSparks(15, &pos, room); |
| 5343 | |
| 5344 | // Stop pulling |
| 5345 | StopPulling(me); |
| 5346 | } |
| 5347 | } |
| 5348 | } |
| 5349 | |
| 5350 | // Something collided with lifter |
| 5351 | void Lifter::DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data) {} |
| 5352 | |
| 5353 | // Does any final cleanup when object is destroyed |
| 5354 | void Lifter::DoCleanUp(int me) { |
| 5355 | // remove the powerup props |
| 5356 | msafe_struct mo; |
| 5357 | mo.objhandle = memory->pull_source_prop; |
| 5358 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 5359 | mo.objhandle = memory->pull_target_prop; |
| 5360 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 5361 | |
| 5362 | // if we're pulling a target, release it |
| 5363 | if (memory->pull_target != OBJECT_HANDLE_NONE) { |
| 5364 | ReleaseTarget(me); |
| 5365 | } |
| 5366 | } |
| 5367 | |
| 5368 | // Receives all basic events and calls processesing functions |
| 5369 | int16_t Lifter::CallEvent(int event, tOSIRISEventInfo *data) { |
| 5370 | switch (event) { |
| 5371 | case EVT_AI_INIT: |
| 5372 | DoInit(data->me_handle); |
| 5373 | break; |
| 5374 | case EVT_AI_FRAME: |
| 5375 | DoFrame(data->me_handle); |
| 5376 | break; |
| 5377 | case EVT_AI_NOTIFY: |
| 5378 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 5379 | break; |
| 5380 | case EVT_DAMAGED: |
| 5381 | DoDamage(data->me_handle, &data->evt_damaged); |
| 5382 | break; |
| 5383 | case EVT_DESTROY: |
| 5384 | DoCleanUp(data->me_handle); |
| 5385 | break; |
| 5386 | case EVT_COLLIDE: |
| 5387 | DoCollide(data->me_handle, &data->evt_collide); |
| 5388 | break; |
| 5389 | case EVT_PLAYER_DIES: |
| 5390 | if (memory->mode == LIFTER_PULLING && data->evt_player_dies.it_handle == memory->pull_target) { |
| 5391 | StopPulling(data->me_handle); |
| 5392 | } |
| 5393 | break; |
| 5394 | case EVT_MEMRESTORE: |
| 5395 | memory = (lifter_data *)data->evt_memrestore.memory_ptr; |
| 5396 | break; |
| 5397 | } |
| 5398 | |
| 5399 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 5400 | } |
| 5401 | |
| 5402 | //----------------- |
| 5403 | // AlienBoss class |
| 5404 | //----------------- |
| 5405 | |
| 5406 | // Sends a command out to alien boss |
| 5407 | bool AlienBoss::SendCommand(int me, int it, char command, void *ptr) { |
| 5408 | bot_com com; |
| 5409 | |
| 5410 | com.action = command; |
| 5411 | com.ptr = ptr; |
| 5412 | |
| 5413 | tOSIRISEventInfo ei; |
| 5414 | |
| 5415 | ei.me_handle = it; |
| 5416 | ei.extra_info = (void *)&com; |
| 5417 | ei.evt_ai_notify.notify_type = AIN_USER_DEFINED; |
| 5418 | ei.evt_ai_notify.it_handle = me; |
| 5419 | |
| 5420 | return Obj_CallEvent(it, EVT_AI_NOTIFY, &ei); |
| 5421 | } |
| 5422 | |
| 5423 | // Processes a command from another alien |
| 5424 | bool AlienBoss::ReceiveCommand(int me, int it, char command, void *ptr) { |
| 5425 | switch (command) { |
| 5426 | case AB_COM_THRUSTER_IS_FIRING: { |
| 5427 | if (memory->mode == AB_HEALING) { |
| 5428 | // Set to the death mode for final dallas-controlled cinematic |
| 5429 | SetMode(me, AB_DYING); |
| 5430 | |
| 5431 | // Let dallas know that we were healing |
| 5432 | *(bool *)ptr = true; |
| 5433 | } else { |
| 5434 | // Run away from flame if necessary |
| 5435 | SetMode(me, AB_HIDING_FROM_THRUSTER); |
| 5436 | |
| 5437 | // Let dallas know that we weren't healing |
| 5438 | *(bool *)ptr = false; |
| 5439 | } |
| 5440 | } break; |
| 5441 | |
| 5442 | case AB_COM_THRUSTER_MISFIRED: { |
| 5443 | // Time to go protect the nest |
| 5444 | SetMode(me, AB_GOING_TO_PROTECT_NEST); |
| 5445 | } break; |
| 5446 | |
| 5447 | case AB_COM_ITS_SHOWTIME: { |
| 5448 | // Make it start out in reverse |
| 5449 | memory->wander_forward = false; |
| 5450 | |
| 5451 | // Set the intro end time |
| 5452 | memory->intro_end_time = *(float *)ptr; |
| 5453 | memory->intro_ended = false; |
| 5454 | |
| 5455 | // Time to go protect the nest |
| 5456 | SetMode(me, AB_WANDERING); |
| 5457 | } break; |
| 5458 | |
| 5459 | case AB_COM_START_WAITING_EFFECT: { |
| 5460 | // Make it start out in reverse |
| 5461 | memory->waiting_effect_enabled = true; |
| 5462 | } break; |
| 5463 | |
| 5464 | case AB_COM_THRUSTER_IGNITED: { |
| 5465 | // This makes us angry |
| 5466 | memory->state = AB_ANGRY; |
| 5467 | |
| 5468 | // Set the new damage level |
| 5469 | memory->damage_threshold = AB_ANGRY_DAMAGE_LEVEL * memory->base_shields; |
| 5470 | |
| 5471 | // Make it slightly faster |
| 5472 | memory->base_speed *= 1.05f; |
| 5473 | |
| 5474 | mprintf(0, "Alien Boss is now angry.\n"); |
| 5475 | } break; |
| 5476 | |
| 5477 | case AB_COM_SET_SCENARIO_IDS: { |
| 5478 | ab_scenario_ids *ids = (ab_scenario_ids *)ptr; |
| 5479 | |
| 5480 | memory->nest_handle = ids->nest_handle; |
| 5481 | memory->left_hide_room = ids->left_hide_room; |
| 5482 | memory->right_hide_room = ids->right_hide_room; |
| 5483 | |
| 5484 | mprintf(0, "Set scenario ids.\n"); |
| 5485 | } break; |
| 5486 | |
| 5487 | case AB_COM_IS_NESTING: { |
| 5488 | if (memory->mode == AB_HEALING) { |
| 5489 | *(bool *)ptr = true; |
| 5490 | } else { |
| 5491 | *(bool *)ptr = false; |
| 5492 | } |
| 5493 | } break; |
| 5494 | } |
| 5495 | |
| 5496 | // mprintf(0, "AlienOrganism action %d failed\n"); |
| 5497 | return false; |
| 5498 | } |
| 5499 | |
| 5500 | // Sets the alien boss's max speed |
| 5501 | void AlienBoss::SetMaxSpeed(int me, float speed) { AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &speed); } |
| 5502 | |
| 5503 | // Checks to see if alien is currently on fire |
| 5504 | bool AlienBoss::IsOnFire(int me) { return (Obj_IsEffect(me, EF_NAPALMED)); } |
| 5505 | |
| 5506 | // Sets wandering destination goal for boss |
| 5507 | void AlienBoss::SetWanderGoal(int me) { |
| 5508 | vector pos; |
| 5509 | int room = 0; |
| 5510 | float dist = 15.0f; |
| 5511 | |
| 5512 | // If the destination object is valid, set the goals to go to that object |
| 5513 | if (memory->dest_object_handle != OBJECT_HANDLE_NONE) { |
| 5514 | int type; |
| 5515 | Obj_Value(memory->dest_object_handle, VF_GET, OBJV_I_TYPE, &type); |
| 5516 | if (type != OBJ_NONE) { |
| 5517 | AI_AddGoal(me, AIG_GET_TO_OBJ, 2, 1.0f, ALIEN_GUID_GOT_TO_DEST_OBJ, |
| 5518 | GF_ORIENT_VELOCITY | GF_USE_BLINE_IF_SEES_GOAL | GF_KEEP_AT_COMPLETION | GF_NONFLUSHABLE, |
| 5519 | memory->dest_object_handle); |
| 5520 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 5521 | |
| 5522 | return; |
| 5523 | } |
| 5524 | memory->dest_object_handle = OBJECT_HANDLE_NONE; |
| 5525 | } |
| 5526 | |
| 5527 | // Set the goal to wander |
| 5528 | AI_AddGoal(me, AIG_WANDER_AROUND, 2, 1.0f, -1, GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, room, room); |
| 5529 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 5530 | } |
| 5531 | |
| 5532 | // Sets goal to go to the current wander room |
| 5533 | void AlienBoss::SetWanderRoomGoal(int me) { |
| 5534 | vector pos; |
| 5535 | int roomnum; |
| 5536 | |
| 5537 | roomnum = memory->wander_rooms[memory->curr_wander_room_index]; |
| 5538 | |
| 5539 | Room_Value(roomnum, VF_GET, RMSV_V_PATH_PNT, &pos, 0); |
| 5540 | AI_AddGoal(me, AIG_GET_TO_POS, 2, DEFAULT_INFLUENCE, AB_GUID_GOT_TO_WANDER_ROOM, GF_ORIENT_VELOCITY, &pos, roomnum); |
| 5541 | |
| 5542 | // Save values for teleport |
| 5543 | memory->dest_pos = pos; |
| 5544 | memory->dest_room = roomnum; |
| 5545 | |
| 5546 | float dist = 35.0f; |
| 5547 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 5548 | } |
| 5549 | |
| 5550 | // Sets goal to go to the current wander room |
| 5551 | void AlienBoss::SetProtectNestGoal(int me) { |
| 5552 | vector pos; |
| 5553 | int roomnum; |
| 5554 | |
| 5555 | // Go to the nest room (first room is list) |
| 5556 | roomnum = memory->wander_rooms[0]; |
| 5557 | |
| 5558 | Room_Value(roomnum, VF_GET, RMSV_V_PATH_PNT, &pos, 0); |
| 5559 | AI_AddGoal(me, AIG_GET_TO_POS, 2, DEFAULT_INFLUENCE, AB_GUID_GOT_TO_NEST_ROOM, GF_ORIENT_VELOCITY, &pos, roomnum); |
| 5560 | |
| 5561 | // Save values for teleport |
| 5562 | memory->dest_pos = pos; |
| 5563 | memory->dest_room = roomnum; |
| 5564 | |
| 5565 | float dist = 35.0f; |
| 5566 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 5567 | } |
| 5568 | |
| 5569 | // Sets goal to go to the current wander room |
| 5570 | void AlienBoss::SetHideRoomGoal(int me) { |
| 5571 | vector pos, left_room_pos, right_room_pos, my_pos; |
| 5572 | int roomnum; |
| 5573 | float left_room_dist; |
| 5574 | float right_room_dist; |
| 5575 | |
| 5576 | // Get current position |
| 5577 | Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos); |
| 5578 | |
| 5579 | // Get positions of hide rooms |
| 5580 | Room_Value(memory->left_hide_room, VF_GET, RMSV_V_PATH_PNT, &left_room_pos, 0); |
| 5581 | Room_Value(memory->right_hide_room, VF_GET, RMSV_V_PATH_PNT, &right_room_pos, 0); |
| 5582 | |
| 5583 | // Get the distance to each hide room |
| 5584 | left_room_dist = vm_VectorDistance(&my_pos, &left_room_pos); |
| 5585 | right_room_dist = vm_VectorDistance(&my_pos, &right_room_pos); |
| 5586 | |
| 5587 | // Determine the closest hide room, and go to it |
| 5588 | if (left_room_dist < right_room_dist) { |
| 5589 | roomnum = memory->left_hide_room; |
| 5590 | pos = left_room_pos; |
| 5591 | } else { |
| 5592 | roomnum = memory->right_hide_room; |
| 5593 | pos = right_room_pos; |
| 5594 | } |
| 5595 | |
| 5596 | Room_Value(roomnum, VF_GET, RMSV_V_PATH_PNT, &pos, 0); |
| 5597 | AI_AddGoal(me, AIG_GET_TO_POS, 2, DEFAULT_INFLUENCE, AB_GUID_GOT_TO_HIDE_ROOM, |
| 5598 | GF_ORIENT_VELOCITY | GF_KEEP_AT_COMPLETION, &pos, roomnum); |
| 5599 | |
| 5600 | // Save values for teleport |
| 5601 | memory->dest_pos = pos; |
| 5602 | memory->dest_room = roomnum; |
| 5603 | |
| 5604 | float dist = 30.0f; |
| 5605 | AI_GoalValue(me, 2, VF_SET, AIGV_F_CIRCLE_DIST, &dist); |
| 5606 | } |
| 5607 | |
| 5608 | // Returns the index of the wander room closest to current position |
| 5609 | int AlienBoss::DetermineClosestRoom(int me) { |
| 5610 | int j, closest_room; |
| 5611 | float closest_dist, dist; |
| 5612 | vector my_pos, room_pos; |
| 5613 | |
| 5614 | // Get current position |
| 5615 | Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos); |
| 5616 | |
| 5617 | // Find the room closest to |
| 5618 | closest_room = 0; |
| 5619 | closest_dist = 10000; |
| 5620 | for (j = 0; j < AB_NUM_WANDER_ROOMS; j++) { |
| 5621 | // Get room's position |
| 5622 | Room_Value(memory->wander_rooms[j], VF_GET, RMSV_V_PATH_PNT, &room_pos, 0); |
| 5623 | |
| 5624 | // Get the distance to this room |
| 5625 | dist = vm_VectorDistanceQuick(&my_pos, &room_pos); |
| 5626 | |
| 5627 | // See if this room is closer than the currently closest room |
| 5628 | if (dist < closest_dist) { |
| 5629 | closest_room = j; |
| 5630 | closest_dist = dist; |
| 5631 | } |
| 5632 | } |
| 5633 | |
| 5634 | mprintf(0, "Alien Boss - Determined closest wander room: %d\n", closest_room); |
| 5635 | |
| 5636 | return closest_room; |
| 5637 | } |
| 5638 | |
| 5639 | // Returns any current animations to alert |
| 5640 | void AlienBoss::AbortCurrentMode(int me) { |
| 5641 | switch (memory->mode) { |
| 5642 | case AB_HEALING: { |
| 5643 | // Stop the healing fog protection |
| 5644 | StopHealing(me); |
| 5645 | } break; |
| 5646 | |
| 5647 | case AB_LANDING_AT_NEST: { |
| 5648 | // Play the takeoff anim and tell it to go to alert next |
| 5649 | Obj_SetCustomAnim(me, AB_TAKEOFF_START_FRAME, AB_TAKEOFF_END_FRAME, AB_TAKEOFF_ANIM_TIME, AIAF_NOTIFY, -1, |
| 5650 | AS_ALERT); |
| 5651 | } break; |
| 5652 | |
| 5653 | case AB_SPECIAL_ATTACK: { |
| 5654 | // Play rest of attack animation and return to alert |
| 5655 | Obj_SetCustomAnim(me, AB_RECOIL_START_FRAME, AB_RECOIL_END_FRAME, AB_RECOIL_ANIM_TIME, AIAF_NOTIFY, -1, AS_ALERT); |
| 5656 | } break; |
| 5657 | } |
| 5658 | } |
| 5659 | |
| 5660 | // Handles the healing effects |
| 5661 | void AlienBoss::UpdateHealingEnergyBeams(int me) { |
| 5662 | // See if it's time to create the next energy effect |
| 5663 | if (memory->next_update_beam_time <= Game_GetTime()) { |
| 5664 | float next_duration = AB_BEAM_UPDATE_TIME; |
| 5665 | |
| 5666 | memory->next_update_beam_time = Game_GetTime() + next_duration; |
| 5667 | |
| 5668 | aLightningCreate(memory->tail_pos_handle, memory->nest_handle, next_duration, 1.0f, 2, boss_heal_effect_id, |
| 5669 | next_duration, 1, 255, 255, 255, false); |
| 5670 | |
| 5671 | // Create healing sparks |
| 5672 | int room; |
| 5673 | vector pos; |
| 5674 | Obj_Value(memory->tail_pos_handle, VF_GET, OBJV_I_ROOMNUM, &room); |
| 5675 | Obj_Value(memory->tail_pos_handle, VF_GET, OBJV_V_POS, &pos); |
| 5676 | Game_CreateRandomSparks(5, &pos, room); |
| 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | // Handles the healing effects |
| 5681 | void AlienBoss::UpdateDamageEffect(int me) { |
| 5682 | // See if it's time to create the next energy effect |
| 5683 | if (memory->next_damage_effect_time <= Game_GetTime()) { |
| 5684 | memory->next_damage_effect_time = Game_GetTime() + AB_DAMAGE_EFFECT_INTERVAL; |
| 5685 | |
| 5686 | float curr_damage; |
| 5687 | curr_damage = memory->damage; |
| 5688 | if (curr_damage > memory->damage_threshold) |
| 5689 | curr_damage = memory->damage_threshold; |
| 5690 | |
| 5691 | if (curr_damage > 0.0f && memory->damage_threshold != 0.0f) { |
| 5692 | float spark_rate; |
| 5693 | |
| 5694 | spark_rate = (curr_damage / memory->damage_threshold) * AB_MAX_DAMAGE_SPARK_RATE; |
| 5695 | aObjSpark(me, spark_rate, AB_DAMAGE_EFFECT_INTERVAL); |
| 5696 | } |
| 5697 | |
| 5698 | // do the following for debugging purposes |
| 5699 | // Obj_Create(OBJ_WEAPON, teleport_effect_id, memory->dest_room, &memory->dest_pos, NULL, me); |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | // Start healing fog protection |
| 5704 | void AlienBoss::StartHealing(int me) { |
| 5705 | // Set the green healing fog |
| 5706 | aRoomChangeFog(memory->wander_rooms[0], 0.0f, 1.0f, 0.0f, 800.0f, 2.0f); |
| 5707 | |
| 5708 | // Set the room damage |
| 5709 | aRoomSetDamage(memory->wander_rooms[0], 5.0f, 1); |
| 5710 | } |
| 5711 | |
| 5712 | // End healing fog protection |
| 5713 | void AlienBoss::StopHealing(int me) { |
| 5714 | // Set the green healing fog |
| 5715 | aRoomChangeFog(memory->wander_rooms[0], 0.0f, 1.0f, 0.0f, 9000.0f, 4.0f); |
| 5716 | |
| 5717 | // Set the room damage |
| 5718 | aRoomSetDamage(memory->wander_rooms[0], 0.0f, 1); |
| 5719 | } |
| 5720 | |
| 5721 | // Checks if the given mode should do stuck prevention |
| 5722 | bool AlienBoss::ModeIsStuckSensitive(int mode) { |
| 5723 | if (mode == AB_WANDERING || mode == AB_GOING_TO_NEST || mode == AB_LANDING_AT_NEST || |
| 5724 | mode == AB_GOING_TO_PROTECT_NEST) { |
| 5725 | return true; |
| 5726 | } |
| 5727 | |
| 5728 | return false; |
| 5729 | } |
| 5730 | |
| 5731 | // Sets the Current Mode |
| 5732 | void AlienBoss::SetMode(int me, char mode) { |
| 5733 | mprintf(0, "From mode %d, ", memory->mode); |
| 5734 | |
| 5735 | int flags; |
| 5736 | char movement_type; |
| 5737 | vector vel; |
| 5738 | |
| 5739 | // Clear out any goals |
| 5740 | AI_SafeSetType(me, AIT_AIS); |
| 5741 | |
| 5742 | // Set normal FOV to 360 |
| 5743 | float fov = -1.0f; |
| 5744 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 5745 | |
| 5746 | // Turn off ranged firing |
| 5747 | flags = AIF_DISABLE_FIRING; |
| 5748 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5749 | |
| 5750 | // Turn off melee attacks |
| 5751 | flags = AIF_MELEE1 | AIF_MELEE2; |
| 5752 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5753 | |
| 5754 | // Make it always aware |
| 5755 | flags = AIF_FORCE_AWARENESS; |
| 5756 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5757 | |
| 5758 | // Do mode specific setups |
| 5759 | switch (mode) { |
| 5760 | case AB_GOING_TO_NEST: { |
| 5761 | mprintf(0, "Going to Nest mode set.\n"); |
| 5762 | |
| 5763 | ray_info ray; |
| 5764 | int fate; |
| 5765 | vector end_pos, landing_pos; |
| 5766 | int end_room, landing_room; |
| 5767 | |
| 5768 | // If currently landed, set take off velocity |
| 5769 | DoTakeoff(me, 8.0f, 3.0f); |
| 5770 | |
| 5771 | // Set movement type back to physics for flying around |
| 5772 | movement_type = MT_PHYSICS; |
| 5773 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 5774 | |
| 5775 | // Calculate destination home point a int16_t distance from actual landing point |
| 5776 | end_pos = memory->home_pos + (memory->home_uvec * 20.0f); |
| 5777 | |
| 5778 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 5779 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 5780 | fate = FVI_RayCast(me, &memory->home_pos, &end_pos, memory->home_room, 0.0f, flags, &ray); |
| 5781 | |
| 5782 | landing_pos = ray.hit_point; |
| 5783 | landing_room = ray.hit_room; |
| 5784 | |
| 5785 | // Set goal to head home |
| 5786 | AI_AddGoal(me, AIG_GET_TO_POS, 2, 1.0f, AB_GUID_GOT_TO_NEST, GF_ORIENT_VELOCITY, &landing_pos, landing_room); |
| 5787 | AI_SetGoalCircleDist(me, 2, 2.0f); |
| 5788 | |
| 5789 | // Save values for teleport |
| 5790 | memory->dest_pos = landing_pos; |
| 5791 | memory->dest_room = landing_room; |
| 5792 | |
| 5793 | // Set returning home speed |
| 5794 | SetMaxSpeed(me, memory->base_speed * AB_RETURN_SPEED_MOD); |
| 5795 | |
| 5796 | // Clear the next activity time |
| 5797 | memory->next_activity_time = 0.0f; |
| 5798 | |
| 5799 | // Clear the next wander time |
| 5800 | memory->max_wander_time = 0.0f; |
| 5801 | } break; |
| 5802 | |
| 5803 | case AB_LANDING_AT_NEST: { |
| 5804 | mprintf(0, "Landing at Nest mode set.\n"); |
| 5805 | |
| 5806 | // If currently landed, set take off velocity |
| 5807 | DoTakeoff(me, 8.0f, 3.0f); |
| 5808 | |
| 5809 | // Turn off dodging |
| 5810 | flags = AIF_DODGE; |
| 5811 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5812 | |
| 5813 | // Turn on point-collide-walls and lock axes |
| 5814 | flags = PF_POINT_COLLIDE_WALLS | PF_LOCK_MASK; |
| 5815 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 5816 | |
| 5817 | // Turn off auto-level |
| 5818 | flags = PF_LEVELING; |
| 5819 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 5820 | |
| 5821 | // Set movement type back to physics for flying around |
| 5822 | movement_type = MT_PHYSICS; |
| 5823 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 5824 | |
| 5825 | // Make him land at his home point |
| 5826 | AI_AddGoal(me, AIG_GET_TO_POS, 2, 100.0f, AB_GUID_LANDED, |
| 5827 | GF_NONFLUSHABLE | GF_KEEP_AT_COMPLETION | GF_ORIENT_SCRIPTED, &memory->home_pos, memory->home_room); |
| 5828 | AI_SetGoalCircleDist(me, 2, 0.0f); |
| 5829 | |
| 5830 | // Save values for teleport |
| 5831 | memory->dest_pos = memory->home_pos; |
| 5832 | memory->dest_room = memory->home_room; |
| 5833 | |
| 5834 | // Play his landing animation |
| 5835 | Obj_SetCustomAnim(me, AB_LANDING_START_FRAME, AB_LANDING_END_FRAME, AB_LANDING_ANIM_TIME, 0, -1, -1); |
| 5836 | |
| 5837 | // Set landing speed |
| 5838 | SetMaxSpeed(me, memory->base_speed * AB_LAND_SPEED_MOD); |
| 5839 | |
| 5840 | // Clear the next activity time |
| 5841 | memory->next_activity_time = 0.0f; |
| 5842 | |
| 5843 | // Clear the next wander time |
| 5844 | memory->max_wander_time = 0.0f; |
| 5845 | } break; |
| 5846 | |
| 5847 | case AB_HEALING: { |
| 5848 | mprintf(0, "Healing mode set.\n"); |
| 5849 | |
| 5850 | // Turn off dodging |
| 5851 | flags = AIF_DODGE; |
| 5852 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5853 | |
| 5854 | // Turn off auto-level |
| 5855 | flags = PF_LEVELING; |
| 5856 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 5857 | |
| 5858 | // Turn on point-collide-walls and lock axes |
| 5859 | flags = PF_POINT_COLLIDE_WALLS | PF_LOCK_MASK; |
| 5860 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 5861 | |
| 5862 | // No movement allowed |
| 5863 | movement_type = MT_NONE; |
| 5864 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 5865 | |
| 5866 | // Play his landing animation |
| 5867 | Obj_SetCustomAnim(me, AB_HEALING_START_FRAME, AB_HEALING_END_FRAME, AB_HEALING_ANIM_TIME, AIAF_LOOPING, -1, -1); |
| 5868 | |
| 5869 | // Set landed speed |
| 5870 | SetMaxSpeed(me, 0.0f); |
| 5871 | |
| 5872 | // Set the next activity time |
| 5873 | memory->next_activity_time = Game_GetTime() + ALIEN_LANDED_ACTION_TIME; |
| 5874 | |
| 5875 | // Start healing protection |
| 5876 | StartHealing(me); |
| 5877 | } break; |
| 5878 | |
| 5879 | case AB_WAITING: { |
| 5880 | mprintf(0, "Waiting mode set.\n"); |
| 5881 | |
| 5882 | // Turn off dodging |
| 5883 | flags = AIF_DODGE; |
| 5884 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5885 | |
| 5886 | // Turn off auto-level |
| 5887 | flags = PF_LEVELING; |
| 5888 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 5889 | |
| 5890 | // Turn on point-collide-walls and lock axes |
| 5891 | flags = PF_POINT_COLLIDE_WALLS | PF_LOCK_MASK; |
| 5892 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 5893 | |
| 5894 | // No movement allowed |
| 5895 | movement_type = MT_NONE; |
| 5896 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 5897 | |
| 5898 | // Play his landing animation |
| 5899 | Obj_SetCustomAnim(me, AB_HEALING_START_FRAME, AB_HEALING_END_FRAME, AB_HEALING_ANIM_TIME, AIAF_LOOPING, -1, -1); |
| 5900 | |
| 5901 | // Set landed speed |
| 5902 | SetMaxSpeed(me, 0.0f); |
| 5903 | } break; |
| 5904 | |
| 5905 | case AB_WANDERING: { |
| 5906 | mprintf(0, "Wandering mode set.\n"); |
| 5907 | |
| 5908 | // If currently landed, set take off velocity |
| 5909 | DoTakeoff(me, 8.0f, 3.0f); |
| 5910 | |
| 5911 | // Set movement type back to physics for flying around |
| 5912 | movement_type = MT_PHYSICS; |
| 5913 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 5914 | |
| 5915 | // Get Closest wander room |
| 5916 | memory->curr_wander_room_index = DetermineClosestRoom(me); |
| 5917 | SetWanderRoomGoal(me); |
| 5918 | |
| 5919 | // Set wander speed |
| 5920 | if (memory->intro_ended) { |
| 5921 | SetMaxSpeed(me, memory->base_speed * AB_WANDER_SPEED_MOD); |
| 5922 | } else { |
| 5923 | // wander at fixed speed for the intro |
| 5924 | SetMaxSpeed(me, 30.0f); |
| 5925 | } |
| 5926 | |
| 5927 | // Set the next activity check to happen within .4 to .8 seconds |
| 5928 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 3.0f + 3.0f; |
| 5929 | } break; |
| 5930 | |
| 5931 | case AB_ATTACKING: { |
| 5932 | mprintf(0, "Attacking mode set.\n"); |
| 5933 | |
| 5934 | // If currently landed, set take off velocity |
| 5935 | DoTakeoff(me, 8.0f, 3.0f); |
| 5936 | |
| 5937 | // Set attack FOV to 360 |
| 5938 | float fov = -1.0f; |
| 5939 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 5940 | |
| 5941 | // Set movement type back to physics for flying around |
| 5942 | movement_type = MT_PHYSICS; |
| 5943 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 5944 | |
| 5945 | // Only set goals if not currently in squad formation |
| 5946 | AI_SafeSetType(me, AIT_EVADER1); |
| 5947 | |
| 5948 | // Turn on ranged firing |
| 5949 | flags = AIF_DISABLE_FIRING; |
| 5950 | AI_Value(me, VF_CLEAR_FLAGS, AIV_I_FLAGS, &flags); |
| 5951 | |
| 5952 | // Turn on melee attacks |
| 5953 | flags = AIF_MELEE1 | AIF_MELEE2; |
| 5954 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5955 | |
| 5956 | // Set Engage and Attack Speeds |
| 5957 | SetMaxSpeed(me, memory->base_speed * AB_ATTACK_SPEED_MOD); |
| 5958 | |
| 5959 | // Set the next activity time |
| 5960 | memory->next_activity_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f; |
| 5961 | |
| 5962 | // Clear the next wander time |
| 5963 | memory->max_wander_time = 0.0f; |
| 5964 | } break; |
| 5965 | |
| 5966 | case AB_MELEE_ATTACK: { |
| 5967 | mprintf(0, "Melee Attack mode set.\n"); |
| 5968 | |
| 5969 | // Set attack FOV to 360 |
| 5970 | float fov = -1.0f; |
| 5971 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 5972 | |
| 5973 | // Turn on melee attacks |
| 5974 | flags = AIF_MELEE1 | AIF_MELEE2; |
| 5975 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 5976 | |
| 5977 | // Only set goals if not currently in squad formation |
| 5978 | AI_SafeSetType(me, AIT_MELEE1); |
| 5979 | |
| 5980 | // Set Engage and Attack Speeds |
| 5981 | SetMaxSpeed(me, memory->base_speed * AB_MELEE_ATTACK_SPEED_MOD); |
| 5982 | } break; |
| 5983 | |
| 5984 | case AB_PREPARE_SPECIAL_ATTACK: { |
| 5985 | mprintf(0, "Prepare Special Attack mode set.\n"); |
| 5986 | |
| 5987 | // Set attack FOV to 360 |
| 5988 | float fov = -1.0f; |
| 5989 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 5990 | |
| 5991 | // Only set goals if not currently in squad formation |
| 5992 | AI_SafeSetType(me, AIT_EVADER1); |
| 5993 | |
| 5994 | // Set Engage and Attack Speeds |
| 5995 | SetMaxSpeed(me, memory->base_speed * AB_SPEC_ATTACK_SPEED_MOD); |
| 5996 | } break; |
| 5997 | |
| 5998 | case AB_SPECIAL_ATTACK: { |
| 5999 | mprintf(0, "Special Attack mode set.\n"); |
| 6000 | |
| 6001 | // Set attack FOV to 360 |
| 6002 | float fov = -1.0f; |
| 6003 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 6004 | |
| 6005 | // Only set goals if not currently in squad formation |
| 6006 | AI_SafeSetType(me, AIT_EVADER1); |
| 6007 | |
| 6008 | // Play special attack animation |
| 6009 | Obj_SetCustomAnim(me, AB_ATTACK_START_FRAME, AB_ATTACK_END_FRAME, AB_ATTACK_ANIM_TIME, 0, -1, -1); |
| 6010 | |
| 6011 | // Set Engage and Attack Speeds |
| 6012 | SetMaxSpeed(me, memory->base_speed * AB_SPEC_ATTACK_SPEED_MOD); |
| 6013 | } break; |
| 6014 | |
| 6015 | case AB_SPECIAL_ATTACK_RECOIL: { |
| 6016 | mprintf(0, "Special Attack Recoil mode set.\n"); |
| 6017 | |
| 6018 | // Set attack FOV to 360 |
| 6019 | float fov = -1.0f; |
| 6020 | AI_Value(me, VF_SET, AIV_F_FOV, &fov); |
| 6021 | |
| 6022 | // Only set goals if not currently in squad formation |
| 6023 | AI_SafeSetType(me, AIT_EVADER1); |
| 6024 | |
| 6025 | // Play special attack animation |
| 6026 | Obj_SetCustomAnim(me, AB_RECOIL_START_FRAME, AB_RECOIL_END_FRAME, AB_RECOIL_ANIM_TIME, AIAF_NOTIFY, -1, AS_ALERT); |
| 6027 | |
| 6028 | // Set Engage and Attack Speeds |
| 6029 | SetMaxSpeed(me, memory->base_speed * AB_SPEC_ATTACK_SPEED_MOD); |
| 6030 | } break; |
| 6031 | |
| 6032 | case AB_FLEEING: { |
| 6033 | mprintf(0, "Fleeing mode set.\n"); |
| 6034 | |
| 6035 | // If currently landed, set take off velocity |
| 6036 | DoTakeoff(me, 8.0f, 3.0f); |
| 6037 | |
| 6038 | // Set movement type back to physics for flying around |
| 6039 | movement_type = MT_PHYSICS; |
| 6040 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 6041 | |
| 6042 | // Set Goal to go somewhere else |
| 6043 | SetWanderGoal(me); |
| 6044 | |
| 6045 | // Set Fleeing Speed |
| 6046 | SetMaxSpeed(me, memory->base_speed * AB_FLEE_SPEED_MOD); |
| 6047 | |
| 6048 | // Set the max time to flee (base time somewhat off of damage) |
| 6049 | float time_percent = (float(memory->fire_flee_chance) / 100.0f); |
| 6050 | memory->max_wander_time = ((float)rand() / (float)D3_RAND_MAX) * 2.0f + AB_MAX_FLEE_TIME * time_percent; |
| 6051 | |
| 6052 | // Decrease the flee chance for next time |
| 6053 | memory->fire_flee_chance -= AB_FLEE_CHANCE_DECREMENT; |
| 6054 | if (memory->fire_flee_chance < 0.0f) |
| 6055 | memory->fire_flee_chance = 0.0f; |
| 6056 | } break; |
| 6057 | |
| 6058 | case AB_HIDING_FROM_THRUSTER: { |
| 6059 | mprintf(0, "Hiding from Thruster mode set.\n"); |
| 6060 | |
| 6061 | // Abort whatever mode we are in |
| 6062 | AbortCurrentMode(me); |
| 6063 | |
| 6064 | // If currently landed, set take off velocity |
| 6065 | DoTakeoff(me, 8.0f, 3.0f); |
| 6066 | |
| 6067 | // Set movement type back to physics for flying around |
| 6068 | movement_type = MT_PHYSICS; |
| 6069 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 6070 | |
| 6071 | // Determine closest hide room and go to it |
| 6072 | SetHideRoomGoal(me); |
| 6073 | |
| 6074 | // Set returning home speed |
| 6075 | SetMaxSpeed(me, memory->base_speed * AB_RETURN_SPEED_MOD); |
| 6076 | |
| 6077 | } break; |
| 6078 | |
| 6079 | case AB_GOING_TO_PROTECT_NEST: { |
| 6080 | mprintf(0, "Going to Protect Nest mode set.\n"); |
| 6081 | |
| 6082 | // Abort whatever mode we are in |
| 6083 | AbortCurrentMode(me); |
| 6084 | |
| 6085 | // Set to protective state |
| 6086 | memory->state = AB_PROTECTIVE; |
| 6087 | |
| 6088 | // Set the new damage level |
| 6089 | memory->damage_threshold = AB_PROTECTIVE_DAMAGE_LEVEL * memory->base_shields; |
| 6090 | |
| 6091 | // If currently landed, set take off velocity |
| 6092 | DoTakeoff(me, 8.0f, 3.0f); |
| 6093 | |
| 6094 | // Set movement type back to physics for flying around |
| 6095 | movement_type = MT_PHYSICS; |
| 6096 | Obj_Value(me, VF_SET, OBJV_C_MOVEMENT_TYPE, &movement_type); |
| 6097 | |
| 6098 | // Return to nest room |
| 6099 | SetProtectNestGoal(me); |
| 6100 | |
| 6101 | // Set returning home speed |
| 6102 | SetMaxSpeed(me, memory->base_speed * AB_RETURN_SPEED_MOD); |
| 6103 | } break; |
| 6104 | |
| 6105 | case AB_DYING: { |
| 6106 | mprintf(0, "Dying mode set.\n"); |
| 6107 | |
| 6108 | // Set Engage and Attack Speeds |
| 6109 | SetMaxSpeed(me, memory->base_speed); |
| 6110 | |
| 6111 | // Stop the healing room effects |
| 6112 | aRoomChangeFog(memory->wander_rooms[0], 0.0f, 1.0f, 0.0f, 9000.0f, 6.0f); |
| 6113 | |
| 6114 | // Set the room damage |
| 6115 | aRoomSetDamage(memory->wander_rooms[0], 0.0f, 1); |
| 6116 | } break; |
| 6117 | |
| 6118 | case AB_TELEPORTING: { |
| 6119 | mprintf(0, "Teleporting mode set.\n"); |
| 6120 | |
| 6121 | // Start cloaking |
| 6122 | aCloakObject(me, 0.0f); |
| 6123 | |
| 6124 | // Save current mode so we can return to it once teleport is done |
| 6125 | memory->mode_prior_teleporting = memory->mode; |
| 6126 | |
| 6127 | // set transfer flag |
| 6128 | memory->did_transfer = false; |
| 6129 | } break; |
| 6130 | |
| 6131 | default: |
| 6132 | mprintf(0, "Alien Boss is all messed up!\n"); |
| 6133 | } |
| 6134 | |
| 6135 | // Reset the landing flags |
| 6136 | memory->done_moving = false; |
| 6137 | memory->done_turning = false; |
| 6138 | |
| 6139 | // Set the current mode and reset the mode time |
| 6140 | memory->mode = mode; |
| 6141 | memory->mode_time = 0.0f; |
| 6142 | |
| 6143 | // If we just switched to a stuck sensitive mode, clear out the values |
| 6144 | if (ModeIsStuckSensitive(memory->mode)) { |
| 6145 | memory->next_check_if_stuck_time = Game_GetTime() + AB_CHECK_IF_STUCK_INTERVAL; |
| 6146 | memory->squared_dist_moved = 0.0f; |
| 6147 | Obj_Value(me, VF_GET, OBJV_V_POS, &memory->last_pos); |
| 6148 | } |
| 6149 | } |
| 6150 | |
| 6151 | // Handles alien takeoffs |
| 6152 | void AlienBoss::DoTakeoff(int me, float takeoff_speed, float speed_variance) { |
| 6153 | // If currently landed, set take off velocity |
| 6154 | if (memory->mode == AB_HEALING || memory->mode == AB_WAITING) { |
| 6155 | vector vel; |
| 6156 | int flags; |
| 6157 | |
| 6158 | Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &vel); |
| 6159 | vel += (memory->home_uvec * (takeoff_speed + ((float)rand() / (float)D3_RAND_MAX) * speed_variance)); |
| 6160 | Obj_Value(me, VF_SET, OBJV_V_VELOCITY, &vel); |
| 6161 | |
| 6162 | // Play the takeoff anim and tell it to go to alert next |
| 6163 | Obj_SetCustomAnim(me, AB_TAKEOFF_START_FRAME, AB_TAKEOFF_END_FRAME, AB_TAKEOFF_ANIM_TIME, AIAF_NOTIFY, -1, |
| 6164 | AS_ALERT); |
| 6165 | |
| 6166 | // Clear wall point collision and axes lock |
| 6167 | flags = PF_LOCK_MASK | PF_POINT_COLLIDE_WALLS; |
| 6168 | Obj_Value(me, VF_CLEAR_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 6169 | |
| 6170 | // Turn on dodging |
| 6171 | flags = AIF_DODGE; |
| 6172 | AI_Value(me, VF_SET_FLAGS, AIV_I_FLAGS, &flags); |
| 6173 | |
| 6174 | // enable auto-leveling |
| 6175 | flags = PF_LEVELING; |
| 6176 | Obj_Value(me, VF_SET_FLAGS, OBJV_I_PHYSICS_FLAGS, &flags); |
| 6177 | } |
| 6178 | } |
| 6179 | |
| 6180 | // Processes the AI Initialize event |
| 6181 | void AlienBoss::DoInit(int me) { |
| 6182 | int flags; |
| 6183 | msafe_struct m; |
| 6184 | m.objhandle = me; |
| 6185 | |
| 6186 | // Setup memory data |
| 6187 | tOSIRISMEMCHUNK ch; |
| 6188 | ch.id = ALIEN_MEMORY_ID; |
| 6189 | ch.size = sizeof(alienboss_data); |
| 6190 | ch.my_id.type = OBJECT_SCRIPT; |
| 6191 | ch.my_id.objhandle = me; |
| 6192 | |
| 6193 | memory = (alienboss_data *)Scrpt_MemAlloc(&ch); |
| 6194 | |
| 6195 | // Init base values |
| 6196 | AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed); |
| 6197 | Obj_Value(me, VF_GET, OBJV_F_SHIELDS, &memory->base_shields); |
| 6198 | |
| 6199 | // Clear the destination object handle |
| 6200 | memory->dest_object_handle = OBJECT_HANDLE_NONE; |
| 6201 | |
| 6202 | // Alien hasn't been hit by player yet |
| 6203 | memory->hit_by_player = false; |
| 6204 | memory->damage = 0.0f; |
| 6205 | memory->damage_threshold = AB_NORMAL_DAMAGE_LEVEL * memory->base_shields; |
| 6206 | memory->fire_flee_chance = AB_STARTING_FLEE_CHANCE; |
| 6207 | |
| 6208 | memory->curr_wander_room_index = 0; |
| 6209 | memory->wander_forward = true; |
| 6210 | memory->protected_nest = false; |
| 6211 | memory->waiting_effect_enabled = false; |
| 6212 | memory->intro_ended = false; |
| 6213 | |
| 6214 | // Update the energy effect as soon as charge exists |
| 6215 | memory->next_update_beam_time = Game_GetTime(); |
| 6216 | |
| 6217 | // Do special damage as soon as relevant |
| 6218 | memory->next_special_damage_time = Game_GetTime(); |
| 6219 | memory->next_damage_effect_time = Game_GetTime(); |
| 6220 | |
| 6221 | // Do special attack as soon as relevant |
| 6222 | memory->next_special_attack_time = Game_GetTime(); |
| 6223 | memory->next_melee_attack_time = Game_GetTime(); |
| 6224 | |
| 6225 | // Set the next generic check time |
| 6226 | memory->next_generic_check_time = Game_GetTime() + ((float)rand() / (float)D3_RAND_MAX) * 1.0f + 0.5f; |
| 6227 | |
| 6228 | // Init other times |
| 6229 | memory->next_activity_time = Game_GetTime(); |
| 6230 | memory->max_wander_time = 0.0f; |
| 6231 | |
| 6232 | // Store Home Information |
| 6233 | Obj_Value(me, VF_GET, OBJV_V_POS, &memory->home_pos); |
| 6234 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &memory->home_room); |
| 6235 | |
| 6236 | matrix orient; |
| 6237 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 6238 | memory->home_fvec = orient.fvec; |
| 6239 | vm_VectorNormalize(&memory->home_fvec); |
| 6240 | memory->home_uvec = orient.uvec; |
| 6241 | vm_VectorNormalize(&memory->home_uvec); |
| 6242 | |
| 6243 | // Save values for teleport |
| 6244 | memory->dest_pos = memory->home_pos; |
| 6245 | memory->dest_room = memory->home_room; |
| 6246 | |
| 6247 | // stuck check stuff |
| 6248 | memory->squared_dist_moved = 0.0f; |
| 6249 | memory->next_check_if_stuck_time = Game_GetTime(); |
| 6250 | memory->last_pos = memory->home_pos; |
| 6251 | |
| 6252 | // Init the props |
| 6253 | memory->pos1_handle = OBJECT_HANDLE_NONE; |
| 6254 | memory->pos2_handle = OBJECT_HANDLE_NONE; |
| 6255 | memory->pos3_handle = OBJECT_HANDLE_NONE; |
| 6256 | |
| 6257 | // Create and setup the energy effect props |
| 6258 | msafe_struct mstruct; |
| 6259 | memory->tail_pos_handle = CreateAndAttach(me, "STEmitter", OBJ_ROBOT, 0, 0, true, true); |
| 6260 | mstruct.objhandle = memory->tail_pos_handle; |
| 6261 | MSafe_CallFunction(MSAFE_OBJECT_NO_RENDER, &mstruct); |
| 6262 | |
| 6263 | // Init the scenario ID's |
| 6264 | memory->nest_handle = OBJECT_HANDLE_NONE; |
| 6265 | memory->left_hide_room = -1; |
| 6266 | memory->right_hide_room = -1; |
| 6267 | |
| 6268 | // Do Lookups |
| 6269 | DoCustomLookups(); |
| 6270 | |
| 6271 | // Set the healing fog in room |
| 6272 | aRoomSetFog(memory->wander_rooms[0], 0.0f, 1.0f, 0.0f, 9000.0f); |
| 6273 | |
| 6274 | // Set to normal state |
| 6275 | memory->state = AB_NORMAL; |
| 6276 | |
| 6277 | // Set starting mode |
| 6278 | // SetMode(me, AB_GOING_TO_NEST); // for debugging |
| 6279 | SetMode(me, AB_WAITING); |
| 6280 | |
| 6281 | // Play looping boss sound |
| 6282 | aSoundPlayObject(boss_flapping_id, me, 1.0f); |
| 6283 | |
| 6284 | mprintf(0, "Alien boss initialized.\n"); |
| 6285 | } |
| 6286 | |
| 6287 | // Does custom name lookups |
| 6288 | void AlienBoss::DoCustomLookups(void) { |
| 6289 | int j; |
| 6290 | |
| 6291 | // Lookup the wander room names |
| 6292 | for (j = 0; j < AB_NUM_WANDER_ROOMS; j++) { |
| 6293 | memory->wander_rooms[j] = Scrpt_FindRoomName(AB_WanderRoomNames[j]); |
| 6294 | |
| 6295 | if (memory->wander_rooms[j] < 0) |
| 6296 | mprintf(0, "Alien Boss Error: Room not found - %s", AB_WanderRoomNames[j]); |
| 6297 | } |
| 6298 | } |
| 6299 | |
| 6300 | // Checks to see if tractor beam pulling can commence/continue |
| 6301 | bool AlienBoss::OkToStartSpecialAttack(int me) { |
| 6302 | matrix orient; |
| 6303 | vector vec_to_target; |
| 6304 | int target_handle; |
| 6305 | float fov_angle; |
| 6306 | |
| 6307 | // Make sure we still have a target |
| 6308 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 6309 | if (target_handle == OBJECT_HANDLE_NONE) |
| 6310 | return false; |
| 6311 | |
| 6312 | // Make sure the target isn't cloaked |
| 6313 | if (qObjectCloakTime(target_handle) != 0.0f) |
| 6314 | return false; |
| 6315 | |
| 6316 | // check distance to target |
| 6317 | float dist; |
| 6318 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 6319 | if (dist > AB_MAX_SPECIAL_ATTACK_DIST) |
| 6320 | return false; |
| 6321 | |
| 6322 | // check FOV position of target (greater than 45 degrees is too much) |
| 6323 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 6324 | |
| 6325 | // NOTE: do my own vec to target here! (chris' doesn't update quick enough) |
| 6326 | AI_Value(me, VF_GET, AIV_V_VEC_TO_TARGET, &vec_to_target); |
| 6327 | vm_VectorNormalize(&vec_to_target); |
| 6328 | fov_angle = orient.fvec * vec_to_target; |
| 6329 | if (fov_angle < 0.7f) |
| 6330 | return false; |
| 6331 | |
| 6332 | return true; |
| 6333 | } |
| 6334 | |
| 6335 | // Checks to see if tractor beam pulling can commence/continue |
| 6336 | bool AlienBoss::DoStingAttack(int me) { |
| 6337 | matrix orient; |
| 6338 | vector vec_to_target; |
| 6339 | int target_handle; |
| 6340 | float fov_angle; |
| 6341 | |
| 6342 | // Make sure we still have a target |
| 6343 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 6344 | if (target_handle == OBJECT_HANDLE_NONE) |
| 6345 | return false; |
| 6346 | |
| 6347 | // check distance to target |
| 6348 | float dist; |
| 6349 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 6350 | if (dist > AB_MAX_STING_DIST) |
| 6351 | return false; |
| 6352 | |
| 6353 | // check FOV position of target (greater than 45 degrees is too much) |
| 6354 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 6355 | |
| 6356 | // NOTE: do my own vec to target here! (chris' doesn't update quick enough) |
| 6357 | AI_Value(me, VF_GET, AIV_V_VEC_TO_TARGET, &vec_to_target); |
| 6358 | vm_VectorNormalize(&vec_to_target); |
| 6359 | fov_angle = orient.fvec * vec_to_target; |
| 6360 | if (fov_angle < 0.7f) |
| 6361 | return false; |
| 6362 | |
| 6363 | // see if anything is in the way |
| 6364 | ray_info ray; |
| 6365 | int flags, fate; |
| 6366 | vector start_pos, end_pos, landing_pos; |
| 6367 | int start_room, landing_room; |
| 6368 | float target_size; |
| 6369 | |
| 6370 | Obj_Value(me, VF_GET, OBJV_V_POS, &start_pos); |
| 6371 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &start_room); |
| 6372 | Obj_Value(target_handle, VF_GET, OBJV_V_POS, &end_pos); |
| 6373 | Obj_Value(target_handle, VF_GET, OBJV_F_SIZE, &target_size); |
| 6374 | |
| 6375 | flags = FQ_CHECK_OBJS | FQ_IGNORE_POWERUPS | FQ_IGNORE_WEAPONS | FQ_IGNORE_MOVING_OBJECTS | |
| 6376 | FQ_IGNORE_NON_LIGHTMAP_OBJECTS; |
| 6377 | fate = FVI_RayCast(me, &start_pos, &end_pos, start_room, target_size, flags, &ray); |
| 6378 | if (fate != HIT_NONE) |
| 6379 | return false; |
| 6380 | |
| 6381 | // Create the lightning effect for the sting attack |
| 6382 | aLightningCreate(target_handle, memory->tail_pos_handle, 0.4f, 1.0f, 3, transfer_effect_id, 0.4f, 1, 255, 255, 255, |
| 6383 | false); |
| 6384 | |
| 6385 | // Damage the target |
| 6386 | aObjApplyDamage(target_handle, AB_STING_DAMAGE); |
| 6387 | |
| 6388 | // Play damaged sound for target |
| 6389 | |
| 6390 | mprintf(0, "Did sting attack.\n"); |
| 6391 | |
| 6392 | return true; |
| 6393 | } |
| 6394 | |
| 6395 | // Processes the AI Frame Interval Event |
| 6396 | void AlienBoss::DoFrame(int me) { |
| 6397 | int flags; |
| 6398 | float anim_frame; |
| 6399 | float last_see_time, last_see_game_time; |
| 6400 | float last_hear_time, last_hear_game_time; |
| 6401 | float last_perceive_time; |
| 6402 | |
| 6403 | // If we're waiting, bail outta here |
| 6404 | if (memory->mode == AB_WAITING) { |
| 6405 | // display healing effects for intro |
| 6406 | if (memory->waiting_effect_enabled) { |
| 6407 | // Handle the healing energy beam effects |
| 6408 | UpdateHealingEnergyBeams(me); |
| 6409 | } |
| 6410 | return; |
| 6411 | } |
| 6412 | |
| 6413 | // Get the last see and hear time |
| 6414 | AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 6415 | AI_Value(me, VF_GET, AIV_F_LAST_HEAR_TARGET_TIME, &last_hear_game_time); |
| 6416 | |
| 6417 | // Calculate the time since target was seen and heard |
| 6418 | last_hear_time = Game_GetTime() - last_hear_game_time; |
| 6419 | last_see_time = Game_GetTime() - last_see_game_time; |
| 6420 | |
| 6421 | // Perceive time is last time target was seen or heard (whichever is smalled) |
| 6422 | if (last_hear_time <= last_see_time) { |
| 6423 | last_perceive_time = last_hear_time; |
| 6424 | } else { |
| 6425 | last_perceive_time = last_see_time; |
| 6426 | } |
| 6427 | |
| 6428 | // If alien boss was hit by player, take action if necessary |
| 6429 | if (memory->hit_by_player) { |
| 6430 | // reset the hit by player flag |
| 6431 | memory->hit_by_player = false; |
| 6432 | } |
| 6433 | |
| 6434 | // Get the current animation frame |
| 6435 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &anim_frame); |
| 6436 | |
| 6437 | // Handle generic checks (pertains to more than 1 mode) |
| 6438 | if (memory->next_generic_check_time <= Game_GetTime()) { |
| 6439 | } |
| 6440 | |
| 6441 | // Handle mode specific operations |
| 6442 | switch (memory->mode) { |
| 6443 | |
| 6444 | case AB_HEALING: { |
| 6445 | // See if we should do a round of healing |
| 6446 | if (Game_GetTime() >= memory->next_activity_time) { |
| 6447 | // Set the next time to do something |
| 6448 | memory->next_activity_time = Game_GetTime() + AB_HEALING_ACTION_TIME; |
| 6449 | |
| 6450 | // Heal Some Damage |
| 6451 | float heal_amount = memory->base_shields * AB_HEAL_AMOUNT_PERCENT; |
| 6452 | memory->damage -= heal_amount; |
| 6453 | |
| 6454 | mprintf(0, "Healing %.1f by %.1f...\n", memory->damage, heal_amount); |
| 6455 | |
| 6456 | bool done_healing = false; |
| 6457 | if (memory->damage <= 0.0f) { |
| 6458 | memory->damage = 0.0f; |
| 6459 | done_healing = true; |
| 6460 | } |
| 6461 | |
| 6462 | // If we're all healed up, return to attack mode |
| 6463 | if (done_healing) { |
| 6464 | StopHealing(me); |
| 6465 | |
| 6466 | SetMode(me, AB_ATTACKING); |
| 6467 | break; |
| 6468 | } |
| 6469 | } |
| 6470 | |
| 6471 | // Handle the healing energy beam effects |
| 6472 | UpdateHealingEnergyBeams(me); |
| 6473 | } break; |
| 6474 | |
| 6475 | case AB_DYING: { |
| 6476 | // Allow the healing effects to play for a few seconds |
| 6477 | if (memory->mode_time < 4.5f) { |
| 6478 | UpdateHealingEnergyBeams(me); |
| 6479 | } |
| 6480 | } break; |
| 6481 | |
| 6482 | case AB_HIDING_FROM_THRUSTER: { |
| 6483 | // Don't hide for more than a few seconds at most |
| 6484 | if (memory->mode_time > 6.0f) { |
| 6485 | SetMode(me, AB_ATTACKING); |
| 6486 | break; |
| 6487 | } |
| 6488 | } break; |
| 6489 | |
| 6490 | case AB_GOING_TO_PROTECT_NEST: { |
| 6491 | // If we've seen a target, switch into attack mode |
| 6492 | if (memory->protected_nest && last_perceive_time <= 2.0f) { |
| 6493 | SetMode(me, AB_ATTACKING); |
| 6494 | break; |
| 6495 | } |
| 6496 | } break; |
| 6497 | |
| 6498 | case AB_TELEPORTING: { |
| 6499 | if (memory->mode_time > 2.0f) { |
| 6500 | // Set to previous mode |
| 6501 | SetMode(me, memory->mode_prior_teleporting); |
| 6502 | break; |
| 6503 | } else if (!memory->did_transfer && memory->mode_time > 1.0f) { |
| 6504 | vector pos; |
| 6505 | int room; |
| 6506 | |
| 6507 | // Do effect before |
| 6508 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 6509 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6510 | Obj_Create(OBJ_WEAPON, teleport_effect_id, room, &pos, NULL, me); |
| 6511 | |
| 6512 | // Move self |
| 6513 | Obj_Value(me, VF_SET, OBJV_V_POS, &memory->dest_pos); |
| 6514 | Obj_Value(me, VF_SET, OBJV_I_ROOMNUM, &memory->dest_room); |
| 6515 | |
| 6516 | // Do effect after |
| 6517 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 6518 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6519 | Obj_Create(OBJ_WEAPON, teleport_effect_id, room, &pos, NULL, me); |
| 6520 | |
| 6521 | memory->did_transfer = true; |
| 6522 | } |
| 6523 | } break; |
| 6524 | |
| 6525 | case AB_LANDING_AT_NEST: { |
| 6526 | // Play his landed animation if done with landing anim |
| 6527 | if (anim_frame == AB_LANDING_END_FRAME) { |
| 6528 | Obj_SetCustomAnim(me, AB_HEALING_START_FRAME, AB_HEALING_END_FRAME, AB_HEALING_ANIM_TIME, AIAF_LOOPING, -1, -1); |
| 6529 | } |
| 6530 | |
| 6531 | if (memory->done_turning == true && memory->done_moving == true) { |
| 6532 | SetMode(me, AB_HEALING); |
| 6533 | break; |
| 6534 | } |
| 6535 | } break; |
| 6536 | |
| 6537 | case AB_GOING_TO_NEST: { |
| 6538 | char type, next_type; |
| 6539 | |
| 6540 | // If we're in alert, or the next anim mode is alert, and we're done moving, land at home |
| 6541 | if (memory->done_moving == true) { |
| 6542 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 6543 | AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_type); |
| 6544 | |
| 6545 | if (type == AS_ALERT || type == AS_IDLE || next_type == AS_ALERT || next_type == AS_IDLE) { |
| 6546 | SetMode(me, AB_LANDING_AT_NEST); |
| 6547 | break; |
| 6548 | } |
| 6549 | } |
| 6550 | } break; |
| 6551 | |
| 6552 | case AB_WANDERING: { |
| 6553 | // If we've seen a target, switch into attack mode |
| 6554 | if (memory->intro_ended && last_perceive_time <= 2.0f) { |
| 6555 | // Play the saw player shriek |
| 6556 | aSoundPlayObject(boss_see_id, me, 1.0f); |
| 6557 | |
| 6558 | SetMode(me, AB_ATTACKING); |
| 6559 | break; |
| 6560 | } |
| 6561 | |
| 6562 | // See if intro has ended yet |
| 6563 | if (!memory->intro_ended) { |
| 6564 | if (memory->mode_time > memory->intro_end_time) { |
| 6565 | // Set the normal wander speed |
| 6566 | SetMaxSpeed(me, memory->base_speed * AB_WANDER_SPEED_MOD); |
| 6567 | |
| 6568 | // set the intro ended flag |
| 6569 | memory->intro_ended = true; |
| 6570 | |
| 6571 | mprintf(0, "Intro ended for alien boss.\n"); |
| 6572 | } |
| 6573 | } |
| 6574 | } break; |
| 6575 | |
| 6576 | case AB_FLEEING: { |
| 6577 | // See if it is time to stop running |
| 6578 | if (memory->mode_time >= memory->max_wander_time) { |
| 6579 | // Go back to attack mode for now |
| 6580 | SetMode(me, AB_ATTACKING); |
| 6581 | } |
| 6582 | } break; |
| 6583 | |
| 6584 | case AB_ATTACKING: { |
| 6585 | // Do we need to heal? |
| 6586 | if (memory->damage > memory->damage_threshold) { |
| 6587 | aSoundPlayObject(boss_hurt_id, me, 1.0f); |
| 6588 | |
| 6589 | SetMode(me, AB_GOING_TO_NEST); |
| 6590 | break; |
| 6591 | } |
| 6592 | |
| 6593 | // See if we should do a round of healing |
| 6594 | if (Game_GetTime() >= memory->next_activity_time) { |
| 6595 | // Set the next time to do something |
| 6596 | memory->next_activity_time = Game_GetTime() + AB_ATTACK_CHECK_INTERVAL; |
| 6597 | |
| 6598 | // Should we flee? |
| 6599 | if (memory->state == AB_NORMAL && IsOnFire(me) && (rand() % 100) < memory->fire_flee_chance) { |
| 6600 | aSoundPlayObject(boss_hurt_id, me, 1.0f); |
| 6601 | |
| 6602 | SetMode(me, AB_FLEEING); |
| 6603 | break; |
| 6604 | } |
| 6605 | |
| 6606 | // Should we do a special attack? |
| 6607 | if (Game_GetTime() >= memory->next_special_attack_time) { |
| 6608 | if (OkToStartSpecialAttack(me)) { |
| 6609 | aSoundPlayObject(boss_see_id, me, 1.0f); |
| 6610 | |
| 6611 | memory->next_special_attack_time = |
| 6612 | Game_GetTime() + AB_SPECIAL_ATTACK_DELAY + ((float)rand() / (float)D3_RAND_MAX) * AB_SPECIAL_ATTACK_VARIANCE; |
| 6613 | |
| 6614 | SetMode(me, AB_PREPARE_SPECIAL_ATTACK); |
| 6615 | break; |
| 6616 | } |
| 6617 | } |
| 6618 | |
| 6619 | // Should we switch to melee mode? |
| 6620 | if (Game_GetTime() >= memory->next_melee_attack_time) { |
| 6621 | int target_handle; |
| 6622 | |
| 6623 | // Make sure we still have a target |
| 6624 | AI_Value(me, VF_GET, AIV_I_TARGET_HANDLE, &target_handle); |
| 6625 | if (target_handle != OBJECT_HANDLE_NONE) { |
| 6626 | // check distance to target |
| 6627 | float dist; |
| 6628 | AI_Value(me, VF_GET, AIV_F_DIST_TO_TARGET, &dist); |
| 6629 | if (dist < AB_MELEE_DIST) { |
| 6630 | SetMode(me, AB_MELEE_ATTACK); |
| 6631 | break; |
| 6632 | } |
| 6633 | } |
| 6634 | } |
| 6635 | } |
| 6636 | |
| 6637 | // If haven't perceived target for a while, return to wander mode |
| 6638 | if (last_perceive_time >= 10.0f) { |
| 6639 | // If we're not in a protective state, go ahead and wander |
| 6640 | if (memory->state == AB_PROTECTIVE) { |
| 6641 | // See if we're in the nest room |
| 6642 | int curr_room; |
| 6643 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &curr_room); |
| 6644 | if (curr_room != memory->wander_rooms[0]) { |
| 6645 | // Go protect nest |
| 6646 | SetMode(me, AB_GOING_TO_PROTECT_NEST); |
| 6647 | break; |
| 6648 | } |
| 6649 | } else { |
| 6650 | SetMode(me, AB_WANDERING); |
| 6651 | break; |
| 6652 | } |
| 6653 | } |
| 6654 | } break; |
| 6655 | |
| 6656 | case AB_MELEE_ATTACK: { |
| 6657 | // Wait until the melee attack time has expired |
| 6658 | if (memory->mode_time > AB_MAX_MELEE_TIME) { |
| 6659 | memory->next_melee_attack_time = |
| 6660 | Game_GetTime() + AB_MELEE_ATTACK_DELAY + ((float)rand() / (float)D3_RAND_MAX) * AB_MELEE_ATTACK_VARIANCE; |
| 6661 | |
| 6662 | SetMode(me, AB_ATTACKING); |
| 6663 | break; |
| 6664 | } |
| 6665 | } break; |
| 6666 | |
| 6667 | case AB_PREPARE_SPECIAL_ATTACK: { |
| 6668 | char type, next_type; |
| 6669 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 6670 | AI_Value(me, VF_GET, AIV_C_NEXT_ANIMATION_TYPE, &next_type); |
| 6671 | |
| 6672 | // Wait until the current or next anim type is alert, then try special attack |
| 6673 | if (type == AS_ALERT || next_type == AS_ALERT) { |
| 6674 | SetMode(me, AB_SPECIAL_ATTACK); |
| 6675 | break; |
| 6676 | } |
| 6677 | } break; |
| 6678 | |
| 6679 | case AB_SPECIAL_ATTACK: { |
| 6680 | // Wait until the fire frame is up |
| 6681 | if (anim_frame == AB_ATTACK_END_FRAME) { |
| 6682 | // Create a frag burst effect |
| 6683 | vector pos; |
| 6684 | int room; |
| 6685 | matrix orient; |
| 6686 | |
| 6687 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 6688 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6689 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 6690 | Obj_Create(OBJ_WEAPON, boss_frag_burst_id, room, &pos, &orient, me); |
| 6691 | |
| 6692 | // Go to recover mode |
| 6693 | SetMode(me, AB_SPECIAL_ATTACK_RECOIL); |
| 6694 | break; |
| 6695 | } |
| 6696 | } break; |
| 6697 | |
| 6698 | case AB_SPECIAL_ATTACK_RECOIL: { |
| 6699 | char type; |
| 6700 | AI_Value(me, VF_GET, AIV_C_ANIMATION_TYPE, &type); |
| 6701 | |
| 6702 | // Wait until the current anim type is alert, then return to normal |
| 6703 | if (type == AS_ALERT) { |
| 6704 | SetMode(me, AB_ATTACKING); |
| 6705 | break; |
| 6706 | } |
| 6707 | } break; |
| 6708 | } |
| 6709 | |
| 6710 | // Do the damage effect if necessary |
| 6711 | UpdateDamageEffect(me); |
| 6712 | |
| 6713 | // If necessary, check if we're stuck |
| 6714 | if (ModeIsStuckSensitive(memory->mode)) { |
| 6715 | vector curr_pos, dist_vec; |
| 6716 | |
| 6717 | // Update the values |
| 6718 | Obj_Value(me, VF_GET, OBJV_V_POS, &curr_pos); |
| 6719 | dist_vec = curr_pos - memory->last_pos; |
| 6720 | memory->squared_dist_moved += (dist_vec.x * dist_vec.x + dist_vec.y * dist_vec.y + dist_vec.z * dist_vec.z); |
| 6721 | memory->last_pos = curr_pos; |
| 6722 | |
| 6723 | // See if we need to do a stuck check |
| 6724 | if (Game_GetTime() >= memory->next_check_if_stuck_time) { |
| 6725 | // Calc the next time to check for stuckitude |
| 6726 | memory->next_check_if_stuck_time = Game_GetTime() + AB_CHECK_IF_STUCK_INTERVAL; |
| 6727 | |
| 6728 | mprintf(0, "Checking to see if Alien Boss is stuck (dist*dist=%f)...\n", memory->squared_dist_moved); |
| 6729 | |
| 6730 | // Check if the distance moved indicates being stuck |
| 6731 | if (memory->squared_dist_moved < (AB_CHECK_IF_STUCK_DIST * AB_CHECK_IF_STUCK_DIST)) { |
| 6732 | mprintf(0, "Alien Boss is stuck... now teleporting to destination.\n"); |
| 6733 | |
| 6734 | // Teleport boss to new location |
| 6735 | SetMode(me, AB_TELEPORTING); |
| 6736 | } else { |
| 6737 | // Clear the distance moved |
| 6738 | memory->squared_dist_moved = 0.0f; |
| 6739 | } |
| 6740 | } |
| 6741 | } |
| 6742 | |
| 6743 | // Increment the current mode time |
| 6744 | memory->mode_time += Game_GetFrameTime(); |
| 6745 | } |
| 6746 | |
| 6747 | // Process all AI Notify events |
| 6748 | bool AlienBoss::DoNotify(int me, tOSIRISEventInfo *data) { |
| 6749 | if (IsGoalFinishedNotify(data->evt_ai_notify.notify_type)) { |
| 6750 | // Handle goal complete events |
| 6751 | switch (data->evt_ai_notify.goal_uid) { |
| 6752 | case AB_GUID_GOT_TO_NEST: |
| 6753 | memory->done_moving = true; |
| 6754 | break; |
| 6755 | |
| 6756 | case AB_GUID_LANDED: |
| 6757 | memory->done_moving = true; |
| 6758 | break; |
| 6759 | |
| 6760 | case AB_GUID_GOT_TO_NEST_ROOM: { |
| 6761 | // if we're going to protect nest, switch into attack mode |
| 6762 | if (memory->mode == AB_GOING_TO_PROTECT_NEST) { |
| 6763 | mprintf(0, "Alien Boss got to nest room.\n"); |
| 6764 | |
| 6765 | // If we haven't protected nest yet, do special stuff |
| 6766 | if (!memory->protected_nest) { |
| 6767 | int minion1_handle, minion2_handle, player_handle; |
| 6768 | |
| 6769 | minion1_handle = Scrpt_FindObjectName("BossMinion1"); |
| 6770 | minion2_handle = Scrpt_FindObjectName("BossMinion2"); |
| 6771 | |
| 6772 | // Unghost the minions |
| 6773 | aObjGhostSet(0, minion1_handle); |
| 6774 | aObjGhostSet(0, minion2_handle); |
| 6775 | |
| 6776 | // Turn on their AI |
| 6777 | aAISetState(1, minion1_handle); |
| 6778 | aAISetState(1, minion2_handle); |
| 6779 | |
| 6780 | // Send them to get the closest player |
| 6781 | player_handle = FindClosestPlayer(minion1_handle); |
| 6782 | SendCommand(minion1_handle, minion1_handle, ALIEN_COM_HUNT_TO_OBJ, &player_handle); |
| 6783 | SendCommand(minion2_handle, minion2_handle, ALIEN_COM_HUNT_TO_OBJ, &player_handle); |
| 6784 | |
| 6785 | // Play Shriek |
| 6786 | aSoundPlayObject(boss_see_id, me, 1.0f); |
| 6787 | |
| 6788 | // Set the protected nest flag |
| 6789 | memory->protected_nest = true; |
| 6790 | } |
| 6791 | |
| 6792 | SetMode(me, AB_ATTACKING); |
| 6793 | break; |
| 6794 | } |
| 6795 | } break; |
| 6796 | |
| 6797 | case AB_GUID_GOT_TO_HIDE_ROOM: { |
| 6798 | // if we're going to protect nest, switch into attack mode |
| 6799 | if (memory->mode == AB_HIDING_FROM_THRUSTER) { |
| 6800 | mprintf(0, "Alien boss got to hide room.\n"); |
| 6801 | // SetMode(me,AB_ATTACKING); |
| 6802 | // break; |
| 6803 | } |
| 6804 | } break; |
| 6805 | |
| 6806 | case AB_GUID_GOT_TO_WANDER_ROOM: { |
| 6807 | // Make sure we're in wander mode |
| 6808 | if (memory->mode == AB_WANDERING) { |
| 6809 | // Decide whether or not to reverse directions |
| 6810 | if ((rand() % 100) < 4) { |
| 6811 | memory->wander_forward = (memory->wander_forward) ? false : true; |
| 6812 | |
| 6813 | mprintf(0, "Alien Boss - Reversing wander direction\n"); |
| 6814 | } |
| 6815 | |
| 6816 | // Check whether to follow list in reverse or not |
| 6817 | if (memory->wander_forward) { |
| 6818 | memory->curr_wander_room_index++; |
| 6819 | if (memory->curr_wander_room_index >= AB_NUM_WANDER_ROOMS) { |
| 6820 | memory->curr_wander_room_index = 0; |
| 6821 | } |
| 6822 | } else { |
| 6823 | memory->curr_wander_room_index--; |
| 6824 | if (memory->curr_wander_room_index < 0) { |
| 6825 | memory->curr_wander_room_index = AB_NUM_WANDER_ROOMS - 1; |
| 6826 | } |
| 6827 | } |
| 6828 | |
| 6829 | // Set the goal to go to the next room |
| 6830 | SetWanderRoomGoal(me); |
| 6831 | |
| 6832 | // Play the wandering sound |
| 6833 | aSoundPlayObject(boss_turf_id, me, 1.0f); |
| 6834 | |
| 6835 | mprintf(0, "Alien Boss - Wandering to room: %d\n", memory->curr_wander_room_index); |
| 6836 | } |
| 6837 | } break; |
| 6838 | |
| 6839 | case AB_GUID_GOT_TO_DEST_OBJ: |
| 6840 | memory->dest_object_handle = OBJECT_HANDLE_NONE; |
| 6841 | SetMode(me, memory->mode); |
| 6842 | mprintf(0, "Alien Boss got to destination object.\n"); |
| 6843 | break; |
| 6844 | } |
| 6845 | } else if (data->evt_ai_notify.notify_type == AIN_SCRIPTED_ORIENT) { |
| 6846 | // Handle custom orientation events |
| 6847 | if (memory->mode == AB_LANDING_AT_NEST) { |
| 6848 | memory->done_turning = (AI_TurnTowardsVectors(me, &memory->home_fvec, &memory->home_uvec) != 0); |
| 6849 | } |
| 6850 | } else if (data->evt_ai_notify.notify_type == AIN_MELEE_HIT) { |
| 6851 | // Create hit sparks |
| 6852 | int room; |
| 6853 | vector pos; |
| 6854 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6855 | Obj_GetGunPos(me, 0, &pos); |
| 6856 | Game_CreateRandomSparks(30, &pos, room); |
| 6857 | |
| 6858 | // Create the concussive hit blast |
| 6859 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6860 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 6861 | Obj_Create(OBJ_WEAPON, lifter_blast_effect_id, room, &pos, NULL, me); |
| 6862 | } else if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) { |
| 6863 | bot_com *com = (bot_com *)data->extra_info; |
| 6864 | |
| 6865 | return ReceiveCommand(me, data->evt_ai_notify.it_handle, com->action, com->ptr); |
| 6866 | } |
| 6867 | |
| 6868 | return true; |
| 6869 | } |
| 6870 | |
| 6871 | // Handles application of damage to an alien |
| 6872 | void AlienBoss::DoDamage(int me, tOSIRISEVTDAMAGED *damage_data) { |
| 6873 | // Handle fire damage |
| 6874 | if (damage_data->damage_type == GD_FIRE) { |
| 6875 | memory->damage += (damage_data->damage * 0.6f); |
| 6876 | return; |
| 6877 | } |
| 6878 | |
| 6879 | // Handle damage by matter weapons |
| 6880 | if (damage_data->damage_type == GD_MATTER) { |
| 6881 | memory->damage += (damage_data->damage * 0.7f); |
| 6882 | |
| 6883 | if (Game_GetTime() >= memory->next_special_damage_time) { |
| 6884 | memory->next_special_damage_time = Game_GetTime() + 0.8f + ((float)rand() / (float)D3_RAND_MAX) * 0.5f; |
| 6885 | |
| 6886 | // Create a frag burst effect |
| 6887 | vector pos; |
| 6888 | int room; |
| 6889 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 6890 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6891 | Obj_Create(OBJ_WEAPON, frag_burst_effect_id, room, &pos, NULL, me); |
| 6892 | } |
| 6893 | |
| 6894 | return; |
| 6895 | } |
| 6896 | |
| 6897 | // Handle damage by energy weapons |
| 6898 | if ((damage_data->damage_type == GD_ENERGY || damage_data->damage_type == GD_ELECTRIC) && |
| 6899 | Game_GetTime() >= memory->next_special_damage_time) { |
| 6900 | // Check if we're currently susceptible to energy damage |
| 6901 | if (false) { |
| 6902 | memory->next_special_damage_time = Game_GetTime() + 0.1f + ((float)rand() / (float)D3_RAND_MAX) * 0.2f; |
| 6903 | |
| 6904 | // Do double damage |
| 6905 | memory->damage += (damage_data->damage * 1.5f); |
| 6906 | |
| 6907 | // Create sparks |
| 6908 | int room; |
| 6909 | vector pos; |
| 6910 | Obj_Value(me, VF_GET, OBJV_V_POS, &pos); |
| 6911 | Obj_Value(me, VF_GET, OBJV_I_ROOMNUM, &room); |
| 6912 | Game_CreateRandomSparks(30 + int(((float)rand() / (float)D3_RAND_MAX) * 10.0f), &pos, room); |
| 6913 | |
| 6914 | return; |
| 6915 | } else { |
| 6916 | // Do standard energy damage |
| 6917 | memory->damage += (damage_data->damage * 0.3f); |
| 6918 | return; |
| 6919 | } |
| 6920 | } |
| 6921 | |
| 6922 | // Apply standard damage mod |
| 6923 | memory->damage += (damage_data->damage * 0.1f); |
| 6924 | } |
| 6925 | |
| 6926 | // Handles attacks on aliens |
| 6927 | void AlienBoss::DoCollide(int me, tOSIRISEVTCOLLIDE *collide_data) { |
| 6928 | // See if it's a player or player weapon that hit us |
| 6929 | if (qObjIsPlayerOrPlayerWeapon(collide_data->it_handle)) { |
| 6930 | // mprintf(0,"Hit by player!\n"); |
| 6931 | memory->hit_by_player = true; |
| 6932 | } |
| 6933 | } |
| 6934 | |
| 6935 | // Does any final cleanup when object is destroyed |
| 6936 | void AlienBoss::DoCleanUp(int me) { |
| 6937 | // remove the powerup props |
| 6938 | msafe_struct mo; |
| 6939 | mo.objhandle = memory->tail_pos_handle; |
| 6940 | MSafe_CallFunction(MSAFE_OBJECT_REMOVE, &mo); |
| 6941 | } |
| 6942 | |
| 6943 | // Receives all basic events and calls processesing functions |
| 6944 | int16_t AlienBoss::CallEvent(int event, tOSIRISEventInfo *data) { |
| 6945 | switch (event) { |
| 6946 | case EVT_AI_INIT: |
| 6947 | DoInit(data->me_handle); |
| 6948 | break; |
| 6949 | case EVT_AI_FRAME: |
| 6950 | DoFrame(data->me_handle); |
| 6951 | break; |
| 6952 | case EVT_AI_NOTIFY: |
| 6953 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 6954 | break; |
| 6955 | case EVT_DAMAGED: { |
| 6956 | DoDamage(data->me_handle, &data->evt_damaged); |
| 6957 | |
| 6958 | // If boss is slightly damaged, restore it's hitpoints (so it can never die!) |
| 6959 | float curr_shields; |
| 6960 | Obj_Value(data->me_handle, VF_GET, OBJV_F_SHIELDS, &curr_shields); |
| 6961 | if (curr_shields < memory->base_shields * 0.75f) { |
| 6962 | Obj_Value(data->me_handle, VF_SET, OBJV_F_SHIELDS, &memory->base_shields); |
| 6963 | } |
| 6964 | |
| 6965 | // Only allow it to take very little damage (must take some or it doesn't catch on fire) |
| 6966 | data->evt_damaged.damage = 0.000001f; |
| 6967 | } break; |
| 6968 | case EVT_DESTROY: |
| 6969 | DoCleanUp(data->me_handle); |
| 6970 | break; |
| 6971 | case EVT_COLLIDE: |
| 6972 | DoCollide(data->me_handle, &data->evt_collide); |
| 6973 | break; |
| 6974 | case EVT_MEMRESTORE: |
| 6975 | memory = (alienboss_data *)data->evt_memrestore.memory_ptr; |
| 6976 | DoCustomLookups(); |
| 6977 | break; |
| 6978 | } |
| 6979 | |
| 6980 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 6981 | } |
| 6982 | |
| 6983 | //----------------------- |
| 6984 | // Security Camera class |
| 6985 | //----------------------- |
| 6986 | |
| 6987 | // Sends a command out to another alien |
| 6988 | bool SecurityCamera::SendCommand(int me, int it, char command, void *ptr) { |
| 6989 | bot_com com; |
| 6990 | |
| 6991 | com.action = command; |
| 6992 | com.ptr = ptr; |
| 6993 | |
| 6994 | tOSIRISEventInfo ei; |
| 6995 | |
| 6996 | ei.me_handle = it; |
| 6997 | ei.extra_info = (void *)&com; |
| 6998 | ei.evt_ai_notify.notify_type = AIN_USER_DEFINED; |
| 6999 | ei.evt_ai_notify.it_handle = me; |
| 7000 | |
| 7001 | return Obj_CallEvent(it, EVT_AI_NOTIFY, &ei); |
| 7002 | } |
| 7003 | |
| 7004 | // Processes a command from another alien |
| 7005 | bool SecurityCamera::ReceiveCommand(int me, int it, char command, void *ptr) { |
| 7006 | switch (command) { |
| 7007 | // Alien is asked to return current mode |
| 7008 | case SC_COM_GET_ALERT_STATUS: |
| 7009 | *(bool *)ptr = memory->alerted; |
| 7010 | return true; |
| 7011 | break; |
| 7012 | } |
| 7013 | |
| 7014 | return false; |
| 7015 | } |
| 7016 | |
| 7017 | // Sets the Current Mode |
| 7018 | void SecurityCamera::SetMode(int me, char mode) { |
| 7019 | int flags; |
| 7020 | float curr_anim_frame; |
| 7021 | |
| 7022 | // Get the current animation frame |
| 7023 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &curr_anim_frame); |
| 7024 | |
| 7025 | // mprintf(0, "From mode %d, ",memory->mode); |
| 7026 | |
| 7027 | // Do mode specific setups |
| 7028 | switch (mode) { |
| 7029 | case SC_PANNING: { |
| 7030 | float time; |
| 7031 | |
| 7032 | // Get the camera ready for looping |
| 7033 | memory->panning_state = SC_WARMING_UP; |
| 7034 | if (curr_anim_frame > SC_MAX_FRAME) |
| 7035 | curr_anim_frame = SC_MAX_FRAME; |
| 7036 | |
| 7037 | time = (SC_MAX_FRAME - curr_anim_frame) / SC_PAN_SPEED; |
| 7038 | Obj_SetCustomAnim(me, curr_anim_frame, SC_MAX_FRAME, time, AIAF_IMMEDIATE, -1, -1); |
| 7039 | mprintf(0, "Warming up...\n"); |
| 7040 | } break; |
| 7041 | |
| 7042 | case SC_TRACKING: { |
| 7043 | memory->next_activity_time = Game_GetTime(); |
| 7044 | // memory->last_update_anim_time = Game_GetTime(); |
| 7045 | |
| 7046 | mprintf(0, "Camera spotted you!\n"); |
| 7047 | } break; |
| 7048 | |
| 7049 | default: |
| 7050 | mprintf(0, "Security Camera is all messed up!\n"); |
| 7051 | break; |
| 7052 | } |
| 7053 | |
| 7054 | // Set the current mode and reset the mode time |
| 7055 | memory->mode = mode; |
| 7056 | memory->mode_time = 0.0f; |
| 7057 | } |
| 7058 | |
| 7059 | // Processes the AI Initialize event |
| 7060 | void SecurityCamera::DoInit(int me) { |
| 7061 | // Setup memory data |
| 7062 | tOSIRISMEMCHUNK ch; |
| 7063 | ch.id = SC_MEMORY_ID; |
| 7064 | ch.size = sizeof(securitycamera_data); |
| 7065 | ch.my_id.type = OBJECT_SCRIPT; |
| 7066 | ch.my_id.objhandle = me; |
| 7067 | |
| 7068 | memory = (securitycamera_data *)Scrpt_MemAlloc(&ch); |
| 7069 | |
| 7070 | memory->alerted = false; |
| 7071 | |
| 7072 | SetMode(me, SC_PANNING); |
| 7073 | } |
| 7074 | |
| 7075 | // Processes the AI Frame Interval Event |
| 7076 | void SecurityCamera::DoFrame(int me) { |
| 7077 | float last_see_time, last_see_game_time; |
| 7078 | float curr_anim_frame; |
| 7079 | |
| 7080 | // Get the last see time |
| 7081 | AI_Value(me, VF_GET, AIV_F_LAST_SEE_TARGET_TIME, &last_see_game_time); |
| 7082 | |
| 7083 | // Calculate the time since target was seen or heard |
| 7084 | last_see_time = Game_GetTime() - last_see_game_time; |
| 7085 | |
| 7086 | // Get the current animation frame |
| 7087 | Obj_Value(me, VF_GET, OBJV_F_ANIM_FRAME, &curr_anim_frame); |
| 7088 | |
| 7089 | // Do mode specific checks |
| 7090 | switch (memory->mode) { |
| 7091 | case SC_PANNING: { |
| 7092 | // If we have a target switch to tracking mode |
| 7093 | if (last_see_time < SC_TIME_TO_GAIN_TARGET) { |
| 7094 | SetMode(me, SC_TRACKING); |
| 7095 | break; |
| 7096 | } |
| 7097 | |
| 7098 | // If we're warming up, see if we should start looping yet |
| 7099 | if (memory->panning_state == SC_WARMING_UP) { |
| 7100 | // See if we're at the final frame |
| 7101 | if (curr_anim_frame >= SC_MAX_FRAME) { |
| 7102 | memory->panning_state = SC_LOOPING; |
| 7103 | |
| 7104 | float time = (SC_MAX_FRAME - SC_START_FRAME) / SC_PAN_SPEED; |
| 7105 | Obj_SetCustomAnim(me, SC_START_FRAME, SC_MAX_FRAME, time, AIAF_IMMEDIATE | AIAF_LOOPING, -1, -1); |
| 7106 | mprintf(0, "Looping pan started...\n"); |
| 7107 | } |
| 7108 | } |
| 7109 | } break; |
| 7110 | |
| 7111 | case SC_TRACKING: { |
| 7112 | // If we haven't seen target for a while, return to panning |
| 7113 | if (last_see_time > SC_TIME_TO_LOSE_TARGET) { |
| 7114 | SetMode(me, SC_PANNING); |
| 7115 | break; |
| 7116 | } |
| 7117 | |
| 7118 | // If we've been tracking target long enough, switch to alert mode |
| 7119 | if (Game_GetTime() >= memory->next_activity_time) { |
| 7120 | memory->next_activity_time = Game_GetTime() + SC_TRACK_INTERVAL; |
| 7121 | |
| 7122 | // Track the current target |
| 7123 | vector local_vec_to_target, world_vec_to_target, dir, local_fvec; |
| 7124 | matrix orient; |
| 7125 | double theta; |
| 7126 | float frame_offset, dot, curr_frame, dest_frame, anim_time, next_frame; |
| 7127 | |
| 7128 | // Get the vec to target in local security camera space |
| 7129 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &orient); |
| 7130 | AI_Value(me, VF_GET, AIV_V_VEC_TO_TARGET, &world_vec_to_target); |
| 7131 | local_vec_to_target = world_vec_to_target * orient; |
| 7132 | |
| 7133 | // Make it track target on a 2D plane |
| 7134 | dir = local_vec_to_target; |
| 7135 | dir.y = 0.0f; |
| 7136 | if ((dir.x + dir.y + dir.z) == 0.0f) |
| 7137 | break; |
| 7138 | vm_VectorNormalize(&dir); |
| 7139 | |
| 7140 | local_fvec.x = 0.0f; |
| 7141 | local_fvec.y = 0.0f; |
| 7142 | local_fvec.z = 1.0f; |
| 7143 | dot = dir * local_fvec; |
| 7144 | if (dot < -1.0f) |
| 7145 | dot = -1.0f; |
| 7146 | if (dot > 1.0f) |
| 7147 | dot = 1.0f; |
| 7148 | theta = acos(dot); |
| 7149 | theta = theta / PI * 4.0; |
| 7150 | |
| 7151 | frame_offset = float(theta) * SC_MAX_FRAME_OFFSET; |
| 7152 | if (frame_offset > SC_MAX_FRAME_OFFSET) |
| 7153 | frame_offset = SC_MAX_FRAME_OFFSET; |
| 7154 | |
| 7155 | // mprintf(0,"x=%.3f, y=%.3f, z=%.3f - dot=%.3f, theta=%.1f\n",dir.x,dir.y,dir.z,dot,theta); |
| 7156 | // mprintf(0,"Frame offset: %.1f\n",frame_offset); |
| 7157 | |
| 7158 | // Get the dest frame between start and end frames for reference |
| 7159 | if (dir.x < 0.0f) |
| 7160 | frame_offset = -frame_offset; |
| 7161 | dest_frame = SC_MID_FRAME + frame_offset; |
| 7162 | |
| 7163 | // Get the current frame between start and end frames for reference |
| 7164 | curr_frame = curr_anim_frame; |
| 7165 | if (curr_frame > SC_END_FRAME) |
| 7166 | curr_frame = SC_MAX_FRAME - curr_frame; |
| 7167 | |
| 7168 | // Prevent wobbling between two frames |
| 7169 | if (abs(dest_frame - curr_frame) <= SC_FRAME_DELTA_ERROR) { |
| 7170 | dest_frame = curr_frame; |
| 7171 | } |
| 7172 | |
| 7173 | // Check if frames are reversed, and adjust accordingly |
| 7174 | if (dest_frame < curr_frame) { |
| 7175 | dest_frame = SC_MAX_FRAME - dest_frame; |
| 7176 | curr_frame = SC_MAX_FRAME - curr_frame; |
| 7177 | } |
| 7178 | |
| 7179 | // Calculate the animation time to go from curr_frame to dest_frame |
| 7180 | anim_time = (dest_frame - curr_frame) / SC_TRACK_SPEED; |
| 7181 | /* |
| 7182 | // Calculate the max distance we can move it this frame |
| 7183 | anim_time = Game_GetTime() - memory->last_update_anim_time; |
| 7184 | next_frame = curr_frame + (anim_time*SC_PAN_SPEED); |
| 7185 | if(next_frame > dest_frame) next_frame=dest_frame; |
| 7186 | Obj_SetCustomAnim(me, next_frame, next_frame, 0.0f, AIAF_IMMEDIATE, -1, -1); |
| 7187 | */ |
| 7188 | |
| 7189 | // Set the next custom animation |
| 7190 | Obj_SetCustomAnim(me, curr_frame, dest_frame, anim_time, AIAF_IMMEDIATE, -1, -1); |
| 7191 | // mprintf(0,"Curr frame: %.6f, Dest frame: %.6f, Anim time: %.1f\n",curr_frame,dest_frame,anim_time); |
| 7192 | |
| 7193 | // Record the last update anim time |
| 7194 | // memory->last_update_anim_time = Game_GetTime(); |
| 7195 | } |
| 7196 | |
| 7197 | // If we've successfully tracked target for a while, then we are alerted |
| 7198 | if (memory->mode_time >= SC_TRACK_TIME_TO_ALERT && !memory->alerted) { |
| 7199 | memory->alerted = true; |
| 7200 | mprintf(0, "Alerted!\n"); |
| 7201 | } |
| 7202 | } break; |
| 7203 | } |
| 7204 | |
| 7205 | // mprintf(0,"Anim frame: %.2f\n",curr_anim_frame); |
| 7206 | |
| 7207 | // if(last_see_time < 3.0f) |
| 7208 | // mprintf(0,"Camera saw target %.2f seconds ago!\n",last_see_time); |
| 7209 | |
| 7210 | // Increment the current mode time |
| 7211 | memory->mode_time += Game_GetFrameTime(); |
| 7212 | } |
| 7213 | |
| 7214 | // Process all AI Notify events |
| 7215 | bool SecurityCamera::DoNotify(int me, tOSIRISEventInfo *data) { |
| 7216 | if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) { |
| 7217 | bot_com *com = (bot_com *)data->extra_info; |
| 7218 | |
| 7219 | return ReceiveCommand(me, data->evt_ai_notify.it_handle, com->action, com->ptr); |
| 7220 | } |
| 7221 | |
| 7222 | return true; |
| 7223 | } |
| 7224 | |
| 7225 | // Receives all basic events and calls processesing functions |
| 7226 | int16_t SecurityCamera::CallEvent(int event, tOSIRISEventInfo *data) { |
| 7227 | switch (event) { |
| 7228 | case EVT_AI_INIT: |
| 7229 | DoInit(data->me_handle); |
| 7230 | break; |
| 7231 | case EVT_AI_FRAME: |
| 7232 | DoFrame(data->me_handle); |
| 7233 | break; |
| 7234 | case EVT_AI_NOTIFY: |
| 7235 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 7236 | break; |
| 7237 | case EVT_DAMAGED: |
| 7238 | // DoDamage(data->me_handle, &data->evt_damaged); |
| 7239 | break; |
| 7240 | case EVT_DESTROY: |
| 7241 | break; |
| 7242 | case EVT_COLLIDE: |
| 7243 | // DoCollide(data->me_handle, &data->evt_collide); |
| 7244 | break; |
| 7245 | case EVT_MEMRESTORE: |
| 7246 | memory = (securitycamera_data *)data->evt_memrestore.memory_ptr; |
| 7247 | break; |
| 7248 | } |
| 7249 | |
| 7250 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 7251 | } |
| 7252 | |
| 7253 | //----------------------- |
| 7254 | // Crowd Control class |
| 7255 | //----------------------- |
| 7256 | |
| 7257 | // Sends a command out to another alien |
| 7258 | bool CrowdControl::SendCommand(int me, int it, char command, void *ptr) { |
| 7259 | bot_com com; |
| 7260 | |
| 7261 | com.action = command; |
| 7262 | com.ptr = ptr; |
| 7263 | |
| 7264 | tOSIRISEventInfo ei; |
| 7265 | |
| 7266 | ei.me_handle = it; |
| 7267 | ei.extra_info = (void *)&com; |
| 7268 | ei.evt_ai_notify.notify_type = AIN_USER_DEFINED; |
| 7269 | ei.evt_ai_notify.it_handle = me; |
| 7270 | |
| 7271 | return Obj_CallEvent(it, EVT_AI_NOTIFY, &ei); |
| 7272 | } |
| 7273 | |
| 7274 | // Processes a command from another alien |
| 7275 | bool CrowdControl::ReceiveCommand(int me, int it, char command, void *ptr) { |
| 7276 | switch (command) { |
| 7277 | // Alien is asked to return current mode |
| 7278 | case CC_COM_SET_DATA: { |
| 7279 | cc_packet *data = (cc_packet *)ptr; |
| 7280 | |
| 7281 | memory->follow_handle = data->follow_handle; |
| 7282 | memory->stop_dist = data->stop_dist; |
| 7283 | memory->slowdown_offset = data->slowdown_offset; |
| 7284 | |
| 7285 | mprintf(0, "Set Crowd Control Data.\n"); |
| 7286 | return true; |
| 7287 | } break; |
| 7288 | |
| 7289 | case CC_COM_DISABLE_CHECK: { |
| 7290 | memory->disable_check = *(bool *)ptr; |
| 7291 | |
| 7292 | mprintf(0, "Crowd control disable check set to: %d\n", memory->disable_check); |
| 7293 | } break; |
| 7294 | } |
| 7295 | |
| 7296 | return false; |
| 7297 | } |
| 7298 | |
| 7299 | // Processes the AI Initialize event |
| 7300 | void CrowdControl::DoInit(int me) { |
| 7301 | // Setup memory data |
| 7302 | tOSIRISMEMCHUNK ch; |
| 7303 | ch.id = CC_MEMORY_ID; |
| 7304 | ch.size = sizeof(crowdcontrol_data); |
| 7305 | ch.my_id.type = OBJECT_SCRIPT; |
| 7306 | ch.my_id.objhandle = me; |
| 7307 | |
| 7308 | memory = (crowdcontrol_data *)Scrpt_MemAlloc(&ch); |
| 7309 | |
| 7310 | AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &memory->base_speed); |
| 7311 | |
| 7312 | memory->follow_handle = OBJECT_HANDLE_NONE; |
| 7313 | memory->stop_dist = 0.0f; |
| 7314 | memory->slowdown_offset = 0.0f; |
| 7315 | |
| 7316 | memory->disable_check = false; |
| 7317 | |
| 7318 | memory->next_check_time = Game_GetTime(); |
| 7319 | |
| 7320 | mprintf(0, "CrowdControl Initialized.\n"); |
| 7321 | } |
| 7322 | |
| 7323 | // Processes the AI Frame Interval Event |
| 7324 | void CrowdControl::DoFrame(int me) { |
| 7325 | // If data hasn't been set yet, just bail |
| 7326 | if (memory->follow_handle == OBJECT_HANDLE_NONE) |
| 7327 | return; |
| 7328 | |
| 7329 | // See if we need to do a distance check yet |
| 7330 | if (Game_GetTime() >= memory->next_check_time) { |
| 7331 | memory->next_check_time = Game_GetTime() + CC_CHECK_INTERVAL; |
| 7332 | |
| 7333 | float my_max_speed; |
| 7334 | bool ok_to_move_normally = false; |
| 7335 | |
| 7336 | // Get my current max speed |
| 7337 | AI_Value(me, VF_GET, AIV_F_MAX_SPEED, &my_max_speed); |
| 7338 | |
| 7339 | // Make sure the object we're following still exists |
| 7340 | if (!memory->disable_check && qObjExists(memory->follow_handle)) { |
| 7341 | vector my_vel, my_pos, leader_pos, leader_dir; |
| 7342 | matrix my_orient; |
| 7343 | float my_max_speed, dist, new_speed; |
| 7344 | |
| 7345 | Obj_Value(me, VF_GET, OBJV_V_VELOCITY, &my_vel); |
| 7346 | Obj_Value(me, VF_GET, OBJV_V_POS, &my_pos); |
| 7347 | Obj_Value(me, VF_GET, OBJV_M_ORIENT, &my_orient); |
| 7348 | Obj_Value(memory->follow_handle, VF_GET, OBJV_V_POS, &leader_pos); |
| 7349 | |
| 7350 | // It's ok to move in reverse, or away from leader |
| 7351 | ok_to_move_normally = ((my_vel * my_orient.fvec) <= 0.0f) ? true : false; |
| 7352 | if (!ok_to_move_normally) { |
| 7353 | leader_dir = leader_pos - my_pos; |
| 7354 | ok_to_move_normally = ((my_vel * leader_dir) <= 0.0f) ? true : false; |
| 7355 | } |
| 7356 | |
| 7357 | // Check to see if we're too close to leader (so we can slow down and stop) |
| 7358 | dist = vm_VectorDistance(&my_pos, &leader_pos); |
| 7359 | if (!ok_to_move_normally && dist < (memory->stop_dist + memory->slowdown_offset)) { |
| 7360 | if (dist <= memory->stop_dist || memory->slowdown_offset == 0.0f) { |
| 7361 | new_speed = CC_MIN_STOPPING_SPEED; |
| 7362 | } else { |
| 7363 | float curr_diff; |
| 7364 | curr_diff = dist - memory->stop_dist; |
| 7365 | |
| 7366 | new_speed = CC_MIN_STOPPING_SPEED + ((curr_diff / memory->slowdown_offset) * memory->base_speed); |
| 7367 | } |
| 7368 | |
| 7369 | AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &new_speed); |
| 7370 | } |
| 7371 | } else { |
| 7372 | ok_to_move_normally = true; |
| 7373 | } |
| 7374 | |
| 7375 | // Restore the max speed to the original value if necessary |
| 7376 | if (ok_to_move_normally && my_max_speed != memory->base_speed) { |
| 7377 | AI_Value(me, VF_SET, AIV_F_MAX_SPEED, &memory->base_speed); |
| 7378 | } |
| 7379 | } |
| 7380 | } |
| 7381 | |
| 7382 | // Process all AI Notify events |
| 7383 | bool CrowdControl::DoNotify(int me, tOSIRISEventInfo *data) { |
| 7384 | if (data->evt_ai_notify.notify_type == AIN_USER_DEFINED) { |
| 7385 | bot_com *com = (bot_com *)data->extra_info; |
| 7386 | |
| 7387 | return ReceiveCommand(me, data->evt_ai_notify.it_handle, com->action, com->ptr); |
| 7388 | } |
| 7389 | |
| 7390 | return true; |
| 7391 | } |
| 7392 | |
| 7393 | // Receives all basic events and calls processesing functions |
| 7394 | int16_t CrowdControl::CallEvent(int event, tOSIRISEventInfo *data) { |
| 7395 | switch (event) { |
| 7396 | case EVT_AI_INIT: |
| 7397 | DoInit(data->me_handle); |
| 7398 | break; |
| 7399 | case EVT_AI_FRAME: |
| 7400 | DoFrame(data->me_handle); |
| 7401 | break; |
| 7402 | case EVT_AI_NOTIFY: |
| 7403 | return (DoNotify(data->me_handle, data) != false) ? CONTINUE_CHAIN | CONTINUE_DEFAULT : 0; |
| 7404 | break; |
| 7405 | case EVT_DAMAGED: |
| 7406 | // DoDamage(data->me_handle, &data->evt_damaged); |
| 7407 | break; |
| 7408 | case EVT_DESTROY: |
| 7409 | break; |
| 7410 | case EVT_COLLIDE: |
| 7411 | // DoCollide(data->me_handle, &data->evt_collide); |
| 7412 | break; |
| 7413 | case EVT_MEMRESTORE: |
| 7414 | memory = (crowdcontrol_data *)data->evt_memrestore.memory_ptr; |
| 7415 | break; |
| 7416 | } |
| 7417 | |
| 7418 | return CONTINUE_CHAIN | CONTINUE_DEFAULT; |
| 7419 | } |