mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-10 01:58:19 +00:00
made stuff for ctf. all editor stuff for it is done. the ctf logic has to be written.
This commit is contained in:
parent
0e7054a24a
commit
c919da6640
|
@ -119,5 +119,4 @@ const array:int sound = sounds.*
|
||||||
const array:int image = images.*
|
const array:int image = images.*
|
||||||
const array:int sprite = sprites.*.*
|
const array:int sprite = sprites.*.*
|
||||||
const array:int anim = animations.*
|
const array:int anim = animations.*
|
||||||
const array:int gametype = playerstats.*
|
|
||||||
const array:int powerup = powerups.*
|
const array:int powerup = powerups.*
|
|
@ -1,6 +1,5 @@
|
||||||
const array:int sound = sounds.*
|
const array:int sound = sounds.*
|
||||||
const array:int weapon = weapons.*
|
const array:int weapon = weapons.*
|
||||||
const array:int gametype = playerstats.*
|
|
||||||
const array:int powerup = powerups.*
|
const array:int powerup = powerups.*
|
||||||
|
|
||||||
struct weapon {
|
struct weapon {
|
||||||
|
@ -21,13 +20,7 @@ struct powerupinf {
|
||||||
int startspawntime = startspawntime@1
|
int startspawntime = startspawntime@1
|
||||||
}
|
}
|
||||||
|
|
||||||
struct playerstats {
|
|
||||||
int maxhealth = maxhealth@1
|
|
||||||
int maxarmor = maxarmor@1
|
|
||||||
}
|
|
||||||
|
|
||||||
struct data_container {
|
struct data_container {
|
||||||
array:weapon weapons = weapons.*
|
array:weapon weapons = weapons.*
|
||||||
array:playerstats playerinfo = playerstats.*
|
|
||||||
array:powerupinf powerupinfo = powerups.*
|
array:powerupinf powerupinfo = powerups.*
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include <engine/system.h>
|
#include <engine/system.h>
|
||||||
|
@ -21,28 +22,31 @@ struct ent_type
|
||||||
{
|
{
|
||||||
const char *name;
|
const char *name;
|
||||||
int id;
|
int id;
|
||||||
int item_id;
|
int numfields;
|
||||||
|
int fields[8];
|
||||||
};
|
};
|
||||||
|
|
||||||
static ent_type ent_types[] = {
|
static ent_type ent_types[] = {
|
||||||
{"spawn", MAPRES_SPAWNPOINT, 0},
|
{"null", 0, 0, {0}},
|
||||||
{"spawn_red", MAPRES_SPAWNPOINT_RED, 0},
|
{"---", 0, 0, {0}},
|
||||||
{"spawn_blue", MAPRES_SPAWNPOINT_BLUE, 0},
|
{"spawn", MAPRES_SPAWNPOINT, 0, {0}},
|
||||||
{"---", 0, 0},
|
{"spawn_red", MAPRES_SPAWNPOINT_RED, 0, {0}},
|
||||||
{"flagstand_red", MAPRES_SPAWNPOINT_RED, 0},
|
{"spawn_blue", MAPRES_SPAWNPOINT_BLUE, 0, {0}},
|
||||||
{"flagstand_blue", MAPRES_SPAWNPOINT_BLUE, 0},
|
{"---", 0, 0, {0}},
|
||||||
{"---", 0, 0},
|
{"flagstand_red", MAPRES_FLAGSTAND_RED, 0, {0}},
|
||||||
{"gun", MAPRES_ITEM, ITEM_WEAPON_GUN},
|
{"flagstand_blue", MAPRES_FLAGSTAND_BLUE, 0, {0}},
|
||||||
{"shotgun", MAPRES_ITEM, ITEM_WEAPON_SHOTGUN},
|
{"---", 0, 0, {0}},
|
||||||
{"rocket", MAPRES_ITEM, ITEM_WEAPON_ROCKET},
|
{"gun", MAPRES_ITEM, 1, {ITEM_WEAPON_GUN,0}},
|
||||||
{"sniper", MAPRES_ITEM, ITEM_WEAPON_SNIPER},
|
{"shotgun", MAPRES_ITEM, 1, {ITEM_WEAPON_SHOTGUN,0}},
|
||||||
{"hammer", MAPRES_ITEM, ITEM_WEAPON_HAMMER},
|
{"rocket", MAPRES_ITEM, 1, {ITEM_WEAPON_ROCKET,0}},
|
||||||
{"---", 0, 0},
|
{"sniper", MAPRES_ITEM, 1, {ITEM_WEAPON_SNIPER,0}},
|
||||||
{"health", MAPRES_ITEM, ITEM_HEALTH},
|
{"hammer", MAPRES_ITEM, 1, {ITEM_WEAPON_HAMMER,0}},
|
||||||
{"armor", MAPRES_ITEM, ITEM_ARMOR},
|
{"---", 0, 0, {0}},
|
||||||
{"---", 0, 0},
|
{"health", MAPRES_ITEM, 1, {ITEM_HEALTH,0}},
|
||||||
{"ninja", MAPRES_ITEM, ITEM_NINJA},
|
{"armor", MAPRES_ITEM, 1, {ITEM_ARMOR,0}},
|
||||||
{0, 0}
|
{"---", 0, 0, {0}},
|
||||||
|
{"ninja", MAPRES_ITEM, 1, {ITEM_NINJA,0}},
|
||||||
|
{0, 0, 0, {0}}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -904,6 +908,10 @@ static void editor_render()
|
||||||
{
|
{
|
||||||
int x = (int)(world_offset_x+400*zoom/2)/32*32+16;
|
int x = (int)(world_offset_x+400*zoom/2)/32*32+16;
|
||||||
int y = (int)(world_offset_y+300*zoom/2)/32*32+16;
|
int y = (int)(world_offset_y+300*zoom/2)/32*32+16;
|
||||||
|
|
||||||
|
if(editor_selected_ent >= 0 && editor_selected_ent < ents_count())
|
||||||
|
ents_new(ents_get(editor_selected_ent)->type, x, y);
|
||||||
|
else
|
||||||
ents_new(0, x, y);
|
ents_new(0, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -955,46 +963,33 @@ int editor_load(const char *filename)
|
||||||
}
|
}
|
||||||
|
|
||||||
// load entities
|
// load entities
|
||||||
|
for(int t = MAPRES_ENTS_START; t < MAPRES_ENTS_END; t++)
|
||||||
{
|
{
|
||||||
int type = -1;
|
// fetch entities of this class
|
||||||
for(int i = 0; ent_types[i].name; i++)
|
int start, num;
|
||||||
|
datafile_get_type(df, t, &start, &num);
|
||||||
|
|
||||||
|
for(int i = 0; i < num; i++)
|
||||||
{
|
{
|
||||||
if(ent_types[i].id == MAPRES_SPAWNPOINT)
|
mapres_entity *e = (mapres_entity *)datafile_get_item(df, start+i,0,0);
|
||||||
|
|
||||||
|
// map type
|
||||||
|
int type = 0;
|
||||||
|
for(int k = 0; ent_types[k].name; k++)
|
||||||
{
|
{
|
||||||
type = i;
|
if(ent_types[k].id == t &&
|
||||||
|
memcmp(ent_types[k].fields, e->data, ent_types[k].numfields*sizeof(int)) == 0)
|
||||||
|
{
|
||||||
|
type = k;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int start, num;
|
//dbg_msg("editor", "ent type=%d pos=(%d,%d)", type, e->x, e->y);
|
||||||
datafile_get_type(df, MAPRES_SPAWNPOINT, &start, &num);
|
ents_new(type, e->x, e->y);
|
||||||
for(int t = 0; t < num; t++)
|
|
||||||
{
|
|
||||||
mapres_spawnpoint *sp = (mapres_spawnpoint *)datafile_get_item(df, start+t,0,0);
|
|
||||||
ents_new(type, sp->x, sp->y);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
|
||||||
int start, num;
|
|
||||||
datafile_get_type(df, MAPRES_ITEM, &start, &num);
|
|
||||||
for(int t = 0; t < num; t++)
|
|
||||||
{
|
|
||||||
mapres_item *it = (mapres_item *)datafile_get_item(df, start+t,0,0);
|
|
||||||
|
|
||||||
int type = -1;
|
|
||||||
for(int i = 0; ent_types[i].name; i++)
|
|
||||||
{
|
|
||||||
if(ent_types[i].id == MAPRES_ITEM && ent_types[i].item_id == it->type)
|
|
||||||
{
|
|
||||||
type = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ents_new(type, it->x, it->y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1056,33 +1051,23 @@ int editor_save(const char *filename)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add spawnpoints
|
// add entities
|
||||||
for(int i = 0, id = 0; i < ents_count(); i++)
|
for(int t = MAPRES_ENTS_START; t < MAPRES_ENTS_END; t++)
|
||||||
|
{
|
||||||
|
int id = 0;
|
||||||
|
for(int i = 0; i < ents_count(); i++)
|
||||||
{
|
{
|
||||||
entity *ent = ents_get(i);
|
entity *ent = ents_get(i);
|
||||||
if(ent->type >= 0 && ent_types[ent->type].id == MAPRES_SPAWNPOINT)
|
if(ent_types[ent->type].id != t)
|
||||||
{
|
continue;
|
||||||
mapres_spawnpoint sp;
|
|
||||||
sp.x = ent->x;
|
|
||||||
sp.y = ent->y;
|
|
||||||
sp.type = 0;
|
|
||||||
datafile_add_item(df, MAPRES_SPAWNPOINT, id, sizeof(sp), &sp);
|
|
||||||
id++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// add items
|
int savebuf[64];
|
||||||
for(int i = 0, id = 0; i < ents_count(); i++)
|
mapres_entity *mapent = (mapres_entity *)savebuf;
|
||||||
{
|
mapent->x = ent->x;
|
||||||
entity *ent = ents_get(i);
|
mapent->y = ent->y;
|
||||||
if(ent->type >= 0 && ent_types[ent->type].id == MAPRES_ITEM)
|
dbg_msg("editor", "saving ent idx=%d pos=(%d,%d)", i, ent->x, ent->y);
|
||||||
{
|
memcpy(mapent->data, ent_types[ent->type].fields, ent_types[ent->type].numfields*sizeof(int));
|
||||||
mapres_item it;
|
datafile_add_item(df, t, id, (ent_types[ent->type].numfields+2)*sizeof(int), mapent);
|
||||||
it.x = ent->x;
|
|
||||||
it.y = ent->y;
|
|
||||||
it.type = ent_types[ent->type].item_id;
|
|
||||||
dbg_msg("editor", "i mapped=%d type=%x", ent->type, it.type);
|
|
||||||
datafile_add_item(df, MAPRES_ITEM, id, sizeof(it), &it);
|
|
||||||
id++;
|
id++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1099,7 +1084,7 @@ static int editor_loop()
|
||||||
int mouse_x = 0;
|
int mouse_x = 0;
|
||||||
int mouse_y = 0;
|
int mouse_y = 0;
|
||||||
|
|
||||||
//input::set_mouse_mode(input::mode_relative);
|
inp_mouse_mode_relative();
|
||||||
|
|
||||||
while(!(inp_key_pressed(KEY_LCTRL) && inp_key_pressed('Q')))
|
while(!(inp_key_pressed(KEY_LCTRL) && inp_key_pressed('Q')))
|
||||||
{
|
{
|
||||||
|
@ -1164,12 +1149,10 @@ static int editor_loop()
|
||||||
gfx_swap();
|
gfx_swap();
|
||||||
|
|
||||||
//
|
//
|
||||||
/*
|
|
||||||
if(inp_key_pressed(KEY_F1))
|
if(inp_key_pressed(KEY_F1))
|
||||||
input::set_mouse_mode(input::mode_absolute);
|
inp_mouse_mode_absolute();
|
||||||
if(inp_key_pressed(KEY_F2))
|
if(inp_key_pressed(KEY_F2))
|
||||||
input::set_mouse_mode(input::mode_relative);
|
inp_mouse_mode_relative();
|
||||||
*/
|
|
||||||
|
|
||||||
// mode switch
|
// mode switch
|
||||||
if(inp_key_down(KEY_TAB))
|
if(inp_key_down(KEY_TAB))
|
||||||
|
|
|
@ -399,6 +399,13 @@ int datafile_add_item(DATAFILE_OUT *df, int type, int id, int size, void *data)
|
||||||
df->items[df->num_items].id = id;
|
df->items[df->num_items].id = id;
|
||||||
df->items[df->num_items].size = size;
|
df->items[df->num_items].size = size;
|
||||||
|
|
||||||
|
/*
|
||||||
|
dbg_msg("datafile", "added item type=%d id=%d size=%d", type, id, size);
|
||||||
|
int i;
|
||||||
|
for(i = 0; i < size/4; i++)
|
||||||
|
dbg_msg("datafile", "\t%d: %08x %d", i, ((int*)data)[i], ((int*)data)[i]);
|
||||||
|
*/
|
||||||
|
|
||||||
/* copy data */
|
/* copy data */
|
||||||
df->items[df->num_items].data = mem_alloc(size, 1);
|
df->items[df->num_items].data = mem_alloc(size, 1);
|
||||||
mem_copy(df->items[df->num_items].data, data, size);
|
mem_copy(df->items[df->num_items].data, data, size);
|
||||||
|
|
|
@ -789,7 +789,7 @@ static void render_flag(const obj_flag *prev, const obj_flag *current)
|
||||||
float size = 64.0f;
|
float size = 64.0f;
|
||||||
|
|
||||||
gfx_blend_normal();
|
gfx_blend_normal();
|
||||||
gfx_texture_set(0);
|
gfx_texture_set(-1);
|
||||||
gfx_quads_begin();
|
gfx_quads_begin();
|
||||||
|
|
||||||
gfx_quads_setrotation(angle);
|
gfx_quads_setrotation(angle);
|
||||||
|
@ -805,7 +805,7 @@ static void render_flag(const obj_flag *prev, const obj_flag *current)
|
||||||
0, // starty
|
0, // starty
|
||||||
1, // endx
|
1, // endx
|
||||||
1); // endy
|
1); // endy
|
||||||
gfx_quads_drawTL(pos.x,pos.y,size,size);
|
gfx_quads_draw(pos.x,pos.y,size,size);
|
||||||
gfx_quads_end();
|
gfx_quads_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1075,7 +1075,7 @@ static void render_player(const obj_player *prev, const obj_player *player)
|
||||||
if(player->health < 0) // dont render dead players
|
if(player->health < 0) // dont render dead players
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int skin = gametype == GAMETYPE_TDM ? skinseed + player->team : player->clientid;
|
int skin = gametype == GAMETYPE_DM ? player->clientid : skinseed + player->team;
|
||||||
|
|
||||||
vec2 direction = get_direction(player->angle);
|
vec2 direction = get_direction(player->angle);
|
||||||
float angle = player->angle/256.0f;
|
float angle = player->angle/256.0f;
|
||||||
|
|
|
@ -27,10 +27,15 @@ inline float get_angle(vec2 dir)
|
||||||
inline bool col_check_point(float x, float y) { return col_check_point((int)x, (int)y) != 0; }
|
inline bool col_check_point(float x, float y) { return col_check_point((int)x, (int)y) != 0; }
|
||||||
inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); }
|
inline bool col_check_point(vec2 p) { return col_check_point(p.x, p.y); }
|
||||||
|
|
||||||
|
struct mapres_entity
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
int data[];
|
||||||
|
};
|
||||||
|
|
||||||
struct mapres_spawnpoint
|
struct mapres_spawnpoint
|
||||||
{
|
{
|
||||||
int x, y;
|
int x, y;
|
||||||
int type;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct mapres_item
|
struct mapres_item
|
||||||
|
@ -39,14 +44,21 @@ struct mapres_item
|
||||||
int type;
|
int type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct mapres_flagstand
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
};
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
|
MAPRES_ENTS_START=1,
|
||||||
MAPRES_SPAWNPOINT=1,
|
MAPRES_SPAWNPOINT=1,
|
||||||
MAPRES_ITEM=2,
|
MAPRES_ITEM=2,
|
||||||
MAPRES_SPAWNPOINT_RED=2,
|
MAPRES_SPAWNPOINT_RED=3,
|
||||||
MAPRES_SPAWNPOINT_BLUE=3,
|
MAPRES_SPAWNPOINT_BLUE=4,
|
||||||
MAPRES_FLAGSTAND_RED=4,
|
MAPRES_FLAGSTAND_RED=5,
|
||||||
MAPRES_FLAGSTAND_BLUE=5,
|
MAPRES_FLAGSTAND_BLUE=6,
|
||||||
|
MAPRES_ENTS_END,
|
||||||
|
|
||||||
ITEM_NULL=0,
|
ITEM_NULL=0,
|
||||||
ITEM_WEAPON_GUN=0x00010001,
|
ITEM_WEAPON_GUN=0x00010001,
|
||||||
|
|
|
@ -409,12 +409,26 @@ game_world world;
|
||||||
gameobject::gameobject()
|
gameobject::gameobject()
|
||||||
: entity(OBJTYPE_GAME)
|
: entity(OBJTYPE_GAME)
|
||||||
{
|
{
|
||||||
gametype = GAMETYPE_DM;
|
// select gametype
|
||||||
if(strcmp(config.gametype, "ctf") == 0)
|
if(strcmp(config.gametype, "ctf") == 0)
|
||||||
|
{
|
||||||
gametype = GAMETYPE_CTF;
|
gametype = GAMETYPE_CTF;
|
||||||
|
dbg_msg("game", "-- Capture The Flag --");
|
||||||
|
}
|
||||||
else if(strcmp(config.gametype, "tdm") == 0)
|
else if(strcmp(config.gametype, "tdm") == 0)
|
||||||
|
{
|
||||||
gametype = GAMETYPE_TDM;
|
gametype = GAMETYPE_TDM;
|
||||||
|
dbg_msg("game", "-- Team Death Match --");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
gametype = GAMETYPE_DM;
|
||||||
|
dbg_msg("game", "-- Death Match --");
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
|
||||||
|
//
|
||||||
game_over_tick = -1;
|
game_over_tick = -1;
|
||||||
sudden_death = 0;
|
sudden_death = 0;
|
||||||
round_start_tick = server_tick();
|
round_start_tick = server_tick();
|
||||||
|
@ -451,6 +465,10 @@ void gameobject::post_reset()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gameobject::tick_ctf()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void gameobject::tick_dm()
|
void gameobject::tick_dm()
|
||||||
{
|
{
|
||||||
if(game_over_tick == -1)
|
if(game_over_tick == -1)
|
||||||
|
@ -533,6 +551,11 @@ void gameobject::tick()
|
||||||
{
|
{
|
||||||
switch(gametype)
|
switch(gametype)
|
||||||
{
|
{
|
||||||
|
case GAMETYPE_CTF:
|
||||||
|
{
|
||||||
|
tick_ctf();
|
||||||
|
break;
|
||||||
|
}
|
||||||
case GAMETYPE_TDM:
|
case GAMETYPE_TDM:
|
||||||
{
|
{
|
||||||
tick_tdm();
|
tick_tdm();
|
||||||
|
@ -794,17 +817,38 @@ void player::respawn()
|
||||||
spawning = true;
|
spawning = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void player::try_respawn()
|
bool try_spawntype(int t, vec2 *pos)
|
||||||
{
|
{
|
||||||
// get spawn point
|
// get spawn point
|
||||||
int start, num;
|
int start, num;
|
||||||
map_get_type(1, &start, &num);
|
map_get_type(t, &start, &num);
|
||||||
|
if(!num)
|
||||||
|
return false;
|
||||||
|
|
||||||
vec2 spawnpos = vec2(100.0f, -60.0f);
|
|
||||||
if(num)
|
|
||||||
{
|
|
||||||
mapres_spawnpoint *sp = (mapres_spawnpoint*)map_get_item(start + (rand()%num), NULL, NULL);
|
mapres_spawnpoint *sp = (mapres_spawnpoint*)map_get_item(start + (rand()%num), NULL, NULL);
|
||||||
spawnpos = vec2((float)sp->x, (float)sp->y);
|
*pos = vec2((float)sp->x, (float)sp->y);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void player::try_respawn()
|
||||||
|
{
|
||||||
|
vec2 spawnpos = vec2(100.0f, -60.0f);
|
||||||
|
|
||||||
|
// get spawn point
|
||||||
|
if(gameobj->gametype == GAMETYPE_CTF)
|
||||||
|
{
|
||||||
|
// try first try own team spawn, then normal spawn and then enemy
|
||||||
|
if(!try_spawntype(MAPRES_SPAWNPOINT_RED+(team&1), &spawnpos))
|
||||||
|
{
|
||||||
|
if(!try_spawntype(MAPRES_SPAWNPOINT, &spawnpos))
|
||||||
|
try_spawntype(MAPRES_SPAWNPOINT_RED+((team+1)&1), &spawnpos);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(!try_spawntype(MAPRES_SPAWNPOINT, &spawnpos))
|
||||||
|
try_spawntype(MAPRES_SPAWNPOINT_RED+(rand()&1), &spawnpos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if the position is occupado
|
// check if the position is occupado
|
||||||
|
@ -822,7 +866,7 @@ void player::try_respawn()
|
||||||
defered_pos = pos;
|
defered_pos = pos;
|
||||||
|
|
||||||
|
|
||||||
health = data->playerinfo[gameobj->gametype].maxhealth;
|
health = 10;
|
||||||
armor = 0;
|
armor = 0;
|
||||||
jumped = 0;
|
jumped = 0;
|
||||||
dead = false;
|
dead = false;
|
||||||
|
@ -1642,18 +1686,18 @@ void powerup::tick()
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case POWERUP_HEALTH:
|
case POWERUP_HEALTH:
|
||||||
if(pplayer->health < data->playerinfo[gameobj->gametype].maxhealth)
|
if(pplayer->health < 10)
|
||||||
{
|
{
|
||||||
create_sound(pos, SOUND_PICKUP_HEALTH, 0);
|
create_sound(pos, SOUND_PICKUP_HEALTH, 0);
|
||||||
pplayer->health = min((int)data->playerinfo[gameobj->gametype].maxhealth, pplayer->health + data->powerupinfo[type].amount);
|
pplayer->health = min(10, pplayer->health + data->powerupinfo[type].amount);
|
||||||
respawntime = data->powerupinfo[type].respawntime;
|
respawntime = data->powerupinfo[type].respawntime;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case POWERUP_ARMOR:
|
case POWERUP_ARMOR:
|
||||||
if(pplayer->armor < data->playerinfo[gameobj->gametype].maxarmor)
|
if(pplayer->armor < 10)
|
||||||
{
|
{
|
||||||
create_sound(pos, SOUND_PICKUP_ARMOR, 0);
|
create_sound(pos, SOUND_PICKUP_ARMOR, 0);
|
||||||
pplayer->armor = min((int)data->playerinfo[gameobj->gametype].maxarmor, pplayer->armor + data->powerupinfo[type].amount);
|
pplayer->armor = min(10, pplayer->armor + data->powerupinfo[type].amount);
|
||||||
respawntime = data->powerupinfo[type].respawntime;
|
respawntime = data->powerupinfo[type].respawntime;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1753,6 +1797,8 @@ void flag::reset()
|
||||||
|
|
||||||
void flag::tick()
|
void flag::tick()
|
||||||
{
|
{
|
||||||
|
// THIS CODE NEEDS TO BE REWRITTEN. ITS NOT SAVE AT ALL
|
||||||
|
|
||||||
// wait for respawn
|
// wait for respawn
|
||||||
if(spawntick > 0)
|
if(spawntick > 0)
|
||||||
{
|
{
|
||||||
|
@ -1763,28 +1809,21 @@ void flag::tick()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a player intersected us
|
// Check if a player intersected us
|
||||||
vec2 meh;
|
if(!carrying_player)
|
||||||
player* pplayer = intersect_player(pos, pos + vel, meh, 0);
|
|
||||||
if (pplayer)
|
|
||||||
{
|
{
|
||||||
if (!carrying_player)
|
player *players[MAX_CLIENTS];
|
||||||
carrying_player = pplayer;
|
int types[] = {OBJTYPE_PLAYER};
|
||||||
|
int num = world.find_entities(pos, 32.0f, (entity**)players, MAX_CLIENTS, types, 1);
|
||||||
// TODO: something..?
|
for(int i = 0; i < num; i++)
|
||||||
}
|
|
||||||
|
|
||||||
if (carrying_player)
|
|
||||||
{
|
{
|
||||||
if (carrying_player->dead)
|
if(players[i]->team != team)
|
||||||
carrying_player = 0x0;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
vel = carrying_player->pos - pos;
|
carrying_player = players[i];
|
||||||
pos = carrying_player->pos;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!carrying_player)
|
if(!carrying_player)
|
||||||
{
|
{
|
||||||
vel.y += 0.25f;
|
vel.y += 0.25f;
|
||||||
vec2 new_pos = pos + vel;
|
vec2 new_pos = pos + vel;
|
||||||
|
@ -1796,6 +1835,17 @@ void flag::tick()
|
||||||
if (is_grounded())
|
if (is_grounded())
|
||||||
vel.x = vel.y = 0;
|
vel.x = vel.y = 0;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (carrying_player->dead)
|
||||||
|
carrying_player = 0x0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vel = carrying_player->pos - pos;
|
||||||
|
pos = carrying_player->pos;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool flag::is_grounded()
|
bool flag::is_grounded()
|
||||||
|
@ -1973,6 +2023,8 @@ void mods_tick()
|
||||||
{
|
{
|
||||||
mods_client_enter(MAX_CLIENTS-i-1);
|
mods_client_enter(MAX_CLIENTS-i-1);
|
||||||
strcpy(players[MAX_CLIENTS-i-1].name, "(bot)");
|
strcpy(players[MAX_CLIENTS-i-1].name, "(bot)");
|
||||||
|
if(gameobj->gametype != GAMETYPE_DM)
|
||||||
|
players[MAX_CLIENTS-i-1].team = count&1;
|
||||||
}
|
}
|
||||||
count = -1;
|
count = -1;
|
||||||
}
|
}
|
||||||
|
@ -2189,6 +2241,23 @@ void mods_init()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(gameobj->gametype == GAMETYPE_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)
|
||||||
|
gameobj->flagsstands[i] = vec2(stand->x, stand->y);
|
||||||
|
|
||||||
|
flag *f = new flag(i);
|
||||||
|
f->pos = gameobj->flagsstands[i];
|
||||||
|
//world.insert_entity(f);
|
||||||
|
dbg_msg("game", "flag at %f,%f", f->pos.x, f->pos.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
world.insert_entity(gameobj);
|
world.insert_entity(gameobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -112,12 +112,16 @@ class gameobject : public entity
|
||||||
int sudden_death;
|
int sudden_death;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
class flag *flags[2];
|
||||||
|
vec2 flagsstands[2];
|
||||||
|
|
||||||
int gametype;
|
int gametype;
|
||||||
gameobject();
|
gameobject();
|
||||||
virtual void post_reset();
|
virtual void post_reset();
|
||||||
virtual void tick();
|
virtual void tick();
|
||||||
virtual void tick_dm();
|
virtual void tick_dm();
|
||||||
virtual void tick_tdm();
|
virtual void tick_tdm();
|
||||||
|
virtual void tick_ctf();
|
||||||
virtual void snap(int snapping_client);
|
virtual void snap(int snapping_client);
|
||||||
virtual int getteam(int notthisid);
|
virtual int getteam(int notthisid);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue