2007-11-25 19:42:40 +00:00
|
|
|
/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */
|
2007-09-25 23:03:15 +00:00
|
|
|
#include "srv_common.h"
|
|
|
|
#include "srv_ctf.h"
|
|
|
|
|
|
|
|
gameobject_ctf::gameobject_ctf()
|
|
|
|
{
|
|
|
|
// fetch flagstands
|
|
|
|
for(int i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
mapres_flagstand *stand;
|
|
|
|
stand = (mapres_flagstand *)map_find_item(MAPRES_FLAGSTAND_RED+i, 0);
|
|
|
|
if(stand)
|
|
|
|
{
|
|
|
|
flag *f = new flag(i);
|
|
|
|
f->stand_pos = vec2(stand->x, stand->y);
|
|
|
|
f->pos = f->stand_pos;
|
|
|
|
flags[i] = f;
|
|
|
|
//dbg_msg("game", "flag at %f,%f", f->pos.x, f->pos.y);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// report massive failure
|
|
|
|
}
|
|
|
|
}
|
2007-11-04 00:19:41 +00:00
|
|
|
|
|
|
|
is_teamplay = true;
|
2007-09-25 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gameobject_ctf::on_player_spawn(class player *p)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-18 23:29:34 +00:00
|
|
|
int gameobject_ctf::on_player_death(class player *victim, class player *killer, int weaponid)
|
2007-09-25 23:03:15 +00:00
|
|
|
{
|
2007-09-26 07:31:14 +00:00
|
|
|
gameobject::on_player_death(victim, killer, weaponid);
|
2007-11-18 23:29:34 +00:00
|
|
|
int had_flag = 0;
|
|
|
|
|
2007-09-25 23:03:15 +00:00
|
|
|
// drop flags
|
|
|
|
for(int fi = 0; fi < 2; fi++)
|
|
|
|
{
|
|
|
|
flag *f = flags[fi];
|
2007-11-18 23:29:34 +00:00
|
|
|
if(f && f->carrying_player == killer)
|
|
|
|
had_flag |= 2;
|
2007-09-25 23:03:15 +00:00
|
|
|
if(f && f->carrying_player == victim)
|
2007-11-18 23:29:34 +00:00
|
|
|
{
|
2007-11-26 19:32:02 +00:00
|
|
|
f->drop_tick = server_tick();
|
2007-09-25 23:03:15 +00:00
|
|
|
f->carrying_player = 0;
|
2007-11-18 23:29:34 +00:00
|
|
|
had_flag |= 1;
|
|
|
|
}
|
2007-09-25 23:03:15 +00:00
|
|
|
}
|
2007-11-18 23:29:34 +00:00
|
|
|
|
|
|
|
return had_flag;
|
2007-09-25 23:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void gameobject_ctf::tick()
|
|
|
|
{
|
|
|
|
gameobject::tick();
|
|
|
|
|
|
|
|
// do flags
|
|
|
|
for(int fi = 0; fi < 2; fi++)
|
|
|
|
{
|
|
|
|
flag *f = flags[fi];
|
|
|
|
|
|
|
|
//
|
|
|
|
if(f->carrying_player)
|
|
|
|
{
|
|
|
|
// update flag position
|
|
|
|
f->pos = f->carrying_player->pos;
|
|
|
|
|
|
|
|
if(flags[fi^1]->at_stand)
|
|
|
|
{
|
|
|
|
if(distance(f->pos, flags[fi^1]->pos) < 24)
|
|
|
|
{
|
|
|
|
// CAPTURE! \o/
|
2007-10-03 21:32:02 +00:00
|
|
|
teamscore[fi^1]++;
|
2007-09-25 23:03:15 +00:00
|
|
|
for(int i = 0; i < 2; i++)
|
|
|
|
flags[i]->reset();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player *players[MAX_CLIENTS];
|
2007-10-28 11:30:25 +00:00
|
|
|
int types[] = {OBJTYPE_PLAYER_CHARACTER};
|
2007-09-25 23:03:15 +00:00
|
|
|
int num = world->find_entities(f->pos, 32.0f, (entity**)players, MAX_CLIENTS, types, 1);
|
|
|
|
for(int i = 0; i < num; i++)
|
|
|
|
{
|
|
|
|
if(players[i]->team == f->team)
|
|
|
|
{
|
|
|
|
// return the flag
|
2007-09-26 07:31:14 +00:00
|
|
|
if(!f->at_stand)
|
|
|
|
f->reset();
|
2007-09-25 23:03:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// take the flag
|
|
|
|
f->at_stand = 0;
|
|
|
|
f->carrying_player = players[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!f->carrying_player)
|
|
|
|
{
|
2007-11-26 19:32:02 +00:00
|
|
|
if(server_tick() > f->drop_tick + SERVER_TICK_SPEED*30)
|
|
|
|
f->reset();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f->vel.y += gravity;
|
|
|
|
move_box(&f->pos, &f->vel, vec2(f->phys_size, f->phys_size), 0.5f);
|
|
|
|
}
|
2007-09-25 23:03:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-10-28 11:30:25 +00:00
|
|
|
// Flag
|
2007-09-25 23:03:15 +00:00
|
|
|
flag::flag(int _team)
|
|
|
|
: entity(OBJTYPE_FLAG)
|
|
|
|
{
|
|
|
|
team = _team;
|
|
|
|
proximity_radius = phys_size;
|
|
|
|
carrying_player = 0x0;
|
|
|
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
// TODO: should this be done here?
|
|
|
|
world->insert_entity(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void flag::reset()
|
|
|
|
{
|
|
|
|
carrying_player = 0;
|
|
|
|
at_stand = 1;
|
|
|
|
pos = stand_pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void flag::snap(int snapping_client)
|
|
|
|
{
|
2007-11-18 23:29:34 +00:00
|
|
|
obj_flag *flag = (obj_flag *)snap_new_item(OBJTYPE_FLAG, team, sizeof(obj_flag));
|
2007-09-25 23:03:15 +00:00
|
|
|
flag->x = (int)pos.x;
|
|
|
|
flag->y = (int)pos.y;
|
|
|
|
flag->team = team;
|
2007-11-18 22:20:35 +00:00
|
|
|
flag->carried_by = -1;
|
2007-09-25 23:03:15 +00:00
|
|
|
|
2007-11-18 23:29:34 +00:00
|
|
|
if(at_stand)
|
|
|
|
flag->carried_by = -2;
|
|
|
|
else if(carrying_player)
|
2007-11-18 22:20:35 +00:00
|
|
|
flag->carried_by = carrying_player->client_id;
|
2007-09-25 23:03:15 +00:00
|
|
|
}
|