diff --git a/datasrc/network.py b/datasrc/network.py index 81b435f46..7bb8e7efe 100644 --- a/datasrc/network.py +++ b/datasrc/network.py @@ -2,8 +2,7 @@ from datatypes import * Emotes = ["NORMAL", "PAIN", "HAPPY", "SURPRISE", "ANGRY", "BLINK"] PlayerStates = ["UNKNOWN", "PLAYING", "IN_MENU", "CHATTING"] -GameTypes = ["DM", "TDM", "CTF"] -GameFlags = ["TEAMS"] +GameFlags = ["TEAMS", "FLAGS"] Emoticons = [str(x) for x in xrange(1,16)] @@ -22,7 +21,6 @@ RawSource = ''' ''' Enums = [ - Enum("GAMETYPE", GameTypes), Enum("PLAYERSTATE", PlayerStates), Enum("EMOTE", Emotes), Enum("POWERUP", Powerups), @@ -96,7 +94,6 @@ Objects = [ NetIntRange("score_limit", 0, 'max_int'), NetIntRange("time_limit", 0, 'max_int'), - NetIntRange("gametype", 0, len(GameTypes)), NetIntRange("warmup", 0, 'max_int'), diff --git a/src/engine/e_if_server.h b/src/engine/e_if_server.h index dd5e14032..98e2b452d 100644 --- a/src/engine/e_if_server.h +++ b/src/engine/e_if_server.h @@ -91,7 +91,7 @@ void server_setclientscore(int client_id, int score); See Also: */ -void server_setbrowseinfo(int game_type, int progression); +void server_setbrowseinfo(const char *game_type, int progression); /* Function: server_kick diff --git a/src/engine/server/es_server.c b/src/engine/server/es_server.c index 905ee2726..8db9865cc 100644 --- a/src/engine/server/es_server.c +++ b/src/engine/server/es_server.c @@ -27,7 +27,7 @@ static int64 game_start_time; static int current_tick = 0; static int run_server = 1; -static int browseinfo_gametype = -1; +static char browseinfo_gametype[16] = {0}; static int browseinfo_progression = -1; static int64 lastheartbeat; @@ -250,9 +250,9 @@ void server_setclientscore(int client_id, int score) clients[client_id].score = score; } -void server_setbrowseinfo(int game_type, int progression) +void server_setbrowseinfo(const char *game_type, int progression) { - browseinfo_gametype = game_type; + str_copy(browseinfo_gametype, game_type, sizeof(browseinfo_gametype)); browseinfo_progression = progression; if(browseinfo_progression > 100) browseinfo_progression = 100; diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp index 5349401b7..762ed1fba 100644 --- a/src/game/client/components/hud.cpp +++ b/src/game/client/components/hud.cpp @@ -31,7 +31,6 @@ void HUD::render_goals() // render_scorehud // render_warmuptimer - int gametype = gameclient.snap.gameobj->gametype; int gameflags = gameclient.snap.gameobj->flags; float whole = 300*gfx_screenaspect(); @@ -84,7 +83,7 @@ void HUD::render_goals() str_format(buf, sizeof(buf), "%d", t?gameclient.snap.gameobj->teamscore_blue:gameclient.snap.gameobj->teamscore_red); float w = gfx_text_width(0, 14, buf, -1); - if(gametype == GAMETYPE_CTF) + if(gameflags&GAMEFLAG_FLAGS) { gfx_text(0, whole-20-w/2+5, 300-40-15+t*20, 14, buf, -1); if(gameclient.snap.flags[t]) diff --git a/src/game/client/components/killmessages.cpp b/src/game/client/components/killmessages.cpp index 106433f58..410f2c3d4 100644 --- a/src/game/client/components/killmessages.cpp +++ b/src/game/client/components/killmessages.cpp @@ -62,7 +62,7 @@ void KILLMESSAGES::on_render() // render victim tee x -= 24.0f; - if(gameclient.snap.gameobj && gameclient.snap.gameobj->gametype == GAMETYPE_CTF) + if(gameclient.snap.gameobj && gameclient.snap.gameobj->flags&GAMEFLAG_FLAGS) { if(killmsgs[r].mode_special&1) { @@ -96,7 +96,7 @@ void KILLMESSAGES::on_render() if(killmsgs[r].victim != killmsgs[r].killer) { - if(gameclient.snap.gameobj && gameclient.snap.gameobj->gametype == GAMETYPE_CTF) + if(gameclient.snap.gameobj && gameclient.snap.gameobj->flags&GAMEFLAG_FLAGS) { if(killmsgs[r].mode_special&2) { diff --git a/src/game/client/components/menus_settings.cpp b/src/game/client/components/menus_settings.cpp index 95a097c2b..e43793a49 100644 --- a/src/game/client/components/menus_settings.cpp +++ b/src/game/client/components/menus_settings.cpp @@ -4,11 +4,7 @@ #include // strcmp, strlen, strncpy #include // atoi -extern "C" { - #include - #include - #include -} +#include #include #include diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 76b3ef3ee..76d003e71 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -14,30 +14,15 @@ GAMECONTROLLER::GAMECONTROLLER() { - // select gametype - if(strcmp(config.sv_gametype, "ctf") == 0) - { - gametype = GAMETYPE_CTF; - dbg_msg("game", "-- Capture The Flag --"); - } - else if(strcmp(config.sv_gametype, "tdm") == 0) - { - gametype = GAMETYPE_TDM; - dbg_msg("game", "-- Team Death Match --"); - } - else - { - gametype = GAMETYPE_DM; - dbg_msg("game", "-- Death Match --"); - } - + gametype = config.sv_gametype; + // do_warmup(config.sv_warmup); game_over_tick = -1; sudden_death = 0; round_start_tick = server_tick(); round_count = 0; - is_teamplay = false; + game_flags = 0; teamscore[0] = 0; teamscore[1] = 0; @@ -87,7 +72,7 @@ bool GAMECONTROLLER::can_spawn(PLAYER *player, vec2 *out_pos) { SPAWNEVAL eval; - if(is_teamplay) + if(is_teamplay()) { eval.friendly_team = player->team; @@ -175,7 +160,7 @@ void GAMECONTROLLER::resetgame() const char *GAMECONTROLLER::get_team_name(int team) { - if(is_teamplay) + if(is_teamplay()) { if(team == 0) return "red team"; @@ -276,7 +261,7 @@ void GAMECONTROLLER::post_reset() void GAMECONTROLLER::on_player_info_change(class PLAYER *p) { const int team_colors[2] = {65387, 10223467}; - if(is_teamplay) + if(is_teamplay()) { if(p->team >= 0 || p->team <= 1) { @@ -297,7 +282,7 @@ int GAMECONTROLLER::on_character_death(class CHARACTER *victim, class PLAYER *ki victim->player->score--; // suicide else { - if(is_teamplay && victim->team == killer->team) + if(is_teamplay() && victim->team == killer->team) killer->score--; // teamkill else killer->score++; // normal kill @@ -327,7 +312,7 @@ bool GAMECONTROLLER::is_friendly_fire(int cid1, int cid2) if(cid1 == cid2) return false; - if(is_teamplay) + if(is_teamplay()) { if(game.players[cid1].team == game.players[cid2].team) return true; @@ -364,7 +349,7 @@ void GAMECONTROLLER::tick() if(config.sv_scorelimit) { - if(is_teamplay) + if(is_teamplay()) { prog = max(prog, (teamscore[0]*100)/config.sv_scorelimit); prog = max(prog, (teamscore[1]*100)/config.sv_scorelimit); @@ -385,6 +370,12 @@ void GAMECONTROLLER::tick() server_setbrowseinfo(gametype, prog); } + +bool GAMECONTROLLER::is_teamplay() const +{ + return game_flags&GAMEFLAG_TEAMS; +} + void GAMECONTROLLER::snap(int snapping_client) { NETOBJ_GAME *gameobj = (NETOBJ_GAME *)snap_new_item(NETOBJTYPE_GAME, 0, sizeof(NETOBJ_GAME)); @@ -395,7 +386,7 @@ void GAMECONTROLLER::snap(int snapping_client) gameobj->score_limit = config.sv_scorelimit; gameobj->time_limit = config.sv_timelimit; gameobj->round_start_tick = round_start_tick; - gameobj->gametype = gametype; + gameobj->flags = game_flags; gameobj->warmup = warmup; @@ -416,7 +407,7 @@ int GAMECONTROLLER::get_auto_team(int notthisid) } int team = 0; - if(is_teamplay) + if(is_teamplay()) team = numplayers[0] > numplayers[1] ? 1 : 0; if(can_join_team(team, notthisid)) @@ -493,7 +484,7 @@ int GAMECONTROLLER::clampteam(int team) { if(team < 0) // spectator return -1; - if(is_teamplay) + if(is_teamplay()) return team&1; return 0; } diff --git a/src/game/server/gamecontroller.hpp b/src/game/server/gamecontroller.hpp index 9006f985b..1a87034b1 100644 --- a/src/game/server/gamecontroller.hpp +++ b/src/game/server/gamecontroller.hpp @@ -35,6 +35,8 @@ protected: void cyclemap(); void resetgame(); + const char *gametype; + int round_start_tick; int game_over_tick; int sudden_death; @@ -44,10 +46,11 @@ protected: int warmup; int round_count; + int game_flags; + public: - int gametype; - bool is_teamplay; + bool is_teamplay() const; GAMECONTROLLER(); diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp index 8d1cdef8c..ba8df237f 100644 --- a/src/game/server/gamemodes/ctf.cpp +++ b/src/game/server/gamemodes/ctf.cpp @@ -10,7 +10,7 @@ GAMECONTROLLER_CTF::GAMECONTROLLER_CTF() { flags[0] = 0; flags[1] = 0; - is_teamplay = true; + game_flags = GAMEFLAG_TEAMS|GAMEFLAG_FLAGS; } bool GAMECONTROLLER_CTF::on_entity(int index, vec2 pos) diff --git a/src/game/server/gamemodes/tdm.cpp b/src/game/server/gamemodes/tdm.cpp index 26441c9f7..914bae085 100644 --- a/src/game/server/gamemodes/tdm.cpp +++ b/src/game/server/gamemodes/tdm.cpp @@ -6,7 +6,7 @@ GAMECONTROLLER_TDM::GAMECONTROLLER_TDM() { - is_teamplay = true; + game_flags = GAMEFLAG_TEAMS; } int GAMECONTROLLER_TDM::on_character_death(class CHARACTER *victim, class PLAYER *killer, int weapon) diff --git a/src/game/server/hooks.cpp b/src/game/server/hooks.cpp index dd2d9db9b..f3d35026b 100644 --- a/src/game/server/hooks.cpp +++ b/src/game/server/hooks.cpp @@ -359,7 +359,7 @@ void mods_init() { mods_connected(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; } }