diff --git a/src/game/client/gc_mapres_tilemap.cpp b/src/game/client/gc_mapres_tilemap.cpp deleted file mode 100644 index 239d2d924..000000000 --- a/src/game/client/gc_mapres_tilemap.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -/* -#include -#include -#include "gc_mapres_tilemap.h" -#include "gc_mapres_image.h" -#include "../g_mapres.h" - -enum -{ - TILEFLAG_VFLIP=1, - TILEFLAG_HFLIP=2, -}; - -int tilemap_init() -{ - return 0; -} - -void tilemap_render(float scale, int fg) -{ - if(!map_is_loaded()) - return; - - float screen_x0, screen_y0, screen_x1, screen_y1; - gfx_getscreen(&screen_x0, &screen_y0, &screen_x1, &screen_y1); - - // fetch indecies - int start, num; - map_get_type(MAPRES_TILEMAP, &start, &num); - - // render tilemaps - int passed_main = 0; - for(int t = 0; t < num; t++) - { - mapres_tilemap *tmap = (mapres_tilemap *)map_get_item(start+t,0,0); - unsigned char *data = (unsigned char *)map_get_data(tmap->data); - - if(tmap->main) - passed_main = 1; - - if((fg && passed_main) || (!fg && !passed_main)) - { - if(!config.gfx_high_detail && !tmap->main) - continue; - gfx_texture_set(img_get(tmap->image)); - - gfx_quads_begin(); - - int starty = (int)(screen_y0/scale)-1; - int startx = (int)(screen_x0/scale)-1; - int endy = (int)(screen_y1/scale)+1; - int endx = (int)(screen_x1/scale)+1; - - float frac = (1.25f/1024.0f);//2.0f; //2.0f; - float texsize = 1024.0f; - float nudge = 0.5f/texsize; - for(int y = starty; y < endy; y++) - for(int x = startx; x < endx; x++) - { - int mx = x; - int my = y; - if(mx<0) mx = 0; - if(mx>=tmap->width) mx = tmap->width-1; - if(my<0) my = 0; - if(my>=tmap->height) my = tmap->height-1; - - int c = mx + my*tmap->width; - - unsigned char d = data[c*2]; - unsigned char f = data[c*2+1]; - if(d) - { - int tx = d%16; - int ty = d/16; - int px0 = tx*(1024/16); - int py0 = ty*(1024/16); - int px1 = (tx+1)*(1024/16)-1; - int py1 = (ty+1)*(1024/16)-1; - - float u0 = nudge + px0/texsize+frac; - float v0 = nudge + py0/texsize+frac; - float u1 = nudge + px1/texsize-frac; - float v1 = nudge + py1/texsize-frac; - - if(f&TILEFLAG_VFLIP) - { - float tmp = u0; - u0 = u1; - u1 = tmp; - } - - if(f&TILEFLAG_HFLIP) - { - float tmp = v0; - v0 = v1; - v1 = tmp; - } - - gfx_quads_setsubset(u0,v0,u1,v1); - - gfx_quads_drawTL(x*scale, y*scale, scale, scale); - } - } - - gfx_quads_end(); - } - } -} -*/ diff --git a/src/game/client/gc_mapres_tilemap.h b/src/game/client/gc_mapres_tilemap.h deleted file mode 100644 index 5dfbd6b51..000000000 --- a/src/game/client/gc_mapres_tilemap.h +++ /dev/null @@ -1,20 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ - -// dependencies: image - -// -int tilemap_init(); - -// renders the tilemaps -void tilemap_render(float scale, int fg); - -struct mapres_tilemap -{ - int image; - int width; - int height; - int x, y; - int scale; - int data; - int main; -}; diff --git a/src/game/editor/ed_editor.cpp b/src/game/editor/ed_editor.cpp index 69bf75544..a45c9588e 100644 --- a/src/game/editor/ed_editor.cpp +++ b/src/game/editor/ed_editor.cpp @@ -12,10 +12,7 @@ extern "C" { } #include -#include #include -//#include "game/mapres_col.h" -#include #include #include @@ -26,7 +23,7 @@ static int background_texture = 0; static int cursor_texture = 0; static int entities_texture = 0; - +// backwards compatiblity class mapres_image { public: @@ -36,6 +33,27 @@ public: }; +struct mapres_tilemap +{ + int image; + int width; + int height; + int x, y; + int scale; + int data; + int main; +}; + +enum +{ + MAPRES_REGISTERED=0x8000, + MAPRES_IMAGE=0x8001, + MAPRES_TILEMAP=0x8002, + MAPRES_COLLISIONMAP=0x8003, + MAPRES_TEMP_THEME=0x8fff, +}; + + EDITOR editor; diff --git a/src/game/g_mapres.h b/src/game/g_mapres.h deleted file mode 100644 index 77a3ccaaa..000000000 --- a/src/game/g_mapres.h +++ /dev/null @@ -1,14 +0,0 @@ -/* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -enum -{ - MAPRES_REGISTERED=0x8000, - MAPRES_IMAGE=0x8001, - MAPRES_TILEMAP=0x8002, - MAPRES_COLLISIONMAP=0x8003, - MAPRES_TEMP_THEME=0x8fff, -}; - -struct mapres_theme -{ - int id; -}; diff --git a/src/game/server/gs_common.h b/src/game/server/gs_common.h index 605bbadc2..90363cb86 100644 --- a/src/game/server/gs_common.h +++ b/src/game/server/gs_common.h @@ -141,6 +141,8 @@ public: bool is_friendly_fire(int cid1, int cid2); + virtual bool on_entity(int index, vec2 pos); + virtual void post_reset(); virtual void tick(); diff --git a/src/game/server/gs_game.cpp b/src/game/server/gs_game.cpp index 2b3af5308..bae964abc 100644 --- a/src/game/server/gs_game.cpp +++ b/src/game/server/gs_game.cpp @@ -1,7 +1,8 @@ /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ -#include -#include "gs_common.h" #include +#include +#include +#include "gs_common.h" gameobject::gameobject() : entity(OBJTYPE_GAME) @@ -34,6 +35,51 @@ gameobject::gameobject() teamscore[1] = 0; } +// UGLY!!!! +extern vec2 spawn_points[3][64]; +extern int num_spawn_points[3]; + +bool gameobject::on_entity(int index, vec2 pos) +{ + int type = -1; + int subtype = 0; + + if(index == ENTITY_SPAWN) + spawn_points[0][num_spawn_points[0]++] = pos; + else if(index == ENTITY_SPAWN_RED) + spawn_points[1][num_spawn_points[1]++] = pos; + else if(index == ENTITY_SPAWN_BLUE) + spawn_points[2][num_spawn_points[2]++] = pos; + else if(index == ENTITY_ARMOR_1) + type = POWERUP_ARMOR; + else if(index == ENTITY_HEALTH_1) + type = POWERUP_HEALTH; + else if(index == ENTITY_WEAPON_SHOTGUN) + { + type = POWERUP_WEAPON; + subtype = WEAPON_SHOTGUN; + } + else if(index == ENTITY_WEAPON_ROCKET) + { + type = POWERUP_WEAPON; + subtype = WEAPON_ROCKET; + } + else if(index == ENTITY_POWERUP_NINJA) + { + type = POWERUP_NINJA; + subtype = WEAPON_NINJA; + } + + if(type != -1) + { + powerup *ppower = new powerup(type, subtype); + ppower->pos = pos; + return true; + } + + return false; +} + void gameobject::endround() { if(warmup) // game can't end when we are running warmup diff --git a/src/game/server/gs_game_ctf.cpp b/src/game/server/gs_game_ctf.cpp index 90e0393af..fd54a97b3 100644 --- a/src/game/server/gs_game_ctf.cpp +++ b/src/game/server/gs_game_ctf.cpp @@ -1,32 +1,31 @@ /* copyright (c) 2007 magnus auvinen, see licence.txt for more info */ +#include #include "gs_common.h" #include "gs_game_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 - flags[i] = 0; - } - } - is_teamplay = true; } +bool gameobject_ctf::on_entity(int index, vec2 pos) +{ + if(gameobject::on_entity(index, pos)) + return true; + + int team = -1; + if(index == ENTITY_FLAGSTAND_RED) team = 0; + if(index == ENTITY_FLAGSTAND_BLUE) team = 1; + if(team == -1) + return false; + + flag *f = new flag(team); + f->stand_pos = pos; + f->pos = pos; + flags[team] = f; + return true; +} + void gameobject_ctf::on_player_spawn(class player *p) { } diff --git a/src/game/server/gs_game_ctf.h b/src/game/server/gs_game_ctf.h index 02acef37e..107c000dd 100644 --- a/src/game/server/gs_game_ctf.h +++ b/src/game/server/gs_game_ctf.h @@ -9,6 +9,8 @@ public: gameobject_ctf(); virtual void tick(); + virtual bool on_entity(int index, vec2 pos); + virtual void on_player_spawn(class player *p); virtual int on_player_death(class player *victim, class player *killer, int weapon); }; diff --git a/src/game/server/gs_server.cpp b/src/game/server/gs_server.cpp index 98a998044..d4538ba18 100644 --- a/src/game/server/gs_server.cpp +++ b/src/game/server/gs_server.cpp @@ -2081,41 +2081,8 @@ void mods_init() for(int x = 0; x < tmap->width; x++) { int index = tiles[y*tmap->width+x].index - ENTITY_OFFSET; - int type = -1; - int subtype = 0; vec2 pos(x*32.0f+16.0f, y*32.0f+16.0f); - - if(index == ENTITY_SPAWN) - spawn_points[0][num_spawn_points[0]++] = pos; - else if(index == ENTITY_SPAWN_RED) - spawn_points[1][num_spawn_points[1]++] = pos; - else if(index == ENTITY_SPAWN_BLUE) - spawn_points[2][num_spawn_points[2]++] = pos; - else if(index == ENTITY_ARMOR_1) - type = POWERUP_ARMOR; - else if(index == ENTITY_HEALTH_1) - type = POWERUP_HEALTH; - else if(index == ENTITY_WEAPON_SHOTGUN) - { - type = POWERUP_WEAPON; - subtype = WEAPON_SHOTGUN; - } - else if(index == ENTITY_WEAPON_ROCKET) - { - type = POWERUP_WEAPON; - subtype = WEAPON_ROCKET; - } - else if(index == ENTITY_POWERUP_NINJA) - { - type = POWERUP_NINJA; - subtype = WEAPON_NINJA; - } - - if(type != -1) - { - powerup *ppower = new powerup(type, subtype); - ppower->pos = pos; - } + gameobj->on_entity(index, pos); } }