diff --git a/config/menus_settings.cfg b/config/menus_settings.cfg index 2d83ce1f..5fc79517 100644 --- a/config/menus_settings.cfg +++ b/config/menus_settings.cfg @@ -20,21 +20,21 @@ menuitem "V-19 Combat Shotgun" "nextprimary 2;echo V-19 Combat Shotgun selecte newmenu CLA menumdl playermodels/CLA/01 all 50 4 -menuitem "Comandante" "skin 0" "chmenumdl CLA playermodels/CLA/01 all 50 4" -menuitem "Psycho" "skin 1" "chmenumdl CLA playermodels/CLA/02 all 50 4" -menuitem "Bomber" "skin 2" "chmenumdl CLA playermodels/CLA/03 all 50 4" -menuitem "Ripper" "skin 3" "chmenumdl CLA playermodels/CLA/04 all 50 4" +menuitem "Comandante" "skin_cla 0" "chmenumdl CLA playermodels/CLA/01 all 50 4" +menuitem "Psycho" "skin_cla 1" "chmenumdl CLA playermodels/CLA/02 all 50 4" +menuitem "Bomber" "skin_cla 2" "chmenumdl CLA playermodels/CLA/03 all 50 4" +menuitem "Ripper" "skin_cla 3" "chmenumdl CLA playermodels/CLA/04 all 50 4" newmenu RVSF menumdl playermodels/RVSF/01 all 50 4 -menuitem "Alpha" "skin 0" "chmenumdl RVSF playermodels/RVSF/01 all 50 4" -menuitem "Tango" "skin 1" "chmenumdl RVSF playermodels/RVSF/02 all 50 4" -menuitem "Cobra" "skin 2" "chmenumdl RVSF playermodels/RVSF/03 all 50 4" -menuitem "Viper" "skin 3" "chmenumdl RVSF playermodels/RVSF/04 all 50 4" -menuitem "Swat" "skin 4" "chmenumdl RVSF playermodels/RVSF/05 all 50 4" -menuitem "Police" "skin 5" "chmenumdl RVSF playermodels/RVSF/06 all 50 4" +menuitem "Alpha" "skin_rvsf 0" "chmenumdl RVSF playermodels/RVSF/01 all 50 4" +menuitem "Tango" "skin_rvsf 1" "chmenumdl RVSF playermodels/RVSF/02 all 50 4" +menuitem "Cobra" "skin_rvsf 2" "chmenumdl RVSF playermodels/RVSF/03 all 50 4" +menuitem "Viper" "skin_rvsf 3" "chmenumdl RVSF playermodels/RVSF/04 all 50 4" +menuitem "Swat" "skin_rvsf 4" "chmenumdl RVSF playermodels/RVSF/05 all 50 4" +menuitem "Police" "skin_rvsf 5" "chmenumdl RVSF playermodels/RVSF/06 all 50 4" newmenu "QUICK setup" diff --git a/source/src/bot/botmanager.cpp b/source/src/bot/botmanager.cpp index 96c8a7a4..6af62e47 100644 --- a/source/src/bot/botmanager.cpp +++ b/source/src/bot/botmanager.cpp @@ -34,22 +34,22 @@ CBotManager::~CBotManager(void) void CBotManager::Init() { m_pBotToView = NULL; - + m_bBotsShoot = true; m_bIdleBots = false; m_iFrameTime = 0; m_iPrevTime = lastmillis; m_sBotSkill = 1; // Default all bots have the skill 'Good' - + CreateSkillData(); LoadBotNamesFile(); LoadBotTeamsFile(); //WaypointClass.Init(); lsrand(time(NULL)); } - + void CBotManager::Think() -{ +{ if (m_bInit) { Init(); @@ -64,7 +64,7 @@ void CBotManager::Think() short x, y; WaypointClass.GetNodeIndexes(player1->o, &x, &y); AddDebugText("x: %d y: %d", x, y); - + m_iFrameTime = lastmillis - m_iPrevTime; if (m_iFrameTime > 250) m_iFrameTime = 250; m_iPrevTime = lastmillis; @@ -78,10 +78,10 @@ void CBotManager::Think() ReAddBot(pStoredBot); delete pStoredBot; } - + m_fReAddBotDelay = -1.0f; } - + // If this is a ded server check if there are any players, if not bots should be idle if (dedserv) { @@ -90,10 +90,10 @@ void CBotManager::Think() { if (players[i] && (players[i]->state != CS_DEDHOST)) { botsbeidle = false; break; } } - + if (botsbeidle) return; } - + // Let all bots 'think' loopv(bots) { @@ -112,22 +112,22 @@ void CBotManager::LoadBotNamesFile() // Init bot names array first for (int i=0;i<100;i++) strcpy(m_szBotNames[i], "Bot"); - + m_sBotNameCount = 0; - + // Load bot file char szNameFileName[256]; MakeBotFileName("bot_names.txt", NULL, NULL, szNameFileName); FILE *fp = fopen(szNameFileName, "r"); char szNameBuffer[256]; int iIndex, iStrIndex; - + if (!fp) { conoutf("Warning: Couldn't load bot names file"); return; } - + while (fgets(szNameBuffer, 80, fp) != NULL) { if (m_sBotNameCount >= 150) @@ -136,7 +136,7 @@ void CBotManager::LoadBotNamesFile() "names"); break; } - + short length = (short)strlen(szNameBuffer); if (szNameBuffer[length-1] == '\n') @@ -154,7 +154,7 @@ void CBotManager::LoadBotNamesFile() for (iIndex=iStrIndex; iIndex < length; iIndex++) szNameBuffer[iIndex] = szNameBuffer[iIndex+1]; } - + iStrIndex++; } @@ -170,67 +170,67 @@ void CBotManager::LoadBotNamesFile() } fclose(fp); } - + const char *CBotManager::GetBotName() { const char *szOutput = NULL; TMultiChoice BotNameChoices; short ChoiceVal; - + for(int j=0;jstate != CS_DEDHOST) && + if (players[i] && (players[i]->state != CS_DEDHOST) && !strcasecmp(players[i]->name, m_szBotNames[j])) ChoiceVal -= 10; } - + loopv(bots) { if (bots[i] && (!strcasecmp(bots[i]->name, m_szBotNames[j]))) ChoiceVal -= 10; } - + if ((player1->state != CS_DEDHOST) && !strcasecmp(player1->name, m_szBotNames[j])) ChoiceVal -= 10; - + if (ChoiceVal <= 0) ChoiceVal = 1; - + BotNameChoices.Insert(m_szBotNames[j], ChoiceVal); } - + // Couldn't find a selection? if (!BotNameChoices.GetSelection(szOutput)) szOutput = "Bot"; - + return szOutput; } - + void CBotManager::LoadBotTeamsFile() { // Init bot teams array first for (int i=0;i<20;i++) strcpy(m_szBotTeams[i], "b0ts"); - + m_sBotTeamCount = 0; - + // Load bot file char szNameFileName[256]; MakeBotFileName("bot_teams.txt", NULL, NULL, szNameFileName); FILE *fp = fopen(szNameFileName, "r"); char szNameBuffer[256]; int iIndex, iStrIndex; - + if (!fp) { conoutf("Warning: Couldn't load bot teams file"); return; } - + while ((m_sBotTeamCount < 20) && (fgets(szNameBuffer, 80, fp) != NULL)) { short length = (short)strlen(szNameBuffer); @@ -250,7 +250,7 @@ void CBotManager::LoadBotTeamsFile() for (iIndex=iStrIndex; iIndex < length; iIndex++) szNameBuffer[iIndex] = szNameBuffer[iIndex+1]; } - + iStrIndex++; } @@ -268,7 +268,7 @@ const char *CBotManager::GetBotTeam() const char *szOutput = NULL; TMultiChoice BotTeamChoices; short ChoiceVal; - + for(int j=0;jname, m_szBotNames[j]))) ChoiceVal -= 10; } - + loopv(bots) { if (bots[i] && (!strcasecmp(bots[i]->name, m_szBotNames[j]))) ChoiceVal -= 10; } - + if (!strcasecmp(player1->name, m_szBotNames[j])) ChoiceVal -= 10; - + if (ChoiceVal <= 0) ChoiceVmonsterclearal = 1;*/ - + BotTeamChoices.Insert(m_szBotTeams[j], ChoiceVal); } - + // Couldn't find a selection? if (!BotTeamChoices.GetSelection(szOutput)) szOutput = "b0t"; - + return szOutput; } void CBotManager::RenderBots() { //static bool drawblue; - + loopv(bots) { if (bots[i] && (bots[i] != m_pBotToView)) @@ -320,23 +320,23 @@ void CBotManager::EndMap() { // Remove all bots loopv(bots) - { + { if(!bots[i] || !bots[i]->pBot) continue; // Store bots so they can be re-added after map change - if (bots[i]->pBot && bots[i]->name[0] && bots[i]->team[0]) + if (bots[i]->pBot && bots[i]->name[0] && team_isactive(bots[i]->team)) { - CStoredBot *pStoredBot = new CStoredBot(bots[i]->name, bots[i]->team, + CStoredBot *pStoredBot = new CStoredBot(bots[i]->name, (char *) team_string(bots[i]->team), bots[i]->pBot->m_sSkillNr); m_StoredBots.AddNode(pStoredBot); } delete bots[i]->pBot; - + bots[i]->pBot = NULL; freebotent(bots[i]); } - bots.setsize(0); + bots.setsize(0); condebug("Cleared all bots"); m_fReAddBotDelay = lastmillis + 7500; //if(ishost()) WaypointClass.SaveWPExpFile(); //UNDONE @@ -345,7 +345,7 @@ void CBotManager::EndMap() void CBotManager::BeginMap(const char *szMapName) { EndMap(); // End previous map - + WaypointClass.Init(); WaypointClass.SetMapName(szMapName); if (!WaypointClass.LoadWaypoints()) @@ -356,18 +356,18 @@ void CBotManager::BeginMap(const char *szMapName) m_sUsingAStarBotsCount = 0; PickNextTrigger(); } - + int CBotManager::GetBotIndex(botent *m) { loopv(bots) { if (!bots[i]) continue; - + if (bots[i] == m) return i; } - + return -1; } @@ -379,7 +379,7 @@ void CBotManager::LetBotsUpdateStats() void CBotManager::LetBotsHear(int n, vec *loc) { if (bots.length() == 0 || !loc) return; - + loopv(bots) { if (!bots[i] || !bots[i]->pBot || (bots[i]->state == CS_DEAD)) continue; @@ -394,22 +394,22 @@ void CBotManager::AddWaypoint(node_s *pNode) { short x, y; waypoint_s *pWP; - + loopv(bots) { if (!bots[i] || !bots[i]->pBot) continue; - + pWP = new waypoint_s; pWP->pNode = pNode; WaypointClass.GetNodeIndexes(pNode->v_origin, &x, &y); bots[i]->pBot->m_WaypointList[x][y].AddNode(pWP); - + #ifndef RELEASE_BUILD if (!bots[i]->pBot->GetWPFromNode(pNode)) condebug("Error adding bot wp!"); -#endif +#endif } } - + CalculateMaxAStarCount(); } @@ -420,14 +420,14 @@ void CBotManager::DelWaypoint(node_s *pNode) { short x, y; TLinkedList::node_s *p; - + loopv(bots) { if (!bots[i] || !bots[i]->pBot) continue; - + WaypointClass.GetNodeIndexes(pNode->v_origin, &x, &y); p = bots[i]->pBot->m_WaypointList[x][y].GetFirst(); - + while(p) { if (p->Entry->pNode == pNode) @@ -437,10 +437,10 @@ void CBotManager::DelWaypoint(node_s *pNode) break; } p = p->next; - } + } } } - + CalculateMaxAStarCount(); } @@ -455,19 +455,19 @@ void CBotManager::MakeBotFileName(const char *szFileName, const char *szDir1, co DirSeperator = "/"; strcpy(szOutput, "bot/"); #endif - + if (szDir1) { strcat(szOutput, szDir1); strcat(szOutput, DirSeperator); } - + if (szDir2) { strcat(szOutput, szDir2); strcat(szOutput, DirSeperator); } - + strcat(szOutput, szFileName); } @@ -475,7 +475,7 @@ void CBotManager::CreateSkillData() { // First give the bot skill structure some default data InitSkillData(); - + // Now see if we can load the skill.cfg file char SkillFileName[256] = ""; FILE *pSkillFile = NULL; @@ -500,7 +500,7 @@ void CBotManager::CreateSkillData() char *cmd, *arg1; while (pSkillFile) - { + { cmd_index = 0; cmd_line[cmd_index] = 0; @@ -520,7 +520,7 @@ void CBotManager::CreateSkillData() ch = fgetc(pSkillFile); // skip multiple spaces in input file - while ((cmd_line[cmd_index] == ' ') && (ch == ' ')) + while ((cmd_line[cmd_index] == ' ') && (ch == ' ')) ch = fgetc(pSkillFile); cmd_index++; @@ -644,11 +644,11 @@ void CBotManager::CreateSkillData() else if (strcasecmp(cmd, "can_circle_strafe") == 0) { m_BotSkills[SkillNr].bCircleStrafe = value!=0; - } + } else if (strcasecmp(cmd, "can_search_items_in_combat") == 0) { m_BotSkills[SkillNr].bCanSearchItemsInCombat = value!=0; - } + } } conoutf("done\n"); @@ -761,11 +761,11 @@ void CBotManager::InitSkillData() m_BotSkills[4].bCircleStrafe = false; m_BotSkills[4].bCanSearchItemsInCombat = false; } - + void CBotManager::ChangeBotSkill(short Skill, botent *bot) { static const char *SkillNames[5] = { "best", "good", "medium", "worse", "bad" }; - + if (bot && bot->pBot) { // Only change skill of a single bot @@ -774,24 +774,24 @@ void CBotManager::ChangeBotSkill(short Skill, botent *bot) conoutf("Skill of %s is now %s", bot->name, SkillNames[Skill]); return; } - + // Change skill of all bots loopv(bots) { if (!bots[i] || !bots[i]->pBot) continue; - + bots[i]->pBot->m_pBotSkill = &m_BotSkills[Skill]; bots[i]->pBot->m_sSkillNr = Skill; } - + // Change default bot skill m_sBotSkill = Skill; - + conoutf("Skill of all bots is now %s", SkillNames[Skill]); } void CBotManager::ViewBot() -{ +{ // Check if this bot is still in game bool bFound = false; loopv(bots) @@ -802,15 +802,15 @@ void CBotManager::ViewBot() break; } } - + if (!bFound) { DisableBotView(); return; } - + player1->state = CS_DEAD; // Fake dead - + player1->o = m_pBotToView->o; player1->o.z += 1.0f; player1->yaw = m_pBotToView->yaw; @@ -828,7 +828,7 @@ void CBotManager::DisableBotView() } void CBotManager::CalculateMaxAStarCount() -{ +{ if (WaypointClass.m_iWaypointCount > 0) // Are there any waypoints? { m_sMaxAStarBots = 8 - short(ceil((float)WaypointClass.m_iWaypointCount / @@ -844,26 +844,26 @@ void CBotManager::PickNextTrigger() { short lowest = -1; bool found0 = false; // True if found a trigger with nr 0 - + loopv(ents) { entity &e = ents[i]; - -#if defined AC_CUBE + +#if defined AC_CUBE /* if ((e.type != TRIGGER) || !e.spawned) continue;*/ #elif defined VANILLA_CUBE if ((e.type != CARROT) || !e.spawned) continue; -#endif +#endif if (OUTBORD(e.x, e.y)) continue; - + vec o(e.x, e.y, S(e.x, e.y)->floor+player1->eyeheight); node_s *pWptNearEnt = NULL; - + pWptNearEnt = WaypointClass.GetNearestTriggerWaypoint(o, 2.0f); - + if (pWptNearEnt) { if ((pWptNearEnt->sTriggerNr > 0) && @@ -871,23 +871,23 @@ void CBotManager::PickNextTrigger() lowest = pWptNearEnt->sTriggerNr; if (pWptNearEnt->sTriggerNr == 0) found0 = true; } - + #ifdef WP_FLOOD pWptNearEnt = WaypointClass.GetNearestTriggerFloodWP(o, 2.0f); - + if (pWptNearEnt) { - if ((pWptNearEnt->sTriggerNr > 0) && + if ((pWptNearEnt->sTriggerNr > 0) && ((pWptNearEnt->sTriggerNr < lowest) || (lowest == -1))) lowest = pWptNearEnt->sTriggerNr; if (pWptNearEnt->sTriggerNr == 0) found0 = true; } - -#endif + +#endif } - + if ((lowest == -1) && found0) lowest = 0; - + if (lowest != -1) m_sCurrentTriggerNr = lowest; } @@ -906,7 +906,7 @@ botent *CBotManager::CreateBot(const char *team, const char *skill, const char * m->lifesequence = 0; setskin(m, rnd(6)); // Create new bot class, dependand on the current mod -#if defined VANILLA_CUBE +#if defined VANILLA_CUBE m->pBot = new CCubeBot; #elif defined AC_CUBE m->pBot = new CACBot; @@ -922,12 +922,11 @@ botent *CBotManager::CreateBot(const char *team, const char *skill, const char * s_strncpy(m->name, name, 16); else s_strncpy(m->name, BotManager.GetBotName(), 16); - - if (team && *team && strcmp(team, "random")) - s_strncpy(m->team, team, 5); - else - s_strncpy(m->team, BotManager.GetBotTeam(), 5); - + + const char *tempteam = team && *team && strcmp(team, "random") ? team : BotManager.GetBotTeam(); + m->team = TEAM_SPECT; + loopi(TEAM_NUM) if(!strcmp(teamnames[i], tempteam)) { m->team = i; break; } + if (skill && *skill && strcmp(skill, "random")) { if (!strcasecmp(skill, "best")) @@ -950,17 +949,17 @@ botent *CBotManager::CreateBot(const char *team, const char *skill, const char * } else // No skill specified, use default m->pBot->m_sSkillNr = BotManager.m_sBotSkill; - + m->pBot->m_pBotSkill = &BotManager.m_BotSkills[m->pBot->m_sSkillNr]; // Sync waypoints m->pBot->SyncWaypoints(); - + m->pBot->Spawn(); - + bots.add(m); - - return m; + + return m; } bool botmode() @@ -993,9 +992,9 @@ void addnbot(char *arg1, char *arg2, char *arg3) { if(!botmode()) return; if (!arg1 || !arg1[0]) return; - + int i = atoi(arg1); - + while(i > 0) { addbot(arg2, arg3, NULL); @@ -1020,7 +1019,7 @@ void botsshoot(int Shoot) } COMMAND(botsshoot, ARG_1INT); - + void idlebots(int Idle) { if (Idle) @@ -1054,19 +1053,19 @@ void kickbot(const char *szName) if(!botmode()) return; if (!szName || !(*szName)) return; - + int iBotInd = -1; loopv(bots) { if (!bots[i]) continue; - + if (!strcmp(bots[i]->name, szName)) { iBotInd = i; break; } } - + if (iBotInd != -1) { botent *d = bots[iBotInd]; @@ -1092,7 +1091,7 @@ void kickallbots(void) freebotent(bots[i]); } }; - + bots.setsize(0); } @@ -1119,7 +1118,7 @@ void togglebotview(char *bot) loopv(bots) { if (!bots[i]) continue; - + if (!strcmp(bots[i]->name, bot)) { BotManager.EnableBotView(bots[i]); @@ -1135,9 +1134,9 @@ void botskill(char *bot, char *skill) { if (!skill || !(*skill)) return; - + short SkillNr; - + if (!strcasecmp(skill, "best")) SkillNr = 0; else if (!strcasecmp(skill, "good")) @@ -1153,7 +1152,7 @@ void botskill(char *bot, char *skill) conoutf("Wrong skill specified. Should be best, good, medium, worse or bad"); return; } - + if (bot) { loopv(bots) @@ -1213,13 +1212,13 @@ void telebot(void) vec dest = player1->o, forward, right, up; vec angles(player1->pitch, player1->yaw, player1->roll); traceresult_s tr; - + AnglesToVectors(angles, forward, right, up); forward.mul(4.0f); dest.add(forward); - + TraceLine(player1->o, dest, player1, true, &tr); - + if (!tr.collided) { // Get the first bot @@ -1237,11 +1236,11 @@ COMMAND(telebot, ARG_NONE); void testvisible(int iDir) { - + vec angles, end, forward, right, up; traceresult_s tr; int Dir; - + switch(iDir) { case 0: default: Dir = FORWARD; break; @@ -1251,23 +1250,23 @@ void testvisible(int iDir) case 4: Dir = UP; break; case 5: Dir = DOWN; break; } - + vec from = player1->o; from.z -= (player1->eyeheight - 1.25f); end = from; makevec(&angles, player1->pitch, player1->yaw, player1->roll); angles.x=0; - + if (Dir & UP) angles.x = WrapXAngle(angles.x + 45.0f); else if (Dir & DOWN) angles.x = WrapXAngle(angles.x - 45.0f); - + if ((Dir & FORWARD) || (Dir & BACKWARD)) { if (Dir & BACKWARD) angles.y = WrapYZAngle(angles.y + 180.0f); - + if (Dir & LEFT) { if (Dir & FORWARD) @@ -1291,14 +1290,14 @@ void testvisible(int iDir) angles.x = WrapXAngle(angles.x + 90.0f); else if (Dir & DOWN) angles.x = WrapXAngle(angles.x - 90.0f); - + AnglesToVectors(angles, forward, right, up); - + forward.mul(20.0f); end.add(forward); - + TraceLine(from, end, player1, false, &tr); - + //debugbeam(from, tr.end); char sz[250]; sprintf(sz, "dist: %f; hit: %d", GetDistance(from, tr.end), tr.collided); @@ -1313,5 +1312,5 @@ void mapsize(void) } COMMAND(mapsize, ARG_NONE); - + #endif diff --git a/source/src/client.cpp b/source/src/client.cpp index 9df52822..5405314d 100644 --- a/source/src/client.cpp +++ b/source/src/client.cpp @@ -358,7 +358,7 @@ void c2sinfo(playerent *d) // send update to the server c2sinit = true; putint(p, SV_INITC2S); sendstring(player1->name, p); - sendstring(player1->team, p); + putint(p, player1->team); putint(p, player1->skin); } if(sendmapidenttoserver) diff --git a/source/src/clientgame.cpp b/source/src/clientgame.cpp index caaca425..694172d6 100644 --- a/source/src/clientgame.cpp +++ b/source/src/clientgame.cpp @@ -39,8 +39,8 @@ void setskin(playerent *pl, uint skin) { if(!pl) return; if(pl == player1) c2sinit=false; - const int maxskin[2] = { 3, 5 }; - pl->skin = skin % (maxskin[team_int(pl->team)]+1); + const int maxskin[2] = { 4, 6 }; + pl->skin = skin % maxskin[team_base(pl->team)]; } bool duplicatename(playerent *d, char *name = NULL) @@ -95,8 +95,8 @@ void newname(const char *name) int smallerteam() { int teamsize[2] = {0, 0}; - loopv(players) if(players[i]) teamsize[team_int(players[i]->team)]++; - teamsize[team_int(player1->team)]++; + loopv(players) if(players[i] && !team_isspect(players[i]->team)) teamsize[players[i]->team]++; + if(!team_isspect(player1->team)) teamsize[player1->team]++; if(teamsize[0] == teamsize[1]) return -1; return teamsize[0] < teamsize[1] ? 0 : 1; } @@ -105,7 +105,7 @@ void changeteam(int team, bool respawn) // force team and respawn { c2sinit = false; if(m_flags) tryflagdrop(false); - filtertext(player1->team, team_string(team), 0, MAXTEAMLEN); + player1->team = team; if(respawn) addmsg(SV_CHANGETEAM, "r"); } @@ -115,32 +115,30 @@ void newteam(char *name) { if(m_teammode) { - if(!strcmp(name, player1->team)) return; // same team + int nt = -1; + loopi(TEAM_NUM) if(!strcmp(teamnames[i], name)) nt = i; + if(nt == player1->team) return; // same team if(player1->isspectating() && !(player1->state==CS_DEAD && player1->spectatemode == SM_DEATHCAM)) { conoutf("\f3you can not switch teams when spectating"); return; } - if(!team_valid(name)) { conoutf("\f3\"%s\" is not a valid team name (try CLA or RVSF)", name); return; } + if(nt < 0 || nt > 1) { conoutf("\f3\"%s\" is not a valid team name (try CLA or RVSF)", name); return; } // FIXME bool checkteamsize = autoteambalance && players.length() >= 1 && !m_botmode; int freeteam = smallerteam(); - if(team_valid(name)) + if(checkteamsize && nt != freeteam) { - int team = team_int(name); - if(checkteamsize && team != freeteam) - { - conoutf("\f3the %s team is already full", name); - return; - } - changeteam(team); + conoutf("\f3the %s team is already full", teamnames[nt]); + return; } - else changeteam(checkteamsize ? (uint)freeteam : rnd(2)); // random assignement + changeteam(nt); } } - else conoutf("your team is: %s", player1->team); + else conoutf("your team is: %s", team_string(player1->team)); } -VARNP(skin, nextskin, 0, 0, 1000); +VARNP(skin_cla, nextskin_cla, 0, 0, 1000); +VARNP(skin_rvsf, nextskin_rvsf, 0, 0, 1000); -int curteam() { return team_int(player1->team); } +int curteam() { return player1->team; } int currole() { return player1->clientrole; } int curmode() { return gamemode; } void curmap(int cleaned) { result(cleaned ? behindpath(getclientmap()) : getclientmap()); } @@ -154,6 +152,19 @@ COMMAND(curmap, ARG_1INT); VARP(showscoresondeath, 0, 1, 1); VARP(autoscreenshot, 0, 0, 1); +void nextskin_player1() +{ + switch(player1->team) + { + case TEAM_CLA: + if(player1->skin != nextskin_cla) setskin(player1, nextskin_cla); + break; + case TEAM_RVSF: + if(player1->skin != nextskin_rvsf) setskin(player1, nextskin_rvsf); + break; + } +} + void deathstate(playerent *pl) { pl->state = CS_DEAD; @@ -180,7 +191,7 @@ void spawnstate(playerent *d) // reset player state not persistent d->spawnstate(gamemode); if(d==player1) { - if(player1->skin!=nextskin) setskin(player1, nextskin); + nextskin_player1(); setscope(false); } } @@ -399,7 +410,7 @@ int spawncycle = -1; int fixspawn = 2; // returns -1 for a free place, else dist to the nearest enemy -float nearestenemy(vec place, char *team) +float nearestenemy(vec place, int team) { float nearestenemydist = -1; loopv(players) @@ -419,7 +430,7 @@ void findplayerstart(playerent *d, bool mapcenter, int arenaspawn) entity *e = NULL; if(!mapcenter) { - int type = m_teammode ? team_int(d->team) : 100; + int type = m_teammode ? team_base(d->team) : 100; if(m_arena && arenaspawn >= 0) { int x = -1; @@ -783,7 +794,7 @@ void flagmsg(int flag, int message, int actor, int flagtime) static int musicplaying = -1; playerent *act = getclient(actor); if(actor != getclientnum() && !act && message != FM_RESET) return; - bool own = flag == team_int(player1->team); + bool own = flag == team_base(player1->team); bool firstperson = actor == getclientnum(); bool teammate = !act ? true : isteam(player1->team, act->team); bool firstpersondrop = false; diff --git a/source/src/clients2c.cpp b/source/src/clients2c.cpp index 66ee1932..447265d4 100644 --- a/source/src/clients2c.cpp +++ b/source/src/clients2c.cpp @@ -335,7 +335,8 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) } s_strncpy(d->name, text, MAXNAMELEN+1); getstring(text, p); - filtertext(d->team, text, 0, MAXTEAMLEN); + d->team = getint(p); + if(!team_isvalid(d->team)) d->team = TEAM_VOID; setskin(d, getint(p)); if(m_flags) loopi(2) { @@ -398,8 +399,8 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) loopi(NUMGUNS) player1->mag[i] = getint(p); player1->state = CS_ALIVE; findplayerstart(player1, false, arenaspawn); - extern int nextskin; - if(player1->skin!=nextskin) setskin(player1, nextskin); + extern void nextskin_player1(); + nextskin_player1(); arenaintermission = 0; if(m_arena) { @@ -695,7 +696,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) conoutf("the round is over! next round in 5 seconds..."); if(m_botmode && acn==-2) hudoutf("the bots have won the round!"); else if(!alive) hudoutf("everyone died!"); - else if(m_teammode) hudoutf("team %s has won the round!", alive->team); + else if(m_teammode) hudoutf("team %s has won the round!", team_string(alive->team)); else if(alive==player1) hudoutf("you are the survivor!"); else hudoutf("%s is the survivor!", colorname(alive)); arenaintermission = lastmillis; @@ -731,7 +732,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) case SV_FORCETEAM: { - int team = getint(p), oldteam = team_int(player1->team); + int team = getint(p), oldteam = player1->team; int attr = getint(p); bool respawn = (attr & 1) == 1; changeteam(team, respawn); @@ -745,7 +746,7 @@ void parsemessages(int cn, playerent *d, ucharbuf &p) int fnt = getint(p); playerent *d = getclient(fpl); bool you = fpl == player1->clientnum; // sound? - bool et = team_int(player1->team) != fnt; + bool et = team_base(player1->team) != team_base(fnt); hudoutf("the server forced %s to%s team%s", you ? "you" : d ? colorname(d) : "", you ? "" : et ? " the enemy" : " your", you ? fnt ? " RVSF": " CLA" : ""); break; } diff --git a/source/src/entities.cpp b/source/src/entities.cpp index bb389ca2..07892ed8 100644 --- a/source/src/entities.cpp +++ b/source/src/entities.cpp @@ -106,7 +106,7 @@ void renderentities() { if(e.type==CTF_FLAG) { - s_sprintfd(path)("pickups/flags/%s", team_string(e.attr2)); + s_sprintfd(path)("pickups/flags/%s", team_basestring(e.attr2)); rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(e.x, e.y, (float)S(e.x, e.y)->floor), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); } else if(e.type==CLIP && !stenciling) renderclip(e); @@ -134,7 +134,7 @@ void renderentities() if(f.actor && f.actor != player1) { if(OUTBORD(f.actor->o.x, f.actor->o.y)) break; - s_sprintfd(path)("pickups/flags/small_%s%s", m_ktf ? "" : team_string(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); + s_sprintfd(path)("pickups/flags/small_%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); rendermodel(path, ANIM_FLAG|ANIM_START|ANIM_DYNALLOC, 0, 0, vec(f.actor->o).add(vec(0, 0, 0.3f+(sinf(lastmillis/100.0f)+1)/10)), lastmillis/2.5f, 0, 120.0f); } break; @@ -144,7 +144,7 @@ void renderentities() { if(OUTBORD(f.pos.x, f.pos.y)) break; entity &e = *f.flagent; - s_sprintfd(path)("pickups/flags/%s%s", m_ktf ? "" : team_string(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); + s_sprintfd(path)("pickups/flags/%s%s", m_ktf ? "" : team_basestring(i), m_htf ? "_htf" : m_ktf ? "ktf" : ""); rendermodel(path, ANIM_FLAG|ANIM_LOOP, 0, 0, vec(f.pos.x, f.pos.y, f.state==CTFF_INBASE ? (float)S(int(f.pos.x), int(f.pos.y))->floor : f.pos.z), (float)((e.attr1+7)-(e.attr1+7)%15), 0, 120.0f); break; } @@ -212,7 +212,7 @@ void trypickupflag(int flag, playerent *d) flaginfo &f = flaginfos[flag]; flaginfo &of = flaginfos[team_opposite(flag)]; if(f.state == CTFF_STOLEN) return; - bool own = flag == team_int(d->team); + bool own = flag == team_base(d->team); if(m_ctf) { diff --git a/source/src/entity.h b/source/src/entity.h index 869031bf..b0cf6db3 100644 --- a/source/src/entity.h +++ b/source/src/entity.h @@ -82,14 +82,25 @@ static inline int reloadtime(int gun) { return guns[gun].reloadtime; } static inline int attackdelay(int gun) { return guns[gun].attackdelay; } static inline int magsize(int gun) { return guns[gun].magsize; } -#define isteam(a,b) (m_teammode && strcmp(a, b)==0) +enum { TEAM_CLA = 0, TEAM_RVSF, TEAM_CLA_SPECT, TEAM_RVSF_SPECT, TEAM_SPECT, TEAM_NUM }; +static const char *teamnames[] = {"CLA", "RVSF", "CLA-SPECT", "RVSF-SPECT", "SPECTATOR", "void"}; +static const char *teamnames_s[] = {"CLA", "RVSF", "CSPC", "RSPC", "SPEC", "void"}; -#define TEAM_CLA 0 -#define TEAM_RVSF 1 -#define team_valid(t) (!strcmp(t, "RVSF") || !strcmp(t, "CLA")) -#define team_string(t) ((t) ? "RVSF" : "CLA") -#define team_int(t) (strcmp((t), "CLA") == 0 ? TEAM_CLA : TEAM_RVSF) -#define team_opposite(o) ((o) == TEAM_CLA ? TEAM_RVSF : TEAM_CLA) +#define TEAM_VOID TEAM_NUM +#define isteam(a,b) (m_teammode && (a) == (b)) +#define team_opposite(o) (team_isvalid(o) && (o) < TEAM_SPECT ? (o) ^ 1 : TEAM_SPECT) +#define team_base(t) ((t) & 1) +#define team_basestring(t) ((t) == 1 ? teamnames[1] : ((t) == 0 ? teamnames[0] : "SPECT")) +#define team_isvalid(t) ((int(t)) >= 0 && (t) < TEAM_NUM) +#define team_isactive(t) ((t) == TEAM_CLA || (t) == TEAM_RVSF) +#define team_isspect(t) ((t) > 1) +// note: team_isactive and team_base can/should be used to check the limits for arrays of size '2' +static inline const char *team_string(int t, bool abbr = false) { const char **n = abbr ? teamnames_s : teamnames; return team_isvalid(t) ? n[t] : n[TEAM_NUM]; } + +//#define team_valid(t) (!strcmp(t, "RVSF") || !strcmp(t, "CLA")) +//#define team_string(t) ((t) ? "RVSF" : "CLA") +//#define team_int(t) (strcmp((t), "CLA") == 0 ? TEAM_CLA : TEAM_RVSF) +//#define team_opposite(o) ((o) == TEAM_CLA ? TEAM_RVSF : TEAM_CLA) enum { ENT_PLAYER = 0, ENT_BOT, ENT_CAMERA, ENT_BOUNCE }; enum { CS_ALIVE = 0, CS_DEAD, CS_SPAWNING, CS_LAGGED, CS_EDITING, CS_SPECTATE }; @@ -185,7 +196,6 @@ public: }; #define MAXNAMELEN 15 -#define MAXTEAMLEN 4 class bounceent; @@ -354,7 +364,8 @@ public: int lastaction, lastmove, lastpain, lastvoicecom; int clientrole; bool attacking; - string name, team; + string name; + int team; int weaponchanging; int nextweapon; // weapon we switch to int skin; @@ -378,11 +389,11 @@ public: playerent() : clientnum(-1), lastupdate(0), plag(0), ping(0), lifesequence(0), frags(0), flagscore(0), deaths(0), lastpain(0), lastvoicecom(0), clientrole(CR_DEFAULT), skin(0), spectatemode(SM_NONE), followplayercn(-1), eardamagemillis(0), respawnoffset(0), prevweaponsel(NULL), weaponsel(NULL), nextweaponsel(NULL), primweap(NULL), nextprimweap(NULL), lastattackweapon(NULL), - smoothmillis(-1), + smoothmillis(-1), team(0), head(-1, -1, -1) { type = ENT_PLAYER; - name[0] = team[0] = 0; + name[0] = 0; maxeyeheight = 4.5f; aboveeye = 0.7f; radius = 1.1f; diff --git a/source/src/renderhud.cpp b/source/src/renderhud.cpp index da76fa58..72125b62 100644 --- a/source/src/renderhud.cpp +++ b/source/src/renderhud.cpp @@ -408,7 +408,7 @@ void drawradar(playerent *p, int w, int h) { playerent *pl = players[i]; if(!pl || pl==p || !isteam(p->team, pl->team) || !insideradar(centerpos, res/2, pl->o)) continue; - drawradarent(pl->o.x*coordtrans, pl->o.y*coordtrans, pl->yaw, pl->state==CS_ALIVE ? (isattacking(pl) ? 2 : 0) : 1, team_int(pl->team), iconsize, isattacking(pl), "%s", colorname(pl)); + drawradarent(pl->o.x*coordtrans, pl->o.y*coordtrans, pl->yaw, pl->state==CS_ALIVE ? (isattacking(pl) ? 2 : 0) : 1, team_base(pl->team), iconsize, isattacking(pl), "%s", colorname(pl)); } if(m_flags) { @@ -430,7 +430,7 @@ void drawradar(playerent *p, int w, int h) if(f.actor) { pos.add(f.actor->o); - bool tm = i != team_int(p->team); + bool tm = i != team_base(p->team); if(m_htf) tm = !tm; else if(m_ktf) tm = true; if(tm && insideradar(centerpos, res/2, pos)) @@ -476,7 +476,7 @@ void drawteamicons(int w, int h) glColor3f(1, 1, 1); static Texture *icons = NULL; if(!icons) icons = textureload("packages/misc/teamicons.png", 3); - quad(icons->id, VIRTW-VIRTH/12-10, 10, VIRTH/12, team_int(player1->team) ? 0.5f : 0, 0, 0.49f, 1.0f); + quad(icons->id, VIRTW-VIRTH/12-10, 10, VIRTH/12, team_base(player1->team) ? 0.5f : 0, 0, 0.49f, 1.0f); } int damageblendmillis = 0; diff --git a/source/src/rendermodel.cpp b/source/src/rendermodel.cpp index d18cc494..d78c6d77 100644 --- a/source/src/rendermodel.cpp +++ b/source/src/rendermodel.cpp @@ -692,8 +692,8 @@ void updateclientname(playerent *d) void renderclient(playerent *d) { if(!d) return; - const char *cs = NULL, *skinbase = SKINBASE; - int team = team_int(d->team); + int team = team_base(d->team); + const char *cs = NULL, *skinbase = SKINBASE, *teamname = team_basestring(team); int skinid = 1 + max(0, min(d->skin, (team==TEAM_CLA ? 3 : 5))); string skin; if(hidecustomskins == 0 || (hidecustomskins == 1 && !m_teammode)) @@ -705,11 +705,11 @@ void renderclient(playerent *d) s_sprintf(skin)("%s/custom/%s.jpg", skinbase, cs); else { - if(!m_teammode || !teamdisplaymode) s_sprintf(skin)("%s/%s/%02i.jpg", skinbase, team_string(team), skinid); + if(!m_teammode || !teamdisplaymode) s_sprintf(skin)("%s/%s/%02i.jpg", skinbase, teamname, skinid); else switch(teamdisplaymode) { - case 1: s_sprintf(skin)("%s/%s/%02i_%svest.jpg", skinbase, team_string(team), skinid, team ? "blue" : "red"); break; - case 2: default: s_sprintf(skin)("%s/%s/%s.jpg", skinbase, team_string(team), team ? "blue" : "red"); break; + case 1: s_sprintf(skin)("%s/%s/%02i_%svest.jpg", skinbase, teamname, skinid, team ? "blue" : "red"); break; + case 2: default: s_sprintf(skin)("%s/%s/%s.jpg", skinbase, teamname, team ? "blue" : "red"); break; } } string vwep; diff --git a/source/src/scoreboard.cpp b/source/src/scoreboard.cpp index ca9d0bb5..c6ce857e 100644 --- a/source/src/scoreboard.cpp +++ b/source/src/scoreboard.cpp @@ -117,7 +117,7 @@ void renderteamscore(void *menu, teamscore *t) if(m_flags) s_sprintf(line.s)("%d\t%d\t%d\t%.*f\t\t\t\t%s\t\t%s", t->flagscore, t->frags, t->deaths, sr.precision, sr.ratio, team_string(t->team), plrs); else if(m_teammode) s_sprintf(line.s)("%d\t%d\t%.*f\t\t\t\t%s\t\t%s", t->frags, t->deaths, sr.precision, sr.ratio, team_string(t->team), plrs); static color teamcolors[2] = { color(1.0f, 0, 0, 0.2f), color(0, 0, 1.0f, 0.2f) }; - line.bgcolor = &teamcolors[t->team]; + line.bgcolor = &teamcolors[team_base(t->team)]; loopv(t->teammembers) renderscore(menu, t->teammembers[i]); } @@ -172,9 +172,9 @@ void renderscores(void *menu, bool init) loopv(players) { if(!players[i]) continue; - teamscores[team_int(players[i]->team)].addscore(players[i]); + teamscores[team_base(players[i]->team)].addscore(players[i]); } - if(!watchingdemo) teamscores[team_int(player1->team)].addscore(player1); + if(!watchingdemo) teamscores[team_base(player1->team)].addscore(player1); loopi(2) teamscores[i].teammembers.sort(scorecmp); int sort = teamscorecmp(&teamscores[TEAM_CLA], &teamscores[TEAM_RVSF]); @@ -250,7 +250,7 @@ const char *asciiscores(bool destjpg) { d = scores[i]; sr.calc(d->frags, d->deaths); - s_sprintf(team)(destjpg ? ", %s" : " %-4s", d->team); + s_sprintf(team)(destjpg ? ", %s" : " %-4s", team_string(d->team, true)); s_sprintf(flags)(destjpg ? "%d/" : " %4d ", d->flagscore); if(destjpg) s_sprintf(text)("%s%s (%s%d/%d)\n", d->name, m_teammode ? team : "", m_flags ? flags : "", d->frags, d->deaths); diff --git a/source/src/server.cpp b/source/src/server.cpp index 1a2f8958..89289728 100644 --- a/source/src/server.cpp +++ b/source/src/server.cpp @@ -244,7 +244,8 @@ struct client // server side version of "dynent" type int clientnum; ENetPeer *peer; string hostname; - string name, team; + string name; + int team; char lang[3]; int ping; int skin; @@ -290,8 +291,9 @@ struct client // server side version of "dynent" type void reset() { - name[0] = team[0] = demoflags = 0; + name[0] = demoflags = 0; ping = 9999; + team = TEAM_VOID; skin = 0; position.setsizenodelete(0); messages.setsizenodelete(0); @@ -494,9 +496,9 @@ int freeteam(int pl = -1) int teamscore[2] = {0, 0}; int t; int sum = calcscores(); - loopv(clients) if(clients[i]->type!=ST_EMPTY && i != pl && clients[i]->isauthed) + loopv(clients) if(clients[i]->type!=ST_EMPTY && i != pl && clients[i]->isauthed && team_isactive(clients[i]->team)) { - t = team_int(clients[i]->team); + t = team_base(clients[i]->team); teamsize[t]++; teamscore[t] += clients[i]->at3_score; } @@ -787,7 +789,7 @@ void setupdemorecord() ucharbuf q(&buf[sizeof(header)], sizeof(buf)-sizeof(header)); putint(q, SV_INITC2S); sendstring(ci->name, q); - sendstring(ci->team, q); + putint(q, ci->team); putint(q, ci->skin); ucharbuf h(header, sizeof(header)); @@ -1029,7 +1031,7 @@ void flagaction(int flag, int action, int actor) { if(deadactor || f.state == CTFF_STOLEN) return; flagdistance(f, actor); - int team = team_int(clients[actor]->team); + int team = team_base(clients[actor]->team); if(m_ctf) team = team_opposite(team); if(team != flag) return; f.state = CTFF_STOLEN; @@ -1133,7 +1135,7 @@ void flagaction(int flag, int action, int actor) logline(ACLOG_INFO,"[%s] %s returned the flag", c.hostname, c.name); break; case FM_SCORE: - logline(ACLOG_INFO, "[%s] %s scored with the flag for %s, new score %d", c.hostname, c.name, c.team, c.state.flagscore); + logline(ACLOG_INFO, "[%s] %s scored with the flag for %s, new score %d", c.hostname, c.name, team_string(c.team), c.state.flagscore); break; case FM_KTFSCORE: logline(ACLOG_INFO, "[%s] %s scored, carrying for %d seconds, new score %d", c.hostname, c.name, (gamemillis - f.stolentime) / 1000, c.state.flagscore); @@ -1203,7 +1205,7 @@ void htf_forceflag(int flag) int besthealth = 0, numbesthealth = 0; loopv(clients) if(clients[i]->type!=ST_EMPTY) { - if(clients[i]->state.state == CS_ALIVE && team_int(clients[i]->team) == flag) + if(clients[i]->state.state == CS_ALIVE && team_base(clients[i]->team) == flag) { if(clients[i]->state.health == besthealth) numbesthealth++; @@ -1222,7 +1224,7 @@ void htf_forceflag(int flag) int pick = rnd(numbesthealth); loopv(clients) if(clients[i]->type!=ST_EMPTY) { - if(clients[i]->state.state == CS_ALIVE && team_int(clients[i]->team) == flag && --pick < 0) + if(clients[i]->state.state == CS_ALIVE && team_base(clients[i]->team) == flag && --pick < 0) { f.state = CTFF_STOLEN; f.actor_cn = i; @@ -1263,7 +1265,7 @@ void distributeteam(int team) tdistrib.setsize(0); loopv(clients) if(clients[i]->type!=ST_EMPTY) { - if(team == 100 || team == team_int(clients[i]->team)) + if(team == 100 || team == clients[i]->team) { tdistrib.add(i); clients[i]->at3_score = rand(); @@ -1346,7 +1348,7 @@ void arenacheck() if(c.state.state==CS_ALIVE || (c.state.state==CS_DEAD && c.state.lastspawn>=0)) { if(!alive) alive = &c; - else if(!m_teammode || strcmp(alive->team, c.team)) return; + else if(!m_teammode || alive->team != c.team) return; } else if(c.state.state==CS_DEAD) { @@ -1392,7 +1394,7 @@ bool spamdetect(client *cl, char *text) // checks doubled lines and average typi void sendteamtext(char *text, int sender) { - if(!valid_client(sender) || !clients[sender]->team[0]) return; + if(!valid_client(sender) || clients[sender]->team == TEAM_VOID) return; ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); ucharbuf p(packet->data, packet->dataLength); putint(p, SV_TEAMTEXT); @@ -1401,7 +1403,7 @@ void sendteamtext(char *text, int sender) enet_packet_resize(packet, p.length()); loopv(clients) if(i!=sender) { - if(!strcmp(clients[i]->team, clients[sender]->team) || !m_teammode) // send to everyone in non-team mode + if(clients[i]->team == clients[sender]->team || !m_teammode) // send to everyone in non-team mode sendpacket(i, 1, packet); } if(packet->referenceCount==0) enet_packet_destroy(packet); @@ -1409,7 +1411,7 @@ void sendteamtext(char *text, int sender) void sendvoicecomteam(int sound, int sender) { - if(!valid_client(sender) || !clients[sender]->team[0]) return; + if(!valid_client(sender) || clients[sender]->team == TEAM_VOID) return; ENetPacket *packet = enet_packet_create(NULL, MAXTRANS, ENET_PACKET_FLAG_RELIABLE); ucharbuf p(packet->data, packet->dataLength); putint(p, SV_VOICECOMTEAM); @@ -1418,7 +1420,7 @@ void sendvoicecomteam(int sound, int sender) enet_packet_resize(packet, p.length()); loopv(clients) if(i!=sender) { - if(!strcmp(clients[i]->team, clients[sender]->team) || !m_teammode) + if(clients[i]->team == clients[sender]->team || !m_teammode) sendpacket(i, 1, packet); } if(packet->referenceCount==0) enet_packet_destroy(packet); @@ -2064,15 +2066,14 @@ bool refillteams(bool now, bool notify) // force only minimal amounts of player c->at3_dontmove = true; if(c->isauthed) { - int t = 0; - if(!strcmp(c->team, "CLA") || t++ || !strcmp(c->team, "RVSF")) // need exact teams here + if(team_isactive(c->team)) // only active players count { - teamsize[t]++; - teamscore[t] += c->at3_score; + teamsize[c->team]++; + teamscore[c->team] += c->at3_score; if(clienthasflag(i) < 0) { c->at3_dontmove = false; - moveable[t]++; + moveable[c->team]++; if(c->lastforce && (servmillis - c->lastforce) < 3000) return false; // possible unanswered forceteam commands } } @@ -2088,7 +2089,7 @@ bool refillteams(bool now, bool notify) // force only minimal amounts of player if(now || gamemillis - lasttime_eventeams > 8000 + allplayers * 1000 || diffnum > 2 + allplayers / 10) { // time to even out teams - loopv(clients) if(clients[i]->type!=ST_EMPTY && team_int(clients[i]->team) != bigteam) clients[i]->at3_dontmove = true; // dont move small team players + loopv(clients) if(clients[i]->type!=ST_EMPTY && clients[i]->team != bigteam) clients[i]->at3_dontmove = true; // dont move small team players while(diffnum > 1 && moveable[bigteam] > 0) { // pick best fitting cn @@ -2968,12 +2969,12 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 filtertext(text, text); if(!spamdetect(cl, text)) { - logline(ACLOG_INFO, "[%s] %s says to team %s: '%s'", cl->hostname, cl->name, cl->team, text); + logline(ACLOG_INFO, "[%s] %s says to team %s: '%s'", cl->hostname, cl->name, team_string(cl->team), text); sendteamtext(text, sender); } else { - logline(ACLOG_INFO, "[%s] %s says to team %s: '%s', SPAM detected", cl->hostname, cl->name, cl->team, text); + logline(ACLOG_INFO, "[%s] %s says to team %s: '%s', SPAM detected", cl->hostname, cl->name, team_string(cl->team), text); sendservmsg("\f3please do not spam", sender); } break; @@ -3016,9 +3017,8 @@ void process(ENetPacket *packet, int sender, int chan) // sender may be -1 bool namechanged = strcmp(cl->name, text) != 0; if(namechanged) logline(ACLOG_INFO,"[%s] %s changed his name to %s", cl->hostname, cl->name, text); s_strncpy(cl->name, text, MAXNAMELEN+1); - getstring(text, p); - filtertext(cl->team, text, 0, MAXTEAMLEN); - QUEUE_STR(text); + cl->team = getint(p); + if(!team_isvalid(cl->team)) cl->team = TEAM_VOID; cl->skin = getint(p); QUEUE_MSG; if(namechanged) @@ -3613,16 +3613,18 @@ void loggamestatus(const char *reason) { client &c = *clients[i]; if(c.type == ST_EMPTY || !c.name[0]) continue; - s_sprintf(text)("%2d %-16s ", c.clientnum, c.name); // cn name - if(m_teammode) s_strcatf(text, "%-4s ", c.team); // team - if(m_flags) s_strcatf(text, "%4d ", c.state.flagscore); // flag - s_strcatf(text, "%4d %5d", c.state.frags, c.state.deaths); // frag death - if(m_teammode) s_strcatf(text, " %2d", c.state.teamkills); // tk + s_sprintf(text)("%2d %-16s ", c.clientnum, c.name); // cn name + if(m_teammode) s_strcatf(text, "%-4s ", team_string(c.team, true)); // teamname (abbreviated) + if(m_flags) s_strcatf(text, "%4d ", c.state.flagscore); // flag + s_strcatf(text, "%4d %5d", c.state.frags, c.state.deaths); // frag death + if(m_teammode) s_strcatf(text, " %2d", c.state.teamkills); // tk logline(ACLOG_INFO, "%s%5d %s %s", text, c.ping, c.role == CR_ADMIN ? "admin " : "normal", c.hostname); - n = team_int(c.team); - flagscore[n] += c.state.flagscore; - fragscore[n] += c.state.frags; - pnum[n] += 1; + if(team_isactive(c.team)) + { + flagscore[c.team] += c.state.flagscore; + fragscore[c.team] += c.state.frags; + pnum[c.team] += 1; + } } if(m_teammode) { @@ -3923,7 +3925,7 @@ void extinfo_statsbuf(ucharbuf &p, int pid, int bpos, ENetSocket &pongsock, ENet putint(p,clients[i]->clientnum); //add player id putint(p,clients[i]->ping); //Ping sendstring(clients[i]->name,p); //Name - sendstring(clients[i]->team,p); //Team + sendstring(team_string(clients[i]->team),p); //Team putint(p,clients[i]->state.frags); //Frags putint(p,clients[i]->state.flagscore); //Flagscore putint(p,clients[i]->state.deaths); //Death @@ -3953,43 +3955,20 @@ void extinfo_teamscorebuf(ucharbuf &p) putint(p, minremain); if(!m_teammode) return; - cvector teams; - bool addteam; - loopv(clients) if(clients[i]->type!=ST_EMPTY) + int teamsizes[TEAM_NUM] = { 0 }, fragscores[TEAM_NUM] = { 0 }, flagscores[TEAM_NUM] = { 0 }; + loopv(clients) if(clients[i]->type!=ST_EMPTY && team_isvalid(clients[i]->team)) { - addteam = true; - loopvj(teams) - { - if(strcmp(clients[i]->team,teams[j])==0 || !clients[i]->team[0]) - { - addteam = false; - break; - } - } - if(addteam) teams.add(clients[i]->team); + teamsizes[clients[i]->team] += 1; + fragscores[clients[i]->team] += clients[i]->state.frags; + flagscores[clients[i]->team] += clients[i]->state.flagscore; } - loopv(teams) + loopi(TEAM_NUM) if(teamsizes[i]) { - sendstring(teams[i],p); //team - int fragscore = 0; - int flagscore = 0; - loopvj(clients) if(clients[j]->type!=ST_EMPTY) - { - if(!(strcmp(clients[j]->team,teams[i])==0)) continue; - fragscore += clients[j]->state.frags; - flagscore += clients[j]->state.flagscore; - } - putint(p,fragscore); //add fragscore per team - if(m_flags) //when capture mode - { - putint(p,flagscore); //add flagscore per team - } - else //all other team modes - { - putint(p,-1); //flagscore not available - } - putint(p,-1); + sendstring(team_string(i), p); // team name + putint(p, fragscores[i]); // add fragscore per team + putint(p, m_flags ? flagscores[i] : -1); // add flagscore per team + putint(p, -1); // ? } } diff --git a/source/src/serveractions.h b/source/src/serveractions.h index 5e7da753..d23a97ba 100644 --- a/source/src/serveractions.h +++ b/source/src/serveractions.h @@ -126,7 +126,7 @@ struct playeraction : serveraction struct forceteamaction : playeraction { - void perform() { forceteam(cn, team_opposite(team_int(clients[cn]->team)), true); } + void perform() { forceteam(cn, team_opposite(clients[cn]->team), true); } virtual bool isvalid() { return m_teammode && valid_client(cn); } forceteamaction(int cn, int caller) : playeraction(cn) {