1 #pragma once 2 3 //******************************************************************************************** 4 //* 5 //* This file is part of Egoboo. 6 //* 7 //* Egoboo is free software: you can redistribute it and/or modify it 8 //* under the terms of the GNU General Public License as published by 9 //* the Free Software Foundation, either version 3 of the License, or 10 //* (at your option) any later version. 11 //* 12 //* Egoboo is distributed in the hope that it will be useful, but 13 //* WITHOUT ANY WARRANTY; without even the implied warranty of 14 //* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 //* General Public License for more details. 16 //* 17 //* You should have received a copy of the GNU General Public License 18 //* along with Egoboo. If not, see <http://www.gnu.org/licenses/>. 19 //* 20 //******************************************************************************************** 21 22 #include "egoboo_typedef.h" 23 24 #include "clock.h" 25 26 //-------------------------------------------------------------------------------------------- 27 //-------------------------------------------------------------------------------------------- 28 29 #define MSGDISTANCE 2000 ///< Range for SendMessageNear 30 #define PITNOSOUND -256 ///< Stop sound at bottom of pits... 31 32 /// These are for FindPath function only 33 #define MOVE_MELEE 300 34 #define MOVE_RANGED 600 35 #define MOVE_DISTANCE 175 36 #define MOVE_RETREAT 900 37 #define MOVE_CHARGE 111 38 #define MOVE_FOLLOW 0 39 40 /// Camera bounds/edge of the map 41 #define EDGE 128 42 43 /// AI targeting 44 #define NEARBY 3*GRID_FSIZE ///< 3 tiles away 45 #define WIDE 6*GRID_FSIZE ///< 6 tiles away 46 #define NEAREST 0 ///< unlimited range 47 48 //-------------------------------------------------------------------------------------------- 49 //-------------------------------------------------------------------------------------------- 50 51 /// Character AI alerts 52 enum chr_alert_bits 53 { 54 ALERT_NONE = 0, 55 ALERTIF_SPAWNED = 1 << 0, 56 ALERTIF_HITVULNERABLE = 1 << 1, 57 ALERTIF_ATWAYPOINT = 1 << 2, 58 ALERTIF_ATLASTWAYPOINT = 1 << 3, 59 ALERTIF_ATTACKED = 1 << 4, 60 ALERTIF_BUMPED = 1 << 5, 61 ALERTIF_ORDERED = 1 << 6, 62 ALERTIF_CALLEDFORHELP = 1 << 7, 63 ALERTIF_KILLED = 1 << 8, 64 ALERTIF_TARGETKILLED = 1 << 9, 65 ALERTIF_DROPPED = 1 << 10, 66 ALERTIF_GRABBED = 1 << 11, 67 ALERTIF_REAFFIRMED = 1 << 12, 68 ALERTIF_LEADERKILLED = 1 << 13, 69 ALERTIF_USED = 1 << 14, 70 ALERTIF_CLEANEDUP = 1 << 15, 71 ALERTIF_SCOREDAHIT = 1 << 16, 72 ALERTIF_HEALED = 1 << 17, 73 ALERTIF_DISAFFIRMED = 1 << 18, 74 ALERTIF_CHANGED = 1 << 19, 75 ALERTIF_INWATER = 1 << 20, 76 ALERTIF_BORED = 1 << 21, 77 ALERTIF_TOOMUCHBAGGAGE = 1 << 22, 78 ALERTIF_LEVELUP = 1 << 23, 79 ALERTIF_CONFUSED = 1 << 24, 80 ALERTIF_HITGROUND = 1 << 25, 81 ALERTIF_NOTDROPPED = 1 << 26, 82 ALERTIF_BLOCKED = 1 << 27, 83 ALERTIF_THROWN = 1 << 28, 84 ALERTIF_CRUSHED = 1 << 29, 85 ALERTIF_NOTPUTAWAY = 1 << 30, 86 ALERTIF_TAKENOUT = 1 << 31, 87 88 // add in some aliases 89 ALERTIF_PUTAWAY = ALERTIF_ATLASTWAYPOINT, 90 ALERTIF_NOTTAKENOUT = ALERTIF_NOTPUTAWAY 91 }; 92 93 //-------------------------------------------------------------------------------------------- 94 // struct s_waypoint_list 95 //-------------------------------------------------------------------------------------------- 96 97 #define MAXWAY 8 ///< Waypoints 98 #define WAYTHRESH (GRID_ISIZE >> 1) ///< Threshold for reaching waypoint (GRID_FSIZE/2) 99 100 // swig chokes on the definition below 101 #if defined(SWIG) 102 # define STOR_BITS 4 103 # define STOR_COUNT 16 ///< Storage data (Used in SetXY) 104 # define STOR_AND 15 ///< Storage data bitmask 105 #else 106 # define STOR_BITS 4 107 # define STOR_COUNT (1 << STOR_BITS) ///< Storage data (Used in SetXY) 108 # define STOR_AND (STOR_COUNT - 1) ///< Storage data bitmask 109 #endif 110 111 typedef float waypoint_t[3]; 112 113 struct s_waypoint_list 114 { 115 int tail; ///< Which waypoint 116 int head; ///< Where to stick next 117 waypoint_t pos[MAXWAY]; ///< Waypoint 118 }; 119 typedef struct s_waypoint_list waypoint_list_t; 120 121 bool_t waypoint_list_peek( waypoint_list_t * plst, waypoint_t wp ); 122 bool_t waypoint_list_push( waypoint_list_t * plst, int x, int y ); 123 bool_t waypoint_list_reset( waypoint_list_t * plst ); 124 bool_t waypoint_list_clear( waypoint_list_t * plst ); 125 bool_t waypoint_list_empty( waypoint_list_t * plst ); 126 bool_t waypoint_list_finished( waypoint_list_t * plst ); 127 bool_t waypoint_list_advance( waypoint_list_t * plst ); 128 129 //-------------------------------------------------------------------------------------------- 130 // struct s_ai_state 131 //-------------------------------------------------------------------------------------------- 132 133 /// the state variables for a script / AI 134 struct s_ai_state 135 { 136 // which script to run 137 REF_T type; 138 139 // the execution pointer(s) 140 size_t exe_stt; 141 size_t exe_end; 142 size_t exe_pos; 143 Uint32 opcode; 144 145 // some script states 146 Sint32 poof_time; 147 bool_t changed; 148 bool_t terminate; 149 Uint32 indent; 150 Uint32 indent_last; 151 152 // who are we related to? 153 CHR_REF index; ///< what is the index value of this character 154 CHR_REF target; ///< Who the AI is after 155 CHR_REF owner; ///< The character's owner 156 CHR_REF child; ///< The character's child 157 158 // some local storage 159 BIT_FIELD alert; ///< Alerts for AI script 160 int state; ///< Short term memory for AI 161 int content; ///< More short term memory 162 int passage; ///< The passage associated with this character 163 Uint32 timer; ///< AI Timer 164 int x[STOR_COUNT]; ///< Temporary values... SetXY 165 int y[STOR_COUNT]; 166 167 // ai memory from the last event 168 CHR_REF bumplast; ///< Last character it was bumped by 169 int bumplast_time; ///< The last time that a ALERTIF_BUMPED was sent 170 171 CHR_REF attacklast; ///< Last character it was attacked by 172 CHR_REF hitlast; ///< Last character it hit 173 FACING_T directionlast; ///< Direction of last attack/healing 174 Uint16 damagetypelast; ///< Last damage type 175 CHR_REF lastitemused; ///< The last item the character used 176 CHR_REF target_old; ///< Target in the previous update 177 178 // message handling 179 Uint32 order_value; ///< The last order given the character 180 Uint16 order_counter; ///< The rank of the character on the order chain 181 182 // waypoints 183 bool_t wp_valid; ///< is the current waypoint valid? 184 waypoint_t wp; ///< current waypoint 185 waypoint_list_t wp_lst; ///< Stored waypoints 186 187 // performance monitoring 188 PROFILE_DECLARE_STRUCT; 189 }; 190 typedef struct s_ai_state ai_state_t; 191 192 ai_state_t * ai_state_ctor( ai_state_t * pself ); 193 ai_state_t * ai_state_dtor( ai_state_t * pself ); 194 bool_t ai_state_set_bumplast( ai_state_t * pself, const CHR_REF ichr ); 195 bool_t ai_state_get_wp( ai_state_t * pself ); 196 bool_t ai_state_ensure_wp( ai_state_t * pself ); 197 198 //-------------------------------------------------------------------------------------------- 199 // struct s_script_state 200 //-------------------------------------------------------------------------------------------- 201 202 /// The state of the scripting system 203 /// @delails It is not persistent between one evaluation of a script and another 204 struct s_script_state 205 { 206 int x; 207 int y; 208 int turn; 209 int distance; 210 int argument; 211 int operationsum; 212 }; 213 typedef struct s_script_state script_state_t; 214 215 //-------------------------------------------------------------------------------------------- 216 // FUNCTION PROTOTYPES 217 //-------------------------------------------------------------------------------------------- 218 219 void scr_run_chr_script( const CHR_REF character ); 220 221 void issue_order( const CHR_REF character, Uint32 order ); 222 void issue_special_order( Uint32 order, IDSZ idsz ); 223 void set_alerts( const CHR_REF character ); 224 225 void scripting_system_begin(); 226 void scripting_system_end(); 227