some server restructure. added hook no attach sound

This commit is contained in:
Magnus Auvinen 2008-09-23 18:08:19 +00:00
parent c10ce4d17b
commit d9d37b945e
15 changed files with 114 additions and 82 deletions

View file

@ -200,6 +200,7 @@ container.sounds.Add(SoundSet("hook_loop", FileList("data/audio/hook_loop-%02d.w
container.sounds.Add(SoundSet("hook_attach_ground", FileList("data/audio/hook_attach-%02d.wv", 3))) container.sounds.Add(SoundSet("hook_attach_ground", FileList("data/audio/hook_attach-%02d.wv", 3)))
container.sounds.Add(SoundSet("hook_attach_player", FileList("data/audio/foley_body_impact-%02d.wv", 3))) container.sounds.Add(SoundSet("hook_attach_player", FileList("data/audio/foley_body_impact-%02d.wv", 3)))
container.sounds.Add(SoundSet("hook_noattach", FileList("data/audio/hook_noattach-%02d.wv", 2)))
container.sounds.Add(SoundSet("pickup_health", FileList("data/audio/sfx_pickup_hrt-%02d.wv", 2))) container.sounds.Add(SoundSet("pickup_health", FileList("data/audio/sfx_pickup_hrt-%02d.wv", 2)))
container.sounds.Add(SoundSet("pickup_armor", FileList("data/audio/sfx_pickup_arm-%02d.wv", 4))) container.sounds.Add(SoundSet("pickup_armor", FileList("data/audio/sfx_pickup_arm-%02d.wv", 4)))

View file

@ -116,6 +116,9 @@ NETSERVER *net;
static void snap_init_id() static void snap_init_id()
{ {
int i; int i;
if(snap_id_inited)
return;
for(i = 0; i < MAX_IDS; i++) for(i = 0; i < MAX_IDS; i++)
{ {
snap_ids[i].next = i+1; snap_ids[i].next = i+1;
@ -911,6 +914,7 @@ static int server_run()
{ {
NETADDR bindaddr; NETADDR bindaddr;
snap_init_id();
net_init(); net_init();
/* */ /* */

View file

@ -683,7 +683,7 @@ void GAMECLIENT::on_predict()
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
//if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos); //if(events&COREEVENT_HOOK_ATTACH_PLAYER) snd_play_random(CHN_WORLD, SOUND_HOOK_ATTACH_PLAYER, 1.0f, pos);
if(events&COREEVENT_HOOK_ATTACH_GROUND) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos); if(events&COREEVENT_HOOK_ATTACH_GROUND) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_ATTACH_GROUND, 1.0f, pos);
if(events&COREEVENT_HOOK_HIT_NOHOOK) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); if(events&COREEVENT_HOOK_HIT_NOHOOK) gameclient.sounds->play(SOUNDS::CHN_WORLD, SOUND_HOOK_NOATTACH, 1.0f, pos);
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
} }
} }

View file

@ -45,8 +45,11 @@ void CHARACTER::reset()
bool CHARACTER::spawn(PLAYER *player, vec2 pos, int team) bool CHARACTER::spawn(PLAYER *player, vec2 pos, int team)
{ {
/*
~CHARACTER();
mem_zero(this, sizeof(CHARACTER)); mem_zero(this, sizeof(CHARACTER));
new(this) CHARACTER(); new(this) CHARACTER();*/
player_state = PLAYERSTATE_UNKNOWN; player_state = PLAYERSTATE_UNKNOWN;
emote_stop = -1; emote_stop = -1;
last_action = -1; last_action = -1;
@ -657,7 +660,7 @@ void CHARACTER::tick_defered()
//if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos); //if(events&COREEVENT_HOOK_LAUNCH) snd_play_random(CHN_WORLD, SOUND_HOOK_LOOP, 1.0f, pos);
if(events&COREEVENT_HOOK_ATTACH_PLAYER) game.create_sound(pos, SOUND_HOOK_ATTACH_PLAYER, cmask_all()); if(events&COREEVENT_HOOK_ATTACH_PLAYER) game.create_sound(pos, SOUND_HOOK_ATTACH_PLAYER, cmask_all());
if(events&COREEVENT_HOOK_ATTACH_GROUND) game.create_sound(pos, SOUND_HOOK_ATTACH_GROUND, mask); if(events&COREEVENT_HOOK_ATTACH_GROUND) game.create_sound(pos, SOUND_HOOK_ATTACH_GROUND, mask);
if(events&COREEVENT_HOOK_HIT_NOHOOK) game.create_sound(pos, SOUND_HOOK_LOOP, mask); if(events&COREEVENT_HOOK_HIT_NOHOOK) game.create_sound(pos, SOUND_HOOK_NOATTACH, mask);
//if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos); //if(events&COREEVENT_HOOK_RETRACT) snd_play_random(CHN_WORLD, SOUND_PLAYER_JUMP, 1.0f, pos);
//} //}
@ -705,7 +708,7 @@ void CHARACTER::die(int killer, int weapon)
{ {
/*if (dead || team == -1) /*if (dead || team == -1)
return;*/ return;*/
int mode_special = game.controller->on_character_death(this, &game.players[killer], weapon); int mode_special = game.controller->on_character_death(this, game.players[killer], weapon);
dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d", dbg_msg("game", "kill killer='%d:%s' victim='%d:%s' weapon=%d special=%d",
killer, server_clientname(killer), killer, server_clientname(killer),
@ -789,7 +792,7 @@ bool CHARACTER::take_damage(vec2 force, int dmg, int from, int weapon)
// do damage hit sound // do damage hit sound
if(from >= 0 && from != player->client_id) if(from >= 0 && from != player->client_id)
game.create_sound(game.players[from].view_pos, SOUND_HIT, cmask_one(from)); game.create_sound(game.players[from]->view_pos, SOUND_HIT, cmask_one(from));
// check for death // check for death
if(health <= 0) if(health <= 0)
@ -799,7 +802,7 @@ bool CHARACTER::take_damage(vec2 force, int dmg, int from, int weapon)
// set attacker's face to happy (taunt!) // set attacker's face to happy (taunt!)
if (from >= 0 && from != player->client_id) if (from >= 0 && from != player->client_id)
{ {
CHARACTER *chr = &game.players[from].character; CHARACTER *chr = game.players[from]->get_character();
chr->emote_type = EMOTE_HAPPY; chr->emote_type = EMOTE_HAPPY;
chr->emote_stop = server_tick() + server_tickspeed(); chr->emote_stop = server_tick() + server_tickspeed();
} }
@ -821,7 +824,7 @@ bool CHARACTER::take_damage(vec2 force, int dmg, int from, int weapon)
void CHARACTER::snap(int snaping_client) void CHARACTER::snap(int snaping_client)
{ {
if(distance(game.players[snaping_client].view_pos, pos) > 1000.0f) if(distance(game.players[snaping_client]->view_pos, pos) > 1000.0f)
return; return;
NETOBJ_CHARACTER *character = (NETOBJ_CHARACTER *)snap_new_item(NETOBJTYPE_CHARACTER, player->client_id, sizeof(NETOBJ_CHARACTER)); NETOBJ_CHARACTER *character = (NETOBJ_CHARACTER *)snap_new_item(NETOBJTYPE_CHARACTER, player->client_id, sizeof(NETOBJ_CHARACTER));

View file

@ -11,7 +11,19 @@
class CHARACTER : public ENTITY class CHARACTER : public ENTITY
{ {
/*static CHARACTER pool_data[MAX_CLIENTS];
static int pool_used[MAX_CLIENTS];*/
public: public:
/*
void operator delete(void *character)
{
(CHARACTER *)character
int id = (CHARACTER *)character - (CHARACTER *)pool_data;
dbg_assert(pool_used[id], "");
pool_used[id] = 0;
mem_zero(&pool_data[id], sizeof(CHARACTER));
}*/
// player controlling this character // player controlling this character
class PLAYER *player; class PLAYER *player;

View file

@ -100,7 +100,7 @@ void LASER::tick()
void LASER::snap(int snapping_client) void LASER::snap(int snapping_client)
{ {
if(distance(game.players[snapping_client].view_pos, pos) > 1000.0f) if(distance(game.players[snapping_client]->view_pos, pos) > 1000.0f)
return; return;
NETOBJ_LASER *obj = (NETOBJ_LASER *)snap_new_item(NETOBJTYPE_LASER, id, sizeof(NETOBJ_LASER)); NETOBJ_LASER *obj = (NETOBJ_LASER *)snap_new_item(NETOBJTYPE_LASER, id, sizeof(NETOBJ_LASER));

View file

@ -100,7 +100,7 @@ void PROJECTILE::snap(int snapping_client)
{ {
float ct = (server_tick()-start_tick)/(float)server_tickspeed(); float ct = (server_tick()-start_tick)/(float)server_tickspeed();
if(distance(game.players[snapping_client].view_pos, get_pos(ct)) > 1000.0f) if(distance(game.players[snapping_client]->view_pos, get_pos(ct)) > 1000.0f)
return; return;
NETOBJ_PROJECTILE *proj = (NETOBJ_PROJECTILE *)snap_new_item(NETOBJTYPE_PROJECTILE, id, sizeof(NETOBJ_PROJECTILE)); NETOBJ_PROJECTILE *proj = (NETOBJ_PROJECTILE *)snap_new_item(NETOBJTYPE_PROJECTILE, id, sizeof(NETOBJ_PROJECTILE));

View file

@ -39,7 +39,7 @@ void EVENTHANDLER::snap(int snapping_client)
if(cmask_is_set(client_masks[i], snapping_client)) if(cmask_is_set(client_masks[i], snapping_client))
{ {
NETEVENT_COMMON *ev = (NETEVENT_COMMON *)&data[offsets[i]]; NETEVENT_COMMON *ev = (NETEVENT_COMMON *)&data[offsets[i]];
if(distance(game.players[snapping_client].view_pos, vec2(ev->x, ev->y)) < 1500.0f) if(distance(game.players[snapping_client]->view_pos, vec2(ev->x, ev->y)) < 1500.0f)
{ {
void *d = snap_new_item(types[i], i, sizes[i]); void *d = snap_new_item(types[i], i, sizes[i]);
mem_copy(d, &data[offsets[i]], sizes[i]); mem_copy(d, &data[offsets[i]], sizes[i]);

View file

@ -7,7 +7,11 @@ GAMECONTEXT game;
GAMECONTEXT::GAMECONTEXT() GAMECONTEXT::GAMECONTEXT()
{ {
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
players[i].init(-1); {
players[i] = 0;
/*players = new PLAYER();
players[i].init(-1);*/
}
} }
GAMECONTEXT::~GAMECONTEXT() GAMECONTEXT::~GAMECONTEXT()
@ -169,7 +173,7 @@ void GAMECONTEXT::send_chat(int chatter_cid, int team, const char *text)
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1 && game.players[i].team == team) if(game.players[i] && game.players[i]->team == team)
server_send_msg(i); server_send_msg(i);
} }
} }
@ -181,10 +185,10 @@ void GAMECONTEXT::send_info(int who, int to_who)
NETMSG_SV_SETINFO msg; NETMSG_SV_SETINFO msg;
msg.cid = who; msg.cid = who;
msg.name = server_clientname(who); msg.name = server_clientname(who);
msg.skin = players[who].skin_name; msg.skin = players[who]->skin_name;
msg.use_custom_color = players[who].use_custom_color; msg.use_custom_color = players[who]->use_custom_color;
msg.color_body = players[who].color_body; msg.color_body = players[who]->color_body;
msg.color_feet = players[who].color_feet; msg.color_feet = players[who]->color_feet;
msg.pack(MSGFLAG_VITAL); msg.pack(MSGFLAG_VITAL);
server_send_msg(to_who); server_send_msg(to_who);
@ -228,8 +232,8 @@ void GAMECONTEXT::tick()
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(players[i].client_id != -1) if(players[i])
players[i].tick(); players[i]->tick();
} }
} }
@ -241,7 +245,7 @@ void GAMECONTEXT::snap(int client_id)
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(players[i].client_id != -1) if(players[i])
players[i].snap(client_id); players[i]->snap(client_id);
} }
} }

View file

@ -37,7 +37,7 @@ public:
void clear(); void clear();
EVENTHANDLER events; EVENTHANDLER events;
PLAYER players[MAX_CLIENTS]; PLAYER *players[MAX_CLIENTS];
GAMECONTROLLER *controller; GAMECONTROLLER *controller;
GAMEWORLD world; GAMEWORLD world;

View file

@ -258,8 +258,8 @@ void GAMECONTROLLER::post_reset()
{ {
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1) if(game.players[i])
game.players[i].respawn(); game.players[i]->respawn();
} }
} }
@ -319,7 +319,7 @@ bool GAMECONTROLLER::is_friendly_fire(int cid1, int cid2)
if(is_teamplay()) if(is_teamplay())
{ {
if(game.players[cid1].team == game.players[cid2].team) if(game.players[cid1]->team == game.players[cid2]->team)
return true; return true;
} }
@ -364,8 +364,8 @@ void GAMECONTROLLER::tick()
int t[2] = {0,0}; int t[2] = {0,0};
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1 && game.players[i].team != -1) if(game.players[i] && game.players[i]->team != -1)
t[game.players[i].team]++; t[game.players[i]->team]++;
} }
int m = (t[0] > t[1]) ? 0 : 1; int m = (t[0] > t[1]) ? 0 : 1;
@ -379,13 +379,13 @@ void GAMECONTROLLER::tick()
int pd = teamscore[m]; int pd = teamscore[m];
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id == -1) if(!game.players[i])
continue; continue;
if(game.players[i].team == m && (!p || abs(scorediff - game.players[i].score) < pd)) if(game.players[i]->team == m && (!p || abs(scorediff - game.players[i]->score) < pd))
{ {
p = &(game.players[i]); p = game.players[i];
pd = abs(scorediff - game.players[i].score); pd = abs(scorediff - game.players[i]->score);
} }
} }
@ -418,8 +418,8 @@ void GAMECONTROLLER::tick()
{ {
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1) if(game.players[i])
prog = max(prog, (game.players[i].score*100)/config.sv_scorelimit); prog = max(prog, (game.players[i]->score*100)/config.sv_scorelimit);
} }
} }
} }
@ -453,7 +453,7 @@ void GAMECONTROLLER::snap(int snapping_client)
gameobj->round_num = (strlen(config.sv_maprotation) || config.sv_rounds_per_map > 1) ? config.sv_rounds_per_map : 0; gameobj->round_num = (strlen(config.sv_maprotation) || config.sv_rounds_per_map > 1) ? config.sv_rounds_per_map : 0;
gameobj->round_current = round_count+1; gameobj->round_current = round_count+1;
gameobj->teamscore_red = is_teamplay() ? teamscore[0] : game.players[snapping_client].score; gameobj->teamscore_red = is_teamplay() ? teamscore[0] : game.players[snapping_client]->score;
gameobj->teamscore_blue = teamscore[1]; gameobj->teamscore_blue = teamscore[1];
} }
@ -462,10 +462,10 @@ int GAMECONTROLLER::get_auto_team(int notthisid)
int numplayers[2] = {0,0}; int numplayers[2] = {0,0};
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1 && game.players[i].client_id != notthisid) if(game.players[i] && i != notthisid)
{ {
if(game.players[i].team == 0 || game.players[i].team == 1) if(game.players[i]->team == 0 || game.players[i]->team == 1)
numplayers[game.players[i].team]++; numplayers[game.players[i]->team]++;
} }
} }
@ -484,10 +484,10 @@ bool GAMECONTROLLER::can_join_team(int team, int notthisid)
int numplayers[2] = {0,0}; int numplayers[2] = {0,0};
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1 && game.players[i].client_id != notthisid) if(game.players[i] && i != notthisid)
{ {
if(game.players[i].team >= 0 || game.players[i].team == 1) if(game.players[i]->team >= 0 || game.players[i]->team == 1)
numplayers[game.players[i].team]++; numplayers[game.players[i]->team]++;
} }
} }
@ -502,8 +502,8 @@ bool GAMECONTROLLER::check_team_balance()
int t[2] = {0, 0}; int t[2] = {0, 0};
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
PLAYER *p = &(game.players[i]); PLAYER *p = game.players[i];
if(p->client_id != -1 && p->team != -1) if(p && p->team != -1)
t[p->team]++; t[p->team]++;
} }
@ -531,8 +531,8 @@ bool GAMECONTROLLER::can_change_team(PLAYER *pplayer, int jointeam)
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
PLAYER *p = &(game.players[i]); PLAYER *p = game.players[i];
if(p->client_id != -1 && p->team != -1) if(p && p->team != -1)
t[p->team]++; t[p->team]++;
} }
@ -563,14 +563,14 @@ void GAMECONTROLLER::do_player_score_wincheck()
int topscore_count = 0; int topscore_count = 0;
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1) if(game.players[i])
{ {
if(game.players[i].score > topscore) if(game.players[i]->score > topscore)
{ {
topscore = game.players[i].score; topscore = game.players[i]->score;
topscore_count = 1; topscore_count = 1;
} }
else if(game.players[i].score == topscore) else if(game.players[i]->score == topscore)
topscore_count++; topscore_count++;
} }
} }

View file

@ -41,7 +41,7 @@ int GAMECONTROLLER_CTF::on_character_death(class CHARACTER *victim, class PLAYER
for(int fi = 0; fi < 2; fi++) for(int fi = 0; fi < 2; fi++)
{ {
FLAG *f = flags[fi]; FLAG *f = flags[fi];
if(f && f->carrying_character == &killer->character) if(f && f->carrying_character == killer->get_character())
had_flag |= 2; had_flag |= 2;
if(f && f->carrying_character == victim) if(f && f->carrying_character == victim)
{ {
@ -139,13 +139,13 @@ void GAMECONTROLLER_CTF::tick()
for(int c = 0; c < MAX_CLIENTS; c++) for(int c = 0; c < MAX_CLIENTS; c++)
{ {
if(game.players[c].client_id == -1) if(!game.players[c])
continue; continue;
if(game.players[c].team == fi) if(game.players[c]->team == fi)
game.create_sound_global(SOUND_CTF_GRAB_EN, game.players[c].client_id); game.create_sound_global(SOUND_CTF_GRAB_EN, game.players[c]->client_id);
else else
game.create_sound_global(SOUND_CTF_GRAB_PL, game.players[c].client_id); game.create_sound_global(SOUND_CTF_GRAB_PL, game.players[c]->client_id);
} }
break; break;
} }

View file

@ -37,13 +37,13 @@ void send_tuning_params(int cid)
void mods_client_direct_input(int client_id, void *input) void mods_client_direct_input(int client_id, void *input)
{ {
if(!game.world.paused) if(!game.world.paused)
game.players[client_id].on_direct_input((NETOBJ_PLAYER_INPUT *)input); game.players[client_id]->on_direct_input((NETOBJ_PLAYER_INPUT *)input);
} }
void mods_client_predicted_input(int client_id, void *input) void mods_client_predicted_input(int client_id, void *input)
{ {
if(!game.world.paused) if(!game.world.paused)
game.players[client_id].on_predicted_input((NETOBJ_PLAYER_INPUT *)input); game.players[client_id]->on_predicted_input((NETOBJ_PLAYER_INPUT *)input);
} }
// Server hooks // Server hooks
@ -60,27 +60,28 @@ void mods_snap(int client_id)
void mods_client_enter(int client_id) void mods_client_enter(int client_id)
{ {
//game.world.insert_entity(&game.players[client_id]); //game.world.insert_entity(&game.players[client_id]);
game.players[client_id].respawn(); game.players[client_id]->respawn();
dbg_msg("game", "join player='%d:%s'", client_id, server_clientname(client_id)); dbg_msg("game", "join player='%d:%s'", client_id, server_clientname(client_id));
char buf[512]; char buf[512];
str_format(buf, sizeof(buf), "%s entered and joined the %s", server_clientname(client_id), game.controller->get_team_name(game.players[client_id].team)); str_format(buf, sizeof(buf), "%s entered and joined the %s", server_clientname(client_id), game.controller->get_team_name(game.players[client_id]->team));
game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), game.players[client_id].team); dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), game.players[client_id]->team);
} }
void mods_connected(int client_id) void mods_connected(int client_id)
{ {
game.players[client_id].init(client_id); game.players[client_id] = new PLAYER(client_id);
//game.players[client_id].init(client_id);
//game.players[client_id].client_id = client_id; //game.players[client_id].client_id = client_id;
// Check which team the player should be on // Check which team the player should be on
if(config.sv_tournament_mode) if(config.sv_tournament_mode)
game.players[client_id].team = -1; game.players[client_id]->team = -1;
else else
game.players[client_id].team = game.controller->get_auto_team(client_id); game.players[client_id]->team = game.controller->get_auto_team(client_id);
(void) game.controller->check_team_balance(); (void) game.controller->check_team_balance();
@ -93,14 +94,15 @@ void mods_connected(int client_id)
void mods_client_drop(int client_id) void mods_client_drop(int client_id)
{ {
game.players[client_id].on_disconnect(); game.players[client_id]->on_disconnect();
(void) game.controller->check_team_balance(); (void) game.controller->check_team_balance();
delete game.players[client_id];
} }
void mods_message(int msgtype, int client_id) void mods_message(int msgtype, int client_id)
{ {
void *rawmsg = netmsg_secure_unpack(msgtype); void *rawmsg = netmsg_secure_unpack(msgtype);
PLAYER *p = &game.players[client_id]; PLAYER *p = game.players[client_id];
if(!rawmsg) if(!rawmsg)
{ {
@ -197,7 +199,7 @@ void mods_message(int msgtype, int client_id)
// send all info to this client // send all info to this client
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1) if(game.players[i])
game.send_info(i, client_id); game.send_info(i, client_id);
} }
@ -293,10 +295,10 @@ static void con_set_team(void *result, void *user_data)
dbg_msg("", "%d %d", client_id, team); dbg_msg("", "%d %d", client_id, team);
if(game.players[client_id].client_id != client_id) if(!game.players[client_id])
return; return;
game.players[client_id].set_team(team); game.players[client_id]->set_team(team);
} }
void mods_console_init() void mods_console_init()
@ -371,7 +373,7 @@ void mods_init()
mods_connected(MAX_CLIENTS-i-1); mods_connected(MAX_CLIENTS-i-1);
mods_client_enter(MAX_CLIENTS-i-1); mods_client_enter(MAX_CLIENTS-i-1);
if(game.controller->is_teamplay()) if(game.controller->is_teamplay())
game.players[MAX_CLIENTS-i-1].team = i&1; game.players[MAX_CLIENTS-i-1]->team = i&1;
} }
} }
} }

View file

@ -5,17 +5,22 @@
#include "player.hpp" #include "player.hpp"
#include "gamecontext.hpp" #include "gamecontext.hpp"
PLAYER::PLAYER() PLAYER::PLAYER(int client_id)
{ {
character = 0;
this->client_id = client_id;
} }
/*
void PLAYER::init(int client_id) void PLAYER::init(int client_id)
{ {
// clear everything // clear everything
~PLAYER();
mem_zero(this, sizeof(*this)); mem_zero(this, sizeof(*this));
new(this) PLAYER(); new(this) PLAYER();
this->client_id = client_id; this->client_id = client_id;
} }*/
void PLAYER::tick() void PLAYER::tick()
{ {
@ -75,9 +80,6 @@ void PLAYER::on_disconnect()
game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf); game.send_chat(-1, GAMECONTEXT::CHAT_ALL, buf);
dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id)); dbg_msg("game", "leave player='%d:%s'", client_id, server_clientname(client_id));
// clear this whole structure
init(-1);
} }
void PLAYER::on_predicted_input(NETOBJ_PLAYER_INPUT *new_input) void PLAYER::on_predicted_input(NETOBJ_PLAYER_INPUT *new_input)
@ -105,16 +107,20 @@ void PLAYER::on_direct_input(NETOBJ_PLAYER_INPUT *new_input)
CHARACTER *PLAYER::get_character() CHARACTER *PLAYER::get_character()
{ {
if(character.alive) if(character && character->alive)
return &character; return character;
return 0; return 0;
} }
void PLAYER::kill_character() void PLAYER::kill_character()
{ {
CHARACTER *chr = get_character(); //CHARACTER *chr = get_character();
if(chr) if(character)
chr->die(-1, -1); {
character->die(-1, -1);
delete character;
character = 0;
}
} }
void PLAYER::respawn() void PLAYER::respawn()
@ -138,12 +144,12 @@ void PLAYER::set_team(int new_team)
score = 0; score = 0;
dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team); dbg_msg("game", "team_join player='%d:%s' team=%d", client_id, server_clientname(client_id), team);
game.controller->on_player_info_change(&game.players[client_id]); game.controller->on_player_info_change(game.players[client_id]);
// send all info to this client // send all info to this client
for(int i = 0; i < MAX_CLIENTS; i++) for(int i = 0; i < MAX_CLIENTS; i++)
{ {
if(game.players[i].client_id != -1) if(game.players[i])
game.send_info(i, -1); game.send_info(i, -1);
} }
} }
@ -162,6 +168,7 @@ void PLAYER::try_respawn()
if(num_ents == 0) if(num_ents == 0)
{ {
spawning = false; spawning = false;
character.spawn(this, spawnpos, team); character = new CHARACTER();
character->spawn(this, spawnpos, team);
} }
} }

View file

@ -7,8 +7,9 @@
// player object // player object
class PLAYER class PLAYER
{ {
CHARACTER *character;
public: public:
PLAYER(); PLAYER(int client_id);
// TODO: clean this up // TODO: clean this up
char skin_name[64]; char skin_name[64];
@ -41,8 +42,6 @@ public:
int max; int max;
} latency; } latency;
CHARACTER character;
// this is used for snapping so we know how we can clip the view for the player // this is used for snapping so we know how we can clip the view for the player
vec2 view_pos; vec2 view_pos;