From 57d3f3b34fa1b30ec8e9ee50e4429ca628427f10 Mon Sep 17 00:00:00 2001 From: zicodxx Date: Thu, 10 May 2012 14:39:26 +0200 Subject: [PATCH] Wrote seperate function for weapon autocycling that also cycles through non-autoselect weapons and properly respects super laser; Added option to not autoselect weapon when firing; On the way, smoothed the menu text in misc menu a bit --- CHANGELOG.txt | 1 + main/menu.c | 34 +++++++------- main/playsave.c | 4 ++ main/playsave.h | 1 + main/weapon.c | 118 +++++++++++++++++++++++++----------------------- 5 files changed, 86 insertions(+), 72 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index f1678de62..3573f3e78 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -3,6 +3,7 @@ D2X-Rebirth Changelog 20120510 -------- main/multi.h, main/state.c: Reuse pre-defined player objects when loading coop savestate to revent messup when player amount or orders change in a certain way +main/menu.c, main/playsave.c, main/playsave.h, main/weapon.c: Wrote seperate function for weapon autocycling that also cycles through non-autoselect weapons and properly respects super laser; Added option to not autoselect weapon when firing; On the way, smoothed the menu text in misc menu a bit 20120509 -------- diff --git a/main/menu.c b/main/menu.c index 8e98b7c00..0c878f291 100644 --- a/main/menu.c +++ b/main/menu.c @@ -1886,7 +1886,7 @@ void do_sound_menu() void do_misc_menu() { - newmenu_item m[12]; + newmenu_item m[13]; int i = 0; do { @@ -1898,25 +1898,27 @@ void do_misc_menu() ADD_CHECK(5, "Persistent Debris",PlayerCfg.PersistentDebris); ADD_CHECK(6, "Screenshots w/o HUD",PlayerCfg.PRShot); ADD_CHECK(7, "Movie Subtitles",GameCfg.MovieSubtitles); - ADD_CHECK(8, "Disable redundant pickup messages",PlayerCfg.NoRedundancy); - ADD_CHECK(9, "Only show Player msgs in Multipl.",PlayerCfg.MultiMessages); - ADD_CHECK(10, "Disable Multiplayer Rankings",PlayerCfg.NoRankings); + ADD_CHECK(8, "No redundant pickup messages",PlayerCfg.NoRedundancy); + ADD_CHECK(9, "Show Player chat only (Multi)",PlayerCfg.MultiMessages); + ADD_CHECK(10, "No Rankings (Multi)",PlayerCfg.NoRankings); ADD_CHECK(11, "Free Flight controls in Automap",PlayerCfg.AutomapFreeFlight); + ADD_CHECK(12, "No Weapon Autoselect when firing",PlayerCfg.NoFireAutoselect); i = newmenu_do1( NULL, "Misc Options", sizeof(m)/sizeof(*m), m, NULL, NULL, i ); - PlayerCfg.AutoLeveling = m[0].value; - PlayerCfg.MissileViewEnabled = m[1].value; - PlayerCfg.HeadlightActiveDefault= m[2].value; - PlayerCfg.GuidedInBigWindow = m[3].value; - PlayerCfg.EscortHotKeys = m[4].value; - PlayerCfg.PersistentDebris = m[5].value; - PlayerCfg.PRShot = m[6].value; - GameCfg.MovieSubtitles = m[7].value; - PlayerCfg.NoRedundancy = m[8].value; - PlayerCfg.MultiMessages = m[9].value; - PlayerCfg.NoRankings = m[10].value; - PlayerCfg.AutomapFreeFlight = m[11].value; + PlayerCfg.AutoLeveling = m[0].value; + PlayerCfg.MissileViewEnabled = m[1].value; + PlayerCfg.HeadlightActiveDefault = m[2].value; + PlayerCfg.GuidedInBigWindow = m[3].value; + PlayerCfg.EscortHotKeys = m[4].value; + PlayerCfg.PersistentDebris = m[5].value; + PlayerCfg.PRShot = m[6].value; + GameCfg.MovieSubtitles = m[7].value; + PlayerCfg.NoRedundancy = m[8].value; + PlayerCfg.MultiMessages = m[9].value; + PlayerCfg.NoRankings = m[10].value; + PlayerCfg.AutomapFreeFlight = m[11].value; + PlayerCfg.NoFireAutoselect = m[12].value; } while( i>-1 ); diff --git a/main/playsave.c b/main/playsave.c index 386e53e24..15f4784b6 100644 --- a/main/playsave.c +++ b/main/playsave.c @@ -117,6 +117,7 @@ int new_player_config() PlayerCfg.MultiMessages = 0; PlayerCfg.NoRankings = 0; PlayerCfg.AutomapFreeFlight = 0; + PlayerCfg.NoFireAutoselect = 0; PlayerCfg.AlphaEffects = 0; PlayerCfg.DynLightColor = 0; @@ -291,6 +292,8 @@ int read_player_d2x(char *filename) PlayerCfg.NoRankings = atoi(line); if(!strcmp(word,"AUTOMAPFREEFLIGHT")) PlayerCfg.AutomapFreeFlight = atoi(line); + if(!strcmp(word,"NOFIREAUTOSELECT")) + PlayerCfg.NoFireAutoselect = atoi(line); d_free(word); PHYSFSX_fgets(line,50,f); word=splitword(line,'='); @@ -435,6 +438,7 @@ int write_player_d2x(char *filename) PHYSFSX_printf(fout,"multimessages=%i\n",PlayerCfg.MultiMessages); PHYSFSX_printf(fout,"norankings=%i\n",PlayerCfg.NoRankings); PHYSFSX_printf(fout,"automapfreeflight=%i\n",PlayerCfg.AutomapFreeFlight); + PHYSFSX_printf(fout,"nofireautoselect=%i\n",PlayerCfg.NoFireAutoselect); PHYSFSX_printf(fout,"[end]\n"); PHYSFSX_printf(fout,"[graphics]\n"); PHYSFSX_printf(fout,"alphaeffects=%i\n",PlayerCfg.AlphaEffects); diff --git a/main/playsave.h b/main/playsave.h index 47fe864d1..c9a53d222 100644 --- a/main/playsave.h +++ b/main/playsave.h @@ -73,6 +73,7 @@ typedef struct player_config ubyte MultiMessages; ubyte NoRankings; ubyte AutomapFreeFlight; + ubyte NoFireAutoselect; int AlphaEffects; int DynLightColor; } __pack__ player_config; diff --git a/main/weapon.c b/main/weapon.c index 8bf657e2c..bd760db45 100644 --- a/main/weapon.c +++ b/main/weapon.c @@ -70,10 +70,6 @@ sbyte Primary_weapon, Secondary_weapon; ubyte DefaultPrimaryOrder[]={9,8,7,6,5,4,3,2,1,0,255}; ubyte DefaultSecondaryOrder[]={9,8,4,3,1,5,0,255,7,6,2}; -// Cycling weapon key pressed? - -ubyte Cycling=0; - //allow player to reorder menus? extern ubyte MenuReordering; @@ -225,16 +221,60 @@ void InitWeaponOrdering () void CyclePrimary () { - Cycling=1; - auto_select_weapon (0); - Cycling=0; + int cur_order_slot = POrderList(Primary_weapon), desired_weapon = Primary_weapon, loop=0; + + // some remapping for SUPER LASER which is not an actual weapon type at all + if (Primary_weapon == LASER_INDEX && Players[Player_num].laser_level > MAX_LASER_LEVEL) + cur_order_slot = POrderList(SUPER_LASER_INDEX); + + while (loop<(MAX_PRIMARY_WEAPONS+1)) + { + loop++; + cur_order_slot++; // next slot + if (cur_order_slot >= MAX_PRIMARY_WEAPONS+1) // loop if necessary + cur_order_slot = 0; + if (cur_order_slot == POrderList(255)) // ignore "do not autoselect" + continue; + desired_weapon = PlayerCfg.PrimaryOrder[cur_order_slot]; // now that is the weapon next to our current one + // some remapping for SUPER LASER which is not an actual weapon type at all + if (desired_weapon == LASER_INDEX && Players[Player_num].laser_level > MAX_LASER_LEVEL) + continue; + if (desired_weapon == SUPER_LASER_INDEX) + { + if (Players[Player_num].laser_level <= MAX_LASER_LEVEL) + continue; + else + desired_weapon = LASER_INDEX; + } + // select the weapon if we have it + if (player_has_weapon(desired_weapon, 0) == HAS_ALL) + { + select_weapon(desired_weapon, 0, 1, 1); + return; + } + } } void CycleSecondary () { - Cycling=1; - auto_select_weapon (1); - Cycling=0; + int cur_order_slot = SOrderList(Secondary_weapon), desired_weapon = Secondary_weapon, loop=0; + + while (loop<(MAX_SECONDARY_WEAPONS+1)) + { + loop++; + cur_order_slot++; // next slot + if (cur_order_slot >= MAX_SECONDARY_WEAPONS+1) // loop if necessary + cur_order_slot = 0; + if (cur_order_slot == SOrderList(255)) // ignore "do not autoselect" + continue; + desired_weapon = PlayerCfg.SecondaryOrder[cur_order_slot]; // now that is the weapon next to our current one + // select the weapon if we have it + if (player_has_weapon(desired_weapon, 1) == HAS_ALL) + { + select_weapon(desired_weapon, 1, 1, 1); + return; + } + } } @@ -265,15 +305,6 @@ void select_weapon(int weapon_num, int secondary_flag, int print_message, int wa else Next_laser_fire_time = 0; Global_laser_firing_count = 0; - } else { - // Select super version if available. - if (wait_for_rearm) - { - if (!Cycling) - ; // -- MK, only plays when can't fire weapon anyway, fixes bug -- digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 ); - else - digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 ); - } } Primary_weapon = weapon_num; weapon_name = PRIMARY_WEAPON_NAMES(weapon_num); @@ -298,10 +329,7 @@ void select_weapon(int weapon_num, int secondary_flag, int print_message, int wa } else { if (wait_for_rearm) { - if (!Cycling) digi_play_sample_once( SOUND_ALREADY_SELECTED, F1_0 ); - else - digi_play_sample_once( SOUND_BAD_SELECTION, F1_0 ); } } @@ -399,7 +427,7 @@ void auto_select_weapon(int weapon_type) if (weapon_type==0) { r = player_has_weapon(Primary_weapon, 0); - if (r != HAS_ALL || Cycling) { + if (r != HAS_ALL) { int cur_weapon; int try_again = 1; @@ -413,14 +441,8 @@ void auto_select_weapon(int weapon_type) { if (looped) { - if (!Cycling) - { - HUD_init_message(HM_DEFAULT, TXT_NO_PRIMARY); - select_weapon(0, 0, 0, 1); - } - else - select_weapon (Primary_weapon,0,0,1); - + HUD_init_message(HM_DEFAULT, TXT_NO_PRIMARY); + select_weapon(0, 0, 0, 1); try_again = 0; continue; } @@ -438,15 +460,8 @@ void auto_select_weapon(int weapon_type) // continue; if (PlayerCfg.PrimaryOrder[cur_weapon] == Primary_weapon) { - if (!Cycling) - { - HUD_init_message(HM_DEFAULT, TXT_NO_PRIMARY); - // if (POrderList(0)=4) supposed_weapon=SUPER_LASER_INDEX; // allotment for stupid way of doing super laser - - if (POrderList(weapon_index)Primary_weapon && old_ammo==0 && + if (((Controls.fire_primary_state && PlayerCfg.NoFireAutoselect)?0:1) && Players[Player_num].primary_weapon_flags&(1<Primary_weapon && old_ammo==0 && POrderList(weapon_index)