about summary refs log tree commit diff
path: root/src/game/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/server')
-rw-r--r--src/game/server/gs_common.h2
-rw-r--r--src/game/server/gs_game.cpp48
-rw-r--r--src/game/server/gs_game_ctf.cpp39
-rw-r--r--src/game/server/gs_game_ctf.h2
-rw-r--r--src/game/server/gs_server.cpp35
5 files changed, 71 insertions, 55 deletions
diff --git a/src/game/server/gs_common.h b/src/game/server/gs_common.h
index 605bbadc..90363cb8 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 2b3af530..bae964ab 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 <string.h>
 #include <engine/e_config.h>
+#include <game/g_mapitems.h>
 #include "gs_common.h"
-#include <string.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 90e0393a..fd54a97b 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 <game/g_mapitems.h>
 #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 02acef37..107c000d 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 98a99804..d4538ba1 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);
 		}
 	}