fixed weapon switching

This commit is contained in:
Magnus Auvinen 2008-08-27 20:04:07 +00:00
parent ae364d4d29
commit 72ec4f1a9d
5 changed files with 74 additions and 52 deletions

View file

@ -22,19 +22,27 @@ static void con_key_input_counter(void *result, void *user_data)
(*v)++;
*v &= INPUT_STATE_MASK;
}
/*
static void con_key_input_weapon(void *result, void *user_data)
struct INPUTSET
{
int w = (char *)user_data - (char *)0;
CONTROLS *controls;
int *variable;
int value;
};
static void con_key_input_set(void *result, void *user_data)
{
INPUTSET *set = (INPUTSET *)user_data;
if(console_arg_int(result, 0))
input_data.wanted_weapon = w;
*set->variable = set->value;
}
static void con_key_input_nextprev_weapon(void *result, void *user_data)
{
con_key_input_counter(result, user_data);
input_data.wanted_weapon = 0;
}*/
INPUTSET *set = (INPUTSET *)user_data;
con_key_input_counter(result, set->variable);
set->controls->input_data.wanted_weapon = 0;
}
void CONTROLS::on_init()
{
@ -44,16 +52,15 @@ void CONTROLS::on_init()
MACRO_REGISTER_COMMAND("+jump", "", con_key_input_state, &input_data.jump);
MACRO_REGISTER_COMMAND("+hook", "", con_key_input_state, &input_data.hook);
MACRO_REGISTER_COMMAND("+fire", "", con_key_input_counter, &input_data.fire);
/*
MACRO_REGISTER_COMMAND("+weapon1", "", con_key_input_weapon, (void *)1);
MACRO_REGISTER_COMMAND("+weapon2", "", con_key_input_weapon, (void *)2);
MACRO_REGISTER_COMMAND("+weapon3", "", con_key_input_weapon, (void *)3);
MACRO_REGISTER_COMMAND("+weapon4", "", con_key_input_weapon, (void *)4);
MACRO_REGISTER_COMMAND("+weapon5", "", con_key_input_weapon, (void *)5);
MACRO_REGISTER_COMMAND("+nextweapon", "", con_key_input_nextprev_weapon, &input_data.next_weapon);
MACRO_REGISTER_COMMAND("+prevweapon", "", con_key_input_nextprev_weapon, &input_data.prev_weapon);
*/
{ static INPUTSET set = {this, &input_data.wanted_weapon, 1}; MACRO_REGISTER_COMMAND("+weapon1", "", con_key_input_set, (void *)&set); }
{ static INPUTSET set = {this, &input_data.wanted_weapon, 2}; MACRO_REGISTER_COMMAND("+weapon2", "", con_key_input_set, (void *)&set); }
{ static INPUTSET set = {this, &input_data.wanted_weapon, 3}; MACRO_REGISTER_COMMAND("+weapon3", "", con_key_input_set, (void *)&set); }
{ static INPUTSET set = {this, &input_data.wanted_weapon, 4}; MACRO_REGISTER_COMMAND("+weapon4", "", con_key_input_set, (void *)&set); }
{ static INPUTSET set = {this, &input_data.wanted_weapon, 5}; MACRO_REGISTER_COMMAND("+weapon5", "", con_key_input_set, (void *)&set); }
{ static INPUTSET set = {this, &input_data.next_weapon, 0}; MACRO_REGISTER_COMMAND("+nextweapon", "", con_key_input_nextprev_weapon, (void *)&set); }
{ static INPUTSET set = {this, &input_data.prev_weapon, 0}; MACRO_REGISTER_COMMAND("+prevweapon", "", con_key_input_nextprev_weapon, (void *)&set); }
}
int CONTROLS::snapinput(int *data)

View file

@ -239,7 +239,6 @@ void SCOREBOARD::on_render()
if(gameclient.snap.gameobj && gameclient.snap.gameobj->game_over)
do_scoreboard = true;*/
float width = 400*3.0f*gfx_screenaspect();
float height = 400*3.0f;

View file

@ -62,6 +62,9 @@ bool CHARACTER::spawn(PLAYER *player, vec2 pos, int team)
game.world.insert_entity(this);
alive = true;
game.controller->on_character_spawn(this);
return true;
}

View file

@ -10,6 +10,42 @@
#include "gamecontroller.hpp"
#include "gamecontext.hpp"
GAMECONTROLLER::GAMECONTROLLER()
{
// select gametype
if(strcmp(config.sv_gametype, "ctf") == 0)
{
gametype = GAMETYPE_CTF;
dbg_msg("game", "-- Capture The Flag --");
}
else if(strcmp(config.sv_gametype, "tdm") == 0)
{
gametype = GAMETYPE_TDM;
dbg_msg("game", "-- Team Death Match --");
}
else
{
gametype = GAMETYPE_DM;
dbg_msg("game", "-- Death Match --");
}
//
do_warmup(config.sv_warmup);
game_over_tick = -1;
sudden_death = 0;
round_start_tick = server_tick();
round_count = 0;
is_teamplay = false;
teamscore[0] = 0;
teamscore[1] = 0;
num_spawn_points[0] = 0;
num_spawn_points[1] = 0;
num_spawn_points[2] = 0;
}
float GAMECONTROLLER::evaluate_spawn_pos(SPAWNEVAL *eval, vec2 pos)
{
float score = 0.0f;
@ -72,42 +108,10 @@ bool GAMECONTROLLER::can_spawn(PLAYER *player, vec2 *out_pos)
}
*out_pos = eval.pos;
return eval.got;}
GAMECONTROLLER::GAMECONTROLLER()
{
// select gametype
if(strcmp(config.sv_gametype, "ctf") == 0)
{
gametype = GAMETYPE_CTF;
dbg_msg("game", "-- Capture The Flag --");
}
else if(strcmp(config.sv_gametype, "tdm") == 0)
{
gametype = GAMETYPE_TDM;
dbg_msg("game", "-- Team Death Match --");
}
else
{
gametype = GAMETYPE_DM;
dbg_msg("game", "-- Death Match --");
}
//
do_warmup(config.sv_warmup);
game_over_tick = -1;
sudden_death = 0;
round_start_tick = server_tick();
round_count = 0;
is_teamplay = false;
teamscore[0] = 0;
teamscore[1] = 0;
num_spawn_points[0] = 0;
num_spawn_points[1] = 0;
num_spawn_points[2] = 0;
return eval.got;
}
bool GAMECONTROLLER::on_entity(int index, vec2 pos)
{
int type = -1;
@ -301,6 +305,15 @@ int GAMECONTROLLER::on_character_death(class CHARACTER *victim, class PLAYER *ki
return 0;
}
void GAMECONTROLLER::on_character_spawn(class CHARACTER *chr)
{
// give default weapons
chr->weapons[WEAPON_HAMMER].got = 1;
chr->weapons[WEAPON_HAMMER].ammo = -1;
chr->weapons[WEAPON_GUN].got = 1;
chr->weapons[WEAPON_GUN].ammo = 10;
}
void GAMECONTROLLER::do_warmup(int seconds)
{
warmup = seconds*server_tickspeed();

View file

@ -89,7 +89,7 @@ public:
Arguments:
chr - The character that was spawned.
*/
virtual void on_character_spawn(class CHARACTER *chr) {}
virtual void on_character_spawn(class CHARACTER *chr);
/*
Function: on_character_death