Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix slots 2 #1096

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ FortressOne Server
New commands
------------

* `fo_default_weapon 0` default weapon when using +zelx binds
* `fo_hud_cache 1` less resource intensive hud
* `fo_hud_fps 60` set hud refresh rate
* `fo_grentimer_ping_frac 1` fraction of ping to correct for
Expand Down Expand Up @@ -178,7 +179,6 @@ sound files are found in `fortress/sound/hitaudio/` and `fortress/sound/announc
* Prime/throw grenades with one button (/gren1 and /gren2).
* Weapon slots (1-4) where 1 is always primary and 4 is always melee.
* Quick attack aliases (+quick1-4 will switch weapon and fire).
* Set default weapon to select after firing (e.g. `setinfo default_weapon 1`).
* Next/previous weapon (/weapprev and /weapnext).
* Last weapon (/weaplast).
* Remember current weapon and last weapon after dying.
Expand Down
10 changes: 10 additions & 0 deletions csqc/csextradefs.qc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ const vector PLAYER_MAXS = [16, 16, 32];

#define MAP_MAX_CHARS 20

#define SLOT1 1
#define SLOT2 2
#define SLOT3 4
#define SLOT4 8
#define MAX_SLOT_SELECTION_HISTORY_SIZE 10

.void() removefunc;
.float owned_by;
.string netname;
Expand Down Expand Up @@ -108,6 +114,10 @@ entity current_vote;
string vote_list_filter;
float oldbuttons;
float zoomed_in;
float input_slots;
float oldslots;
float slot_selection_history[MAX_SLOT_SELECTION_HISTORY_SIZE];
float slot_selection_history_top;

.string name;
.string description;
Expand Down
95 changes: 95 additions & 0 deletions csqc/main.qc
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,17 @@ noref void(float apiver, string enginename, float enginever) CSQC_Init = {
FO_PP_Init(); // Some of this is always used by custom projectiles.
CsGrenTimer::Init();

slot_selection_history_top = -1;

registercommand("+zel1");
registercommand("-zel1");
registercommand("+zel2");
registercommand("-zel2");
registercommand("+zel3");
registercommand("-zel3");
registercommand("+zel4");
registercommand("-zel4");

registercommand("login");
registercommand("fo_hud_editor");
registercommand("fo_hud_reload");
Expand Down Expand Up @@ -170,6 +181,30 @@ noref float(string cmd) CSQC_ConsoleCommand = {
local float grentype;

switch(argv(0)) {
case "+zel1":
input_slots |= SLOT1;
break;
case "-zel1":
input_slots &= ~SLOT1;
break;
case "+zel2":
input_slots |= SLOT2;
break;
case "-zel2":
input_slots &= ~SLOT2;
break;
case "+zel3":
input_slots |= SLOT3;
break;
case "-zel3":
input_slots &= ~SLOT3;
break;
case "+zel4":
input_slots |= SLOT4;
break;
case "-zel4":
input_slots &= ~SLOT4;
break;
case "login":
FoLogin(argv(1));
break;
Expand Down Expand Up @@ -432,7 +467,67 @@ void() CSQC_Ent_Remove = { //the entity in question left the player's pvs, and
remove(self);
};

void PushSlotSelection(float value) {
if (slot_selection_history_top == MAX_SLOT_SELECTION_HISTORY_SIZE) {
// Stack is full
return;
}

slot_selection_history_top += 1;
slot_selection_history[slot_selection_history_top] = value;
}

float PopSlotSelectionHistoryIf(float slot) {
if (slot_selection_history_top == -1) {
// Stack is empty
return -1;
}

for (float i = slot_selection_history_top; i >= 0; i--) {
if (slot_selection_history[i] == slot) {
for (float j = i+1; j < MAX_SLOT_SELECTION_HISTORY_SIZE; j++) {
slot_selection_history[j-1] = slot_selection_history[j];
}

slot_selection_history[MAX_SLOT_SELECTION_HISTORY_SIZE-1] = 0;
slot_selection_history_top--;
break;
}
}
}

void Handle_Slot_Key(float slot, float impulse) {
if (input_slots & slot) { // slot keydown
PushSlotSelection(impulse);
input_impulse = impulse;
} else { // slot keyup
PopSlotSelectionHistoryIf(impulse);
if (slot_selection_history_top >= 0) {
input_impulse = slot_selection_history[slot_selection_history_top];
} else {
if (CVARF(fo_default_weapon)) {
input_impulse = CVARF(fo_default_weapon);
}
}
}
}

noref void CSQC_Input_Frame() {
local float changed_slots = input_slots ^ oldslots;
oldslots = input_slots;

local float slotdowns = changed_slots & input_buttons;
local float slotups = changed_slots & ~input_buttons;

if (input_slots) { // if using slots, you definitely should be shooting
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isn't actually true, e.g. if you're holding +slot3 as a scout or engy, it shouldn't do anything. likewise if the weapon has no ammo.

input_buttons |= BUTTON0;
}

if (changed_slots & SLOT1) { Handle_Slot_Key(SLOT1, 1); }
if (changed_slots & SLOT2) { Handle_Slot_Key(SLOT2, 2); }
if (changed_slots & SLOT3) { Handle_Slot_Key(SLOT3, 3); }
if (changed_slots & SLOT4) { Handle_Slot_Key(SLOT4, 4); }

local float changed_buttons = input_buttons ^ oldbuttons;
oldbuttons = input_buttons;

Expand Down
1 change: 1 addition & 0 deletions csqc/settings.qc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ DEFCVAR_FLOAT(fo_grentimer, 2); // Sound + Ping adjust
DEFCVAR_STRING(fo_grentimersound, "grentimer.wav");
DEFCVAR_FLOAT(fo_grentimervolume, 1);
DEFCVAR_FLOAT(fo_oldscoreboard, 0);
DEFCVAR_FLOAT(fo_default_weapon, 0);

DEFCVAR_FLOAT(fo_hitaudio_enabled, 1);
DEFCVAR_FLOAT(fo_hitaudio_hurtself, 1);
Expand Down
5 changes: 0 additions & 5 deletions csqc/weapon_predict.qc
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,6 @@ static float CalcPredEnabled(float current_enable,
float server_disable, float server_enable,
float client_value,
float dependent_enabled, string* set_by) {
if (csqc_get_user_setting("dw", "default_weapon", "0")) {
*set_by = "[default_weapon unsupported, talk to newby to fix your " \
"config to not need it]";
return FALSE;
}

if (!dependent_enabled) {
// PP depends on WP, so !WP => !PP
Expand Down
2 changes: 0 additions & 2 deletions share/weapons.qc
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,7 @@ float FO_CanReload(Slot slot) {
return FALSE;
}

void () RestoreDefaultWeapon;
void FO_ReloadSlot(Slot slot, float force) {
RestoreDefaultWeapon();
if (self.tfstate & TFSTATE_RELOADING || IsSlotNull(slot))
return;

Expand Down
8 changes: 0 additions & 8 deletions ssqc/actions.qc
Original file line number Diff line number Diff line change
Expand Up @@ -466,13 +466,6 @@ void (entity pe_player, float f_type) CF_Identify = {
}
};

void () RestoreDefaultWeapon = {
float default_weapon = FO_GetUserSetting(self, "default_weapon", "dw", "0");
if (default_weapon >= 1 && default_weapon <= TF_NUM_SLOTS) {
W_ChangeWeaponSlot(MakeSlot(default_weapon));
}
};

void () TeamFortress_ReloadNext = {
Slot slot = self.current_slot;

Expand All @@ -481,7 +474,6 @@ void () TeamFortress_ReloadNext = {

if (FO_CanReload(slot)) {
FO_ReloadSlot(slot, FALSE);
RestoreDefaultWeapon();
return;
}
} while (!IsSameSlot(slot, self.current_slot));
Expand Down
1 change: 0 additions & 1 deletion ssqc/qw.qc
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ float remote_client_time();
.float building_percentage; // The building percentage shown in status bar
.float fragstreak; // Frag streak
.float caps; // Caps during this game
.float default_weapon; // Weapon to select when not firing

.entity nopickup; // Don't pick up this backpack/ammobox because it doesn't contain any of your ammo types

Expand Down
2 changes: 0 additions & 2 deletions ssqc/tforthlp.qc
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ void () TeamFortress_MOTD = {
TeamFortress_Alias("slot3", TF_IMPULSE_SLOT3, 0);
TeamFortress_Alias("slot4", TF_IMPULSE_SLOT4, 0);

// you shouldn't use these in fte, use setinfo default_weapon and +quick instead
// leaving in to prevent breaking change
TeamFortress_AliasString("+slot1", "impulse 20;+attack");
TeamFortress_AliasString("-slot1", "-attack;impulse 24");
TeamFortress_AliasString("+slot2", "impulse 21;+attack");
Expand Down
9 changes: 0 additions & 9 deletions ssqc/weapons.qc
Original file line number Diff line number Diff line change
Expand Up @@ -2345,15 +2345,6 @@ void () ButtonFrame = {
local float keydowns = changed_buttons & input_buttons;
local float keyups = changed_buttons & ~input_buttons;

// +attack keyup
if (keyups & BUTTON0) {
local float default_weapon = FO_GetUserSetting(self, "default_weapon", "dw", "0");

if (default_weapon >= 1 && default_weapon <= 4) {
self.impulse = InputHandlePyroSlotSwap(self.playerclass, default_weapon);
}
}

// +special every frame
if (input_buttons & BUTTON3) {
if (!cb_prematch && !cease_fire) {
Expand Down