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 #include "egoboo_math.h" 24 #include "egoboo_process.h" 25 26 //-------------------------------------------------------------------------------------------- 27 //-------------------------------------------------------------------------------------------- 28 struct s_ego_mpd; 29 struct s_camera; 30 struct s_script_state; 31 struct s_mod_file; 32 33 struct s_wawalite_animtile; 34 struct s_wawalite_damagetile; 35 struct s_wawalite_weather; 36 struct s_wawalite_water; 37 struct s_wawalite_fog; 38 39 struct s_menu_process; 40 41 struct s_chr; 42 struct s_prt; 43 struct s_prt_bundle; 44 45 struct s_Import_list; 46 47 //-------------------------------------------------------------------------------------------- 48 //-------------------------------------------------------------------------------------------- 49 50 #define EXPKEEP 0.85f ///< Experience to keep when respawning 51 52 /// The possible pre-defined orders 53 enum e_order 54 { 55 ORDER_NONE = 0, 56 ORDER_ATTACK, 57 ORDER_ASSIST, 58 ORDER_STAND, 59 ORDER_TERRAIN, 60 ORDER_COUNT 61 }; 62 63 //-------------------------------------------------------------------------------------------- 64 65 /// The bitmasks used by the check_target() function which is used in various character search 66 /// functions like chr_find_target() or find_object_in_passage() 67 enum e_targeting_bits 68 { 69 TARGET_DEAD = ( 1 << 0 ), ///< Target dead stuff 70 TARGET_ENEMIES = ( 1 << 1 ), ///< Target enemies 71 TARGET_FRIENDS = ( 1 << 2 ), ///< Target friends 72 TARGET_ITEMS = ( 1 << 3 ), ///< Target items 73 TARGET_INVERTID = ( 1 << 4 ), ///< Target everything but the specified IDSZ 74 TARGET_PLAYERS = ( 1 << 5 ), ///< Target only players 75 TARGET_SKILL = ( 1 << 6 ), ///< Target needs the specified skill IDSZ 76 TARGET_QUEST = ( 1 << 7 ), ///< Target needs the specified quest IDSZ 77 TARGET_SELF = ( 1 << 8 ) ///< Allow self as a target? 78 }; 79 80 //-------------------------------------------------------------------------------------------- 81 // Enums used with the check_time() function to determine if something time or date related is true 82 enum e_time { 83 SEASON_HALLOWEEN, //Is it halloween? 84 SEASON_CHRISTMAS, //Is it christmas time? 85 TIME_NIGHT, //Is it night? 86 TIME_DAY //Is it day? 87 }; 88 89 90 //-------------------------------------------------------------------------------------------- 91 92 /// a process that controls a single game 93 struct s_game_process 94 { 95 process_t base; 96 97 double frameDuration; 98 bool_t mod_paused, pause_key_ready; 99 bool_t was_active; 100 101 int menu_depth; 102 bool_t escape_requested, escape_latch; 103 104 int fps_ticks_next, fps_ticks_now; 105 int ups_ticks_next, ups_ticks_now; 106 107 }; 108 typedef struct s_game_process game_process_t; 109 110 extern game_process_t * GProc; 111 112 //-------------------------------------------------------------------------------------------- 113 //-------------------------------------------------------------------------------------------- 114 //#define TILESOUNDTIME 16 ///< Not used anywhere 115 #define TILE_REAFFIRM_AND 3 116 117 #define MAXWATERLAYER 2 ///< Maximum water layers 118 #define MAXWATERFRAME 512 ///< Maximum number of wave frames 119 #define WATERFRAMEAND (MAXWATERFRAME-1) 120 #define WATERPOINTS 4 ///< Points in a water fan 121 122 //Inventory stuff 123 #define MAXINVENTORY 6 124 #define MAXIMPORTOBJECTS (MAXINVENTORY + 2) ///< left hand + right hand + MAXINVENTORY 125 #define MAXIMPORTPERPLAYER (1 + MAXIMPORTOBJECTS) ///< player + MAXIMPORTOBJECTS 126 127 /// The bitmasks for various in-game actions 128 enum e_latchbutton_bits 129 { 130 LATCHBUTTON_LEFT = ( 1 << 0 ), ///< Character button presses 131 LATCHBUTTON_RIGHT = ( 1 << 1 ), 132 LATCHBUTTON_JUMP = ( 1 << 2 ), 133 LATCHBUTTON_ALTLEFT = ( 1 << 3 ), ///< ( Alts are for grab/drop ) 134 LATCHBUTTON_ALTRIGHT = ( 1 << 4 ), 135 LATCHBUTTON_PACKLEFT = ( 1 << 5 ), ///< ( Packs are for inventory cycle ) 136 LATCHBUTTON_PACKRIGHT = ( 1 << 6 ), 137 LATCHBUTTON_RESPAWN = ( 1 << 7 ) 138 }; 139 140 //-------------------------------------------------------------------------------------------- 141 //-------------------------------------------------------------------------------------------- 142 143 /// The actual state of the animated tiles in-game 144 struct s_animtile_instance 145 { 146 int update_and; ///< New tile every 7 frames 147 Uint16 frame_and; 148 Uint16 base_and; 149 Uint16 frame_add; 150 }; 151 typedef struct s_animtile_instance animtile_instance_t; 152 153 extern Uint32 animtile_update_and; 154 extern animtile_instance_t animtile[2]; 155 156 //-------------------------------------------------------------------------------------------- 157 158 /// The actual in-game state of the damage tiles 159 struct s_damagetile_instance 160 { 161 IPair amount; ///< Amount of damage 162 int damagetype; 163 164 int part_gpip; 165 Uint32 partand; 166 int sound_index; 167 168 //Sint16 sound_time; // this is not used anywhere in the game 169 //Uint16 min_distance; // this is not used anywhere in the game 170 }; 171 typedef struct s_damagetile_instance damagetile_instance_t; 172 extern damagetile_instance_t damagetile; 173 174 //-------------------------------------------------------------------------------------------- 175 176 /// The data descibing the weather state 177 struct s_weather_instance 178 { 179 int timer_reset; ///< How long between each spawn? 180 bool_t over_water; ///< Only spawn over water? 181 int part_gpip; ///< Which particle to spawn? 182 183 PLA_REF iplayer; 184 int time; ///< 0 is no weather 185 }; 186 typedef struct s_weather_instance weather_instance_t; 187 extern weather_instance_t weather; 188 189 //-------------------------------------------------------------------------------------------- 190 191 /// The data descibing the state of a water layer 192 struct s_water_layer_instance 193 { 194 Uint16 frame; ///< Frame 195 Uint32 frame_add; ///< Speed 196 197 float z; ///< Base height of water 198 float amp; ///< Amplitude of waves 199 200 fvec2_t dist; ///< some indication of "how far away" the layer is if it is an overlay 201 202 fvec2_t tx; ///< Coordinates of texture 203 204 float light_dir; ///< direct reflectivity 0 - 1 205 float light_add; ///< ambient reflectivity 0 - 1 206 207 Uint8 alpha; ///< layer transparency 208 209 fvec2_t tx_add; ///< Texture movement 210 }; 211 typedef struct s_water_layer_instance water_instance_layer_t; 212 213 /// The data descibing the water state 214 struct s_water_instance 215 { 216 float surface_level; ///< Surface level for water striders 217 float douse_level; ///< Surface level for torches 218 bool_t is_water; ///< Is it water? ( Or lava... ) 219 bool_t overlay_req; 220 bool_t background_req; 221 bool_t light; ///< Is it light ( default is alpha ) 222 223 float foregroundrepeat; 224 float backgroundrepeat; 225 226 Uint32 spek[256]; ///< Specular highlights 227 228 int layer_count; 229 water_instance_layer_t layer[MAXWATERLAYER]; 230 231 float layer_z_add[MAXWATERLAYER][MAXWATERFRAME][WATERPOINTS]; 232 }; 233 234 typedef struct s_water_instance water_instance_t; 235 extern water_instance_t water; 236 237 //-------------------------------------------------------------------------------------------- 238 239 /// The in-game fog state 240 /// @warn Fog is currently not used 241 struct s_fog_instance 242 { 243 bool_t on; ///< Do ground fog? 244 float top, bottom; 245 Uint8 red, grn, blu; 246 float distance; 247 }; 248 typedef struct s_fog_instance fog_instance_t; 249 extern fog_instance_t fog; 250 251 //-------------------------------------------------------------------------------------------- 252 //-------------------------------------------------------------------------------------------- 253 254 /// the module data that the game needs 255 struct s_game_module 256 { 257 Uint8 importamount; ///< Number of imports for this module 258 bool_t exportvalid; ///< Can it export? 259 bool_t exportreset; ///< Allow to export when module is reset? 260 Uint8 playeramount; ///< How many players? 261 bool_t importvalid; ///< Can it import? 262 bool_t respawnvalid; ///< Can players respawn with Spacebar? 263 bool_t respawnanytime; ///< True if it's a small level... 264 STRING loadname; ///< Module load names 265 266 bool_t active; ///< Is the control loop still going? 267 bool_t beat; ///< Show Module Ended text? 268 Uint32 seed; ///< The module seed 269 Uint32 randsave; 270 }; 271 typedef struct s_game_module game_module_t; 272 273 //-------------------------------------------------------------------------------------------- 274 // Status displays 275 276 #define MAXSTAT 10 ///< Maximum status displays 277 278 extern bool_t StatusList_on; 279 extern int StatusList_count; 280 extern CHR_REF StatusList[MAXSTAT]; 281 282 //-------------------------------------------------------------------------------------------- 283 // End text 284 #define MAXENDTEXT 1024 285 286 extern char endtext[MAXENDTEXT]; ///< The end-module text 287 extern size_t endtext_carat; 288 289 //-------------------------------------------------------------------------------------------- 290 // Imports 291 292 struct s_Import_element 293 { 294 STRING srcDir; 295 STRING dstDir; 296 STRING name; 297 298 size_t player; ///< Which player is this? 299 BIT_FIELD bits; ///< Input bits for this player 300 int slot; ///< which slot it it to be loaded into 301 }; 302 typedef struct s_Import_element Import_element_t; 303 304 bool_t Import_element_init( Import_element_t * ); 305 306 //-------------------------------------------------------------------------------------------- 307 #define MAX_IMPORTS 16 308 309 struct s_Import_list 310 { 311 size_t count; ///< Number of imports 312 Import_element_t lst[MAX_IMPORTS]; 313 }; 314 typedef struct s_Import_list Import_list_t; 315 316 #define IMPORT_LIST_INIT {0} 317 318 bool_t Import_list_init( Import_list_t * ); 319 egoboo_rv Import_list_from_players( Import_list_t * imp_lst ); 320 321 //-------------------------------------------------------------------------------------------- 322 //-------------------------------------------------------------------------------------------- 323 324 extern bool_t overrideslots; ///< Override existing slots? 325 326 extern struct s_ego_mpd * PMesh; 327 extern struct s_camera * PCamera; 328 extern struct s_game_module * PMod; 329 330 /// Pitty stuff 331 struct s_pit_info 332 { 333 bool_t kill; ///< Do they kill? 334 bool_t teleport; ///< Do they teleport? 335 fvec3_t teleport_pos; 336 }; 337 typedef struct s_pit_info pit_info_t; 338 339 extern pit_info_t pits; 340 341 extern FACING_T glouseangle; ///< actually still used 342 343 extern bool_t activate_spawn_file_active; 344 345 extern Import_list_t ImportList; 346 347 //-------------------------------------------------------------------------------------------- 348 //-------------------------------------------------------------------------------------------- 349 350 /// the hook for deinitializing an old module 351 void game_quit_module(); 352 353 /// the hook for exporting all the current players and reloading them 354 bool_t game_update_imports(); 355 void game_finish_module(); 356 bool_t game_begin_module( const char * modname, Uint32 seed ); 357 358 /// Exporting stuff 359 egoboo_rv export_one_character( const CHR_REF character, const CHR_REF owner, int chr_obj_index, bool_t is_local ); 360 egoboo_rv export_all_players( bool_t require_local ); 361 362 /// Messages 363 void show_stat( int statindex ); 364 void show_armor( int statindex ); 365 void show_full_status( int statindex ); 366 void show_magic_status( int statindex ); 367 368 /// End Text 369 void reset_end_text(); 370 371 /// Particles 372 int number_of_attached_particles( const CHR_REF character ); 373 int spawn_bump_particles( const CHR_REF character, const PRT_REF particle ); 374 struct s_prt * place_particle_at_vertex( struct s_prt * pprt, const CHR_REF character, int vertex_offset ); 375 void disaffirm_attached_particles( const CHR_REF character ); 376 int reaffirm_attached_particles( const CHR_REF character ); 377 378 /// Statlist 379 void statlist_add( const CHR_REF character ); 380 void statlist_move_to_top( const CHR_REF character ); 381 void statlist_sort(); 382 383 /// Player 384 void set_one_player_latch( const PLA_REF player ); 385 bool_t add_player( const CHR_REF character, const PLA_REF player, Uint32 device ); 386 387 /// AI targeting 388 CHR_REF chr_find_target( struct s_chr * psrc, float max_dist, IDSZ idsz, BIT_FIELD targeting_bits ); 389 CHR_REF prt_find_target( float pos_x, float pos_y, float pos_z, FACING_T facing, 390 const PIP_REF particletype, const TEAM_REF team, const CHR_REF donttarget, const CHR_REF oldtarget ); 391 392 /// object initialization 393 void free_all_objects( void ); 394 395 /// Data 396 struct s_ego_mpd * set_PMesh( struct s_ego_mpd * pmpd ); 397 struct s_camera * set_PCamera( struct s_camera * pcam ); 398 399 bool_t upload_animtile_data( animtile_instance_t pinst[], struct s_wawalite_animtile * pdata, size_t animtile_count ); 400 bool_t upload_damagetile_data( damagetile_instance_t * pinst, struct s_wawalite_damagetile * pdata ); 401 bool_t upload_weather_data( weather_instance_t * pinst, struct s_wawalite_weather * pdata ); 402 bool_t upload_water_data( water_instance_t * pinst, struct s_wawalite_water * pdata ); 403 bool_t upload_fog_data( fog_instance_t * pinst, struct s_wawalite_fog * pdata ); 404 405 float get_mesh_level( struct s_ego_mpd * pmesh, float x, float y, bool_t waterwalk ); 406 407 bool_t make_water( water_instance_t * pinst, struct s_wawalite_water * pdata ); 408 409 bool_t game_choose_module( int imod, int seed ); 410 411 int game_do_menu( struct s_menu_process * mproc ); 412 game_process_t * game_process_init( game_process_t * gproc ); 413 414 void expand_escape_codes( const CHR_REF ichr, struct s_script_state * pstate, char * src, char * src_end, char * dst, char * dst_end ); 415 416 void upload_wawalite(); 417 418 bool_t game_module_setup( game_module_t * pinst, struct s_mod_file * pdata, const char * loadname, Uint32 seed ); 419 bool_t game_module_init( game_module_t * pinst ); 420 bool_t game_module_reset( game_module_t * pinst, Uint32 seed ); 421 bool_t game_module_start( game_module_t * pinst ); 422 bool_t game_module_stop( game_module_t * pinst ); 423 424 bool_t check_target( struct s_chr * psrc, const CHR_REF ichr_test, IDSZ idsz, BIT_FIELD targeting_bits ); 425 426 void attach_all_particles(); 427 428 struct s_wawalite_data * read_wawalite(); 429 bool_t write_wawalite( const char *modname, struct s_wawalite_data * pdata ); 430 431 Uint8 get_alpha( int alpha, float seeinvis_mag ); 432 Uint8 get_light( int alpha, float seedark_mag ); 433 434 bool_t do_shop_drop( const CHR_REF idropper, const CHR_REF iitem ); 435 436 bool_t do_shop_buy( const CHR_REF ipicker, const CHR_REF ichr ); 437 bool_t do_shop_steal( const CHR_REF ithief, const CHR_REF iitem ); 438 bool_t can_grab_item_in_shop( const CHR_REF ichr, const CHR_REF iitem ); 439 440 bool_t get_chr_regeneration( struct s_chr * pchr, int *pliferegen, int * pmanaregen ); 441 442 float get_chr_level( struct s_ego_mpd * pmesh, struct s_chr * pchr ); 443 444 int do_game_proc_run( game_process_t * gproc, double frameDuration ); 445 446 egoboo_rv move_water( water_instance_t * pwater ); 447 448 void disenchant_character( const CHR_REF ichr ); 449 450 // manage the game's vfs mount points 451 bool_t game_setup_vfs_paths( const char * mod_path ); 452 453 void cleanup_character_enchants( struct s_chr * pchr ); 454 455 bool_t attach_one_particle( struct s_prt_bundle * pbdl_prt ); 456 457 bool_t attach_chr_to_platform( struct s_chr * pchr, struct s_chr * pplat ); 458 bool_t attach_prt_to_platform( struct s_prt * pprt, struct s_chr * pplat ); 459 460 bool_t detach_character_from_platform( struct s_chr * pchr ); 461 bool_t detach_particle_from_platform( struct s_prt * pprt ); 462 463 egoboo_rv game_copy_imports( struct s_Import_list * imp_lst ); 464 465 bool_t check_time( Uint32 check ); 466