From 62d8de08246c9451568445ccaa6cda02fa6d50fa Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 27 Apr 2013 02:28:35 +0000 Subject: [PATCH 1/8] Make main/fireball.c more like D2XR Add general purpose explode_badass_object. Make object_create_egg a thin wrapper for new drop_powerup, which has the same signature as in D2XR. --- main/fireball.c | 58 ++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/main/fireball.c b/main/fireball.c index 2ff12c98c..0c81ac980 100644 --- a/main/fireball.c +++ b/main/fireball.c @@ -214,19 +214,25 @@ object *explode_badass_weapon(object *obj) } -//blows up the player with a badass explosion -//return the explosion object -object *explode_badass_player(object *objp) +object *explode_badass_object(object *objp, fix damage, fix distance, fix force) { object *rval; rval = object_create_badass_explosion(objp, objp->segnum, &objp->pos, objp->size, get_explosion_vclip(objp, 0), - F1_0*50, F1_0*40, F1_0*150, + damage, distance, force, objp-Objects); if (rval) digi_link_sound_to_object(SOUND_BADASS_EXPLOSION, rval-Objects, 0, F1_0); return (rval); + +} + +//blows up the player with a badass explosion +//return the explosion object +object *explode_badass_player(object *objp) +{ + return explode_badass_object(objp, F1_0*50, F1_0*40, F1_0*150); } @@ -655,28 +661,26 @@ void maybe_replace_powerup_with_energy(object *del_obj) } } -// ------------------------------------------------------------------------------------------------------ -// Returns created object number. -int object_create_egg(object *objp) +int drop_powerup(int type, int id, int num, vms_vector *init_vel, vms_vector *pos, int segnum) { int objnum=0, count; object *obj; vms_vector new_velocity, new_pos; fix old_mag; - switch (objp->contains_type) { + switch (type) { case OBJ_POWERUP: - for (count=0; countcontains_count; count++) { + for (count=0; countmtype.phys_info.velocity; - old_mag = vm_vec_mag_quick(&objp->mtype.phys_info.velocity); + new_velocity = *init_vel; + old_mag = vm_vec_mag_quick(init_vel); // We want powerups to move more in network mode. if ((Game_mode & GM_MULTI) && !(Game_mode & GM_MULTI_ROBOTS)) { rand_scale = 4; // extra life powerups are converted to invulnerability in multiplayer, for what is an extra life, anyway? - if (objp->contains_id == POW_EXTRA_LIFE) - objp->contains_id = POW_INVULNERABILITY; + if (id == POW_EXTRA_LIFE) + id = POW_INVULNERABILITY; } else rand_scale = 2; @@ -686,10 +690,10 @@ int object_create_egg(object *objp) // Give keys zero velocity so they can be tracked better in multi - if ((Game_mode & GM_MULTI) && (objp->contains_id >= POW_KEY_BLUE) && (objp->contains_id <= POW_KEY_GOLD)) + if ((Game_mode & GM_MULTI) && (id >= POW_KEY_BLUE) && (id <= POW_KEY_GOLD)) vm_vec_zero(&new_velocity); - new_pos = objp->pos; + new_pos = *pos; // new_pos.x += (d_rand()-16384)*8; // new_pos.y += (d_rand()-16384)*8; // new_pos.z += (d_rand()-16384)*8; @@ -704,7 +708,7 @@ int object_create_egg(object *objp) } #endif - objnum = obj_create( objp->contains_type, objp->contains_id, objp->segnum, &new_pos, &vmd_identity_matrix, Powerup_info[objp->contains_id].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP); + objnum = obj_create( type, id, segnum, &new_pos, &vmd_identity_matrix, Powerup_info[id].size, CT_POWERUP, MT_PHYSICS, RT_POWERUP); if (objnum < 0 ) { Int3(); @@ -750,10 +754,10 @@ int object_create_egg(object *objp) break; case OBJ_ROBOT: - for (count=0; countcontains_count; count++) { + for (count=0; countmtype.phys_info.velocity; - old_mag = vm_vec_mag_quick(&objp->mtype.phys_info.velocity); + new_velocity = *init_vel; + old_mag = vm_vec_mag_quick(init_vel); vm_vec_normalize_quick(&new_velocity); @@ -769,13 +773,13 @@ int object_create_egg(object *objp) vm_vec_normalize_quick(&new_velocity); vm_vec_scale(&new_velocity, (F1_0*32 + old_mag) * rand_scale); - new_pos = objp->pos; + new_pos = *pos; // This is dangerous, could be outside mine. // new_pos.x += (d_rand()-16384)*8; // new_pos.y += (d_rand()-16384)*7; // new_pos.z += (d_rand()-16384)*6; - objnum = obj_create(OBJ_ROBOT, objp->contains_id, objp->segnum, &new_pos, &vmd_identity_matrix, Polygon_models[Robot_info[ObjId[objp->contains_type]].model_num].rad, CT_AI, MT_PHYSICS, RT_POLYOBJ); + objnum = obj_create(OBJ_ROBOT, id, segnum, &new_pos, &vmd_identity_matrix, Polygon_models[Robot_info[ObjId[type]].model_num].rad, CT_AI, MT_PHYSICS, RT_POLYOBJ); if ( objnum < 0 ) { Int3(); @@ -818,12 +822,22 @@ int object_create_egg(object *objp) break; default: - Error("Error: Illegal type (%i) in object spawning.\n", objp->contains_type); + Error("Error: Illegal type (%i) in object spawning.\n", type); } return objnum; } +// ---------------------------------------------------------------------------- +// Returns created object number. +// If object dropped by player, set flag. +int object_create_egg(object *objp) +{ + int rval; + rval = drop_powerup(objp->contains_type, objp->contains_id, objp->contains_count, &objp->mtype.phys_info.velocity, &objp->pos, objp->segnum); + return rval; +} + #if 0 // implemented differently // get maximum number of objects of this type,id that may be created // returns -1 if no maximum From b65272771e48b4bea5909be0e6ac0a925e97e9e8 Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 31 Mar 2013 21:32:58 +0000 Subject: [PATCH 2/8] Add unused ai_restore_state parameter version to match D2X --- main/state.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/state.c b/main/state.c index 32ca05ceb..e3a85b54e 100644 --- a/main/state.c +++ b/main/state.c @@ -1355,7 +1355,7 @@ RetryObjectLoading: Total_countdown_time = Countdown_timer/F0_5; // we do not need to know this, but it should not be 0 either... // Restore the AI state - ai_restore_state( fp, 0, swap ); + ai_restore_state( fp, version, swap ); // Restore the automap visited info if ( Highest_segment_index+1 > MAX_SEGMENTS_ORIGINAL ) From aebc5da4d3d511dca08b9d094e5839f95f8be21f Mon Sep 17 00:00:00 2001 From: Kp Date: Sun, 26 May 2013 01:56:21 +0000 Subject: [PATCH 3/8] Remove variables that were unused-but-set --- editor/ehostage.c | 2 -- main/bmread.c | 15 +++++++-------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/editor/ehostage.c b/editor/ehostage.c index 9e56ccad5..a0595909f 100644 --- a/editor/ehostage.c +++ b/editor/ehostage.c @@ -345,7 +345,6 @@ void hostage_close_window() int hostage_dialog_handler(UI_DIALOG *dlg, d_event *event, hostage_dialog *h) { - fix DeltaTime; fix64 Temp; int keypress = 0; int rval = 0; @@ -392,7 +391,6 @@ int hostage_dialog_handler(UI_DIALOG *dlg, d_event *event, hostage_dialog *h) // A simple frame time counter for spinning the objects... Temp = timer_query(); - DeltaTime = Temp - h->time; h->time = Temp; if (CurrentHostageIndex > -1 ) { diff --git a/main/bmread.c b/main/bmread.c index cdf7b61b3..c5a3ee1f6 100644 --- a/main/bmread.c +++ b/main/bmread.c @@ -1753,11 +1753,12 @@ void bm_read_hostage() void bm_read_hostage_face(int skip, int pc_shareware) { - char *abm_name,*equal_ptr; - int clip_num=-1,sound_num=-1; - fix time=0; + char *equal_ptr; +#ifndef NDEBUG + int clip_num=-1; +#endif - abm_name = strtok( NULL, space ); + strtok( NULL, space ); arg = strtok( NULL, space ); while (arg!=NULL) { @@ -1768,13 +1769,11 @@ void bm_read_hostage_face(int skip, int pc_shareware) // if we have john=cool, arg is 'john' and equal_ptr is 'cool' +#ifndef NDEBUG if (!d_stricmp( arg, "clip_num" )) { clip_num = atoi(equal_ptr); - } else if (!d_stricmp( arg, "time" )) { - time = fl2f(atof(equal_ptr)); - } else if (!d_stricmp( arg, "sound_num" )) { - sound_num = atoi(equal_ptr); } +#endif } arg = strtok( NULL, space ); From 7f6f191059aa2ead2d3b63909185c75c34e06775 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 7 Jul 2012 21:38:03 +0000 Subject: [PATCH 4/8] Treat robot joints as const --- main/ai.c | 4 ++-- main/robot.c | 2 +- main/robot.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/main/ai.c b/main/ai.c index 4e8d4413c..63d5f07cd 100644 --- a/main/ai.c +++ b/main/ai.c @@ -545,7 +545,7 @@ int player_is_visible_from_object(object *objp, vms_vector *pos, fix field_of_vi int do_silly_animation(object *objp) { int objnum = objp-Objects; - jointpos *jp_list; + const jointpos *jp_list; int robot_type, gun_num, robot_state, num_joint_positions; polyobj_info *pobj_info = &objp->rtype.pobj_info; ai_static *aip = &objp->ctype.ai_info; @@ -580,7 +580,7 @@ int do_silly_animation(object *objp) for (joint=0; jointanim_angles[jointnum]; if (jointnum >= Polygon_models[objp->rtype.pobj_info.model_num].n_models) { diff --git a/main/robot.c b/main/robot.c index 18c5590c5..6ee0ca6e8 100644 --- a/main/robot.c +++ b/main/robot.c @@ -134,7 +134,7 @@ void calc_gun_point(vms_vector *gun_point,object *obj,int gun_num) //fills in ptr to list of joints, and returns the number of joints in list //takes the robot type (object id), gun number, and desired state -int robot_get_anim_state(jointpos **jp_list_ptr,int robot_type,int gun_num,int state) +int robot_get_anim_state(const jointpos **jp_list_ptr,int robot_type,int gun_num,int state) { Assert(gun_num <= Robot_info[robot_type].n_guns); diff --git a/main/robot.h b/main/robot.h index 5b69dfc0b..4489b221b 100644 --- a/main/robot.h +++ b/main/robot.h @@ -123,7 +123,7 @@ void calc_gun_point(vms_vector *gun_point,struct object *obj,int gun_num); // On exit: // Returns number of joints in list. // jp_list_ptr is stuffed with a pointer to a static array of joint positions. This pointer is valid forever. -extern int robot_get_anim_state(jointpos **jp_list_ptr,int robot_type,int gun_num,int state); +extern int robot_get_anim_state(const jointpos **jp_list_ptr,int robot_type,int gun_num,int state); /* * reads n robot_info structs from a PHYSFS_file From 12f8dbfd07083ebea9a858f9fe030c34de26eeb0 Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 7 Jul 2012 20:32:47 +0000 Subject: [PATCH 5/8] Make ranking strings const --- main/gamerend.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main/gamerend.c b/main/gamerend.c index ee81f4f84..0b1376380 100644 --- a/main/gamerend.c +++ b/main/gamerend.c @@ -116,7 +116,7 @@ void show_framerate() void show_netplayerinfo() { int x=0, y=0, i=0, color=0, eff=0; - char *eff_strings[]={"trashing","really hurting","seriously effecting","hurting","effecting","tarnishing"}; + static const char *const eff_strings[]={"trashing","really hurting","seriously effecting","hurting","effecting","tarnishing"}; gr_set_current_canvas(NULL); gr_set_curfont(GAME_FONT); From e72a10a5450e72bb2a1a1e18b75e3d5cf56f58cf Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 14 Jul 2012 03:24:56 +0000 Subject: [PATCH 6/8] Mark reticle control data const --- main/gauges.c | 8 ++++---- main/gauges.h | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/main/gauges.c b/main/gauges.c index 2fa4e9ffc..b184c6cc2 100644 --- a/main/gauges.c +++ b/main/gauges.c @@ -1963,7 +1963,7 @@ extern int Missile_gun; extern int allowed_to_fire_laser(void); extern int allowed_to_fire_missile(void); -rgb player_rgb[] = { {15,15,23}, +const rgb player_rgb[] = { {15,15,23}, {27,0,0}, {0,23,0}, {30,11,31}, @@ -1977,9 +1977,9 @@ typedef struct { } xy; //offsets for reticle parts: high-big high-sml low-big low-sml -xy cross_offsets[4] = { {-8,-5}, {-4,-2}, {-4,-2}, {-2,-1} }; -xy primary_offsets[4] = { {-30,14}, {-16,6}, {-15,6}, {-8, 2} }; -xy secondary_offsets[4] = { {-24,2}, {-12,0}, {-12,1}, {-6,-2} }; +static const xy cross_offsets[4] = { {-8,-5}, {-4,-2}, {-4,-2}, {-2,-1} }; +static const xy primary_offsets[4] = { {-30,14}, {-16,6}, {-15,6}, {-8, 2} }; +static const xy secondary_offsets[4] = { {-24,2}, {-12,0}, {-12,1}, {-6,-2} }; //draw the reticle void show_reticle(int reticle_type, int secondary_display) diff --git a/main/gauges.h b/main/gauges.h index eaf477939..2311e7e8e 100644 --- a/main/gauges.h +++ b/main/gauges.h @@ -57,7 +57,7 @@ typedef struct { ubyte r,g,b; } rgb; -extern rgb player_rgb[]; +extern const rgb player_rgb[]; #define GAUGE_HUD_NUMMODES 4 From ab3d0bd39f7a64ef877ad32eee7ee76a267e08be Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 27 Oct 2012 02:27:28 +0000 Subject: [PATCH 7/8] Mark weapon related globals as const --- main/multi.c | 1 - main/weapon.c | 16 ++++++++-------- main/weapon.h | 16 ++++++---------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/main/multi.c b/main/multi.c index 223b56fb4..e77199c2e 100644 --- a/main/multi.c +++ b/main/multi.c @@ -2439,7 +2439,6 @@ multi_send_player_explode(char type) multi_strip_robots(Player_num); } -extern ubyte Secondary_weapon_to_powerup[], Primary_weapon_to_powerup[]; extern int Proximity_dropped; /* diff --git a/main/weapon.c b/main/weapon.c index c01de9c2c..2194c6c7a 100644 --- a/main/weapon.c +++ b/main/weapon.c @@ -31,21 +31,21 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #include "playsave.h" // Convert primary weapons to indices in Weapon_info array. -ubyte Primary_weapon_to_weapon_info[MAX_PRIMARY_WEAPONS] = {0, 11, 12, 13, 14}; -ubyte Secondary_weapon_to_weapon_info[MAX_SECONDARY_WEAPONS] = {8, 15, 16, 17, 18}; +const ubyte Primary_weapon_to_weapon_info[MAX_PRIMARY_WEAPONS] = {0, 11, 12, 13, 14}; +const ubyte Secondary_weapon_to_weapon_info[MAX_SECONDARY_WEAPONS] = {8, 15, 16, 17, 18}; //for each primary weapon, what kind of powerup gives weapon -ubyte Primary_weapon_to_powerup[MAX_PRIMARY_WEAPONS] = {POW_LASER,POW_VULCAN_WEAPON,POW_SPREADFIRE_WEAPON,POW_PLASMA_WEAPON,POW_FUSION_WEAPON}; +const ubyte Primary_weapon_to_powerup[MAX_PRIMARY_WEAPONS] = {POW_LASER,POW_VULCAN_WEAPON,POW_SPREADFIRE_WEAPON,POW_PLASMA_WEAPON,POW_FUSION_WEAPON}; //for each Secondary weapon, what kind of powerup gives weapon -ubyte Secondary_weapon_to_powerup[MAX_SECONDARY_WEAPONS] = {POW_MISSILE_1,POW_HOMING_AMMO_1,POW_PROXIMITY_WEAPON,POW_SMARTBOMB_WEAPON,POW_MEGA_WEAPON}; -int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0}; -ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5}; +const ubyte Secondary_weapon_to_powerup[MAX_SECONDARY_WEAPONS] = {POW_MISSILE_1,POW_HOMING_AMMO_1,POW_PROXIMITY_WEAPON,POW_SMARTBOMB_WEAPON,POW_MEGA_WEAPON}; +const int Primary_ammo_max[MAX_PRIMARY_WEAPONS] = {0, VULCAN_AMMO_MAX, 0, 0, 0}; +const ubyte Secondary_ammo_max[MAX_SECONDARY_WEAPONS] = {20, 10, 10, 5, 5}; weapon_info Weapon_info[MAX_WEAPON_TYPES]; int N_weapon_types=0; sbyte Primary_weapon, Secondary_weapon; int POrderList (int num); int SOrderList (int num); -ubyte DefaultPrimaryOrder[] = { 4, 3, 2, 1, 0, 255 }; -ubyte DefaultSecondaryOrder[] = { 4, 3, 1, 0, 255, 2 }; +static const ubyte DefaultPrimaryOrder[] = { 4, 3, 2, 1, 0, 255 }; +static const ubyte DefaultSecondaryOrder[] = { 4, 3, 1, 0, 255, 2 }; extern ubyte MenuReordering; // ------------------------------------------------------------------------------------ diff --git a/main/weapon.h b/main/weapon.h index 4bdfc9117..984f0d84e 100644 --- a/main/weapon.h +++ b/main/weapon.h @@ -131,21 +131,17 @@ extern void do_weapon_select(int weapon_num, int secondary_flag); extern sbyte Primary_weapon, Secondary_weapon; -extern ubyte Primary_weapon_to_weapon_info[MAX_PRIMARY_WEAPONS]; -extern ubyte Secondary_weapon_to_weapon_info[MAX_SECONDARY_WEAPONS]; +extern const ubyte Primary_weapon_to_weapon_info[MAX_PRIMARY_WEAPONS]; +extern const ubyte Secondary_weapon_to_weapon_info[MAX_SECONDARY_WEAPONS]; //for each primary weapon, what kind of powerup gives weapon -extern ubyte Primary_weapon_to_powerup[MAX_SECONDARY_WEAPONS]; +extern const ubyte Primary_weapon_to_powerup[MAX_SECONDARY_WEAPONS]; //for each Secondary weapon, what kind of powerup gives weapon -extern ubyte Secondary_weapon_to_powerup[MAX_SECONDARY_WEAPONS]; +extern const ubyte Secondary_weapon_to_powerup[MAX_SECONDARY_WEAPONS]; extern void auto_select_weapon(int weapon_type); //parm is primary or secondary extern void select_weapon(int weapon_num, int secondary_flag, int print_message,int wait_for_rearm); -extern char *Primary_weapon_names_short[]; -extern char *Secondary_weapon_names_short[]; -extern char *Primary_weapon_names[]; -extern char *Secondary_weapon_names[]; -extern int Primary_ammo_max[MAX_PRIMARY_WEAPONS]; -extern ubyte Secondary_ammo_max[MAX_PRIMARY_WEAPONS]; +extern const int Primary_ammo_max[MAX_PRIMARY_WEAPONS]; +extern const ubyte Secondary_ammo_max[MAX_PRIMARY_WEAPONS]; #define HAS_WEAPON_FLAG 1 #define HAS_ENERGY_FLAG 2 From 285985b071b383dd4e3561243ed388bd0fe4341f Mon Sep 17 00:00:00 2001 From: Kp Date: Sat, 1 Jun 2013 23:11:29 +0000 Subject: [PATCH 8/8] Move mine_*info fields into #ifdef EDITOR where they belong --- main/gamemine.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main/gamemine.c b/main/gamemine.c index 806a4f635..54bf43de6 100644 --- a/main/gamemine.c +++ b/main/gamemine.c @@ -44,10 +44,6 @@ COPYRIGHT 1993-1998 PARALLAX SOFTWARE CORPORATION. ALL RIGHTS RESERVED. #define REMOVE_EXT(s) (*(strchr( (s), '.' ))='\0') -struct mtfi mine_top_fileinfo; // Should be same as first two fields below... -struct mfi mine_fileinfo; -struct mh mine_header; -struct me mine_editor; int CreateDefaultNewSegment(); int load_mine_data_compiled_new(PHYSFS_file *LoadFile); @@ -57,6 +53,10 @@ int load_mine_data_compiled_new(PHYSFS_file *LoadFile); static char old_tmap_list[MAX_TEXTURES][13]; short tmap_xlate_table[MAX_TEXTURES]; static short tmap_times_used[MAX_TEXTURES]; +struct mtfi mine_top_fileinfo; // Should be same as first two fields below... +struct mfi mine_fileinfo; +struct mh mine_header; +struct me mine_editor; // ----------------------------------------------------------------------------- //loads from an already-open file