From a01cc343c5cbecc6ec6cc58e2369d483346a68a2 Mon Sep 17 00:00:00 2001 From: Cyp Date: Thu, 24 Feb 2011 22:40:31 +0100 Subject: [PATCH] Fix scores usually being displayed as 0 in multiplayer. Scores were 0 due to some complicated score synchronisation code. Fixed mainly by removing a lot of the score synchronisation code. --- src/multiplay.h | 4 +- src/multistat.cpp | 92 +++++++++++----------------------------------- src/multistat.h | 11 ++---- src/multisync.cpp | 28 +++----------- src/projectile.cpp | 6 +-- 5 files changed, 35 insertions(+), 106 deletions(-) diff --git a/src/multiplay.h b/src/multiplay.h index cd7ac0a87..a1878c237 100644 --- a/src/multiplay.h +++ b/src/multiplay.h @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2010 Warzone 2100 Project + Copyright (C) 2005-2011 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -220,7 +220,7 @@ extern BOOL addTemplateToList(DROID_TEMPLATE *psNew, DROID_TEMPLATE **ppList); void addTemplateBack(unsigned player, DROID_TEMPLATE *psNew); // syncing. -extern BOOL sendCheck (void); //send/recv check info +void sendCheck(); //send/recv check info extern BOOL sendScoreCheck (void); //score check only(frontend) extern BOOL sendPing (void); // allow game to request pings. diff --git a/src/multistat.cpp b/src/multistat.cpp index 864404077..fd1d59360 100644 --- a/src/multistat.cpp +++ b/src/multistat.cpp @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2010 Warzone 2100 Project + Copyright (C) 2005-2011 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -48,17 +48,15 @@ PLAYERSTATS getMultiStats(UDWORD player) // //////////////////////////////////////////////////////////////////////////// // Set Player's stats // send stats to all players when bLocal is false -BOOL setMultiStats(SDWORD player, PLAYERSTATS plStats, BOOL bLocal) +bool setMultiStats(uint32_t playerIndex, PLAYERSTATS plStats, bool bLocal) { - uint32_t playerIndex = (uint32_t)player; - if (playerIndex >= MAX_PLAYERS) { return true; } // First copy over the data into our local array - memcpy(&playerStats[playerIndex], &plStats, sizeof(plStats)); + playerStats[playerIndex] = plStats; if (!bLocal) { @@ -75,8 +73,6 @@ BOOL setMultiStats(SDWORD player, PLAYERSTATS plStats, BOOL bLocal) NETuint32_t(&playerStats[playerIndex].totalScore); NETuint32_t(&playerStats[playerIndex].recentKills); NETuint32_t(&playerStats[playerIndex].recentScore); - NETuint32_t(&playerStats[playerIndex].killsToAdd); - NETuint32_t(&playerStats[playerIndex].scoreToAdd); NETend(); } @@ -108,8 +104,6 @@ void recvMultiStats(NETQUEUE queue) NETuint32_t(&playerStats[playerIndex].totalScore); NETuint32_t(&playerStats[playerIndex].recentKills); NETuint32_t(&playerStats[playerIndex].recentScore); - NETuint32_t(&playerStats[playerIndex].killsToAdd); - NETuint32_t(&playerStats[playerIndex].scoreToAdd); } NETend(); } @@ -165,8 +159,6 @@ BOOL loadMultiStats(char *sPlayerName, PLAYERSTATS *st) // reset recent scores st->recentKills = 0; st->recentScore = 0; - st->killsToAdd = 0; - st->scoreToAdd = 0; // clear any skirmish stats. for(size = 0;size= MAX_PLAYERS) { return; } - st = getMultiStats(selectedPlayer); - st.played ++; - setMultiStats(selectedPlayer, st, true); + ++playerStats[selectedPlayer].played; } // games won void updateMultiStatsWins(void) { - PLAYERSTATS st; - if (Cheated) + if (Cheated || selectedPlayer >= MAX_PLAYERS) { return; } - st = getMultiStats(selectedPlayer); - st.wins ++; - setMultiStats(selectedPlayer, st, true); + ++playerStats[selectedPlayer].wins; } //games lost. void updateMultiStatsLoses(void) { - PLAYERSTATS st; - if (Cheated) + if (Cheated || selectedPlayer >= MAX_PLAYERS) { return; } - st = getMultiStats(selectedPlayer); - ++st.losses; - setMultiStats(selectedPlayer, st, true); + ++playerStats[selectedPlayer].losses; } // update kills void updateMultiStatsKills(BASE_OBJECT *psKilled,UDWORD player) { - PLAYERSTATS st; - - if (Cheated) + if (Cheated || player > MAX_PLAYERS) { return; } // FIXME: Why in the world are we using two different structs for stats when we can use only one? - // Host controls self + AI, so update the scores for them as well. - if(myResponsibility(player) && NetPlay.bComms) + if (NetPlay.bComms) { - st = getMultiStats(player); - - if(NetPlay.bComms) - { - st.killsToAdd++; // increase kill count; - } - else - { - st.recentKills++; - } - setMultiStats(player, st, true); + ++playerStats[player].totalKills; + ++playerStats[player].recentKills; } else { diff --git a/src/multistat.h b/src/multistat.h index 32696aa53..fad55d128 100644 --- a/src/multistat.h +++ b/src/multistat.h @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2010 Warzone 2100 Project + Copyright (C) 2005-2011 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ #include "lib/netplay/netplay.h" -typedef struct +struct PLAYERSTATS { uint32_t played; /// propogated stats. uint32_t wins; @@ -37,15 +37,12 @@ typedef struct uint32_t recentKills; // score/kills in last game. uint32_t recentScore; - - uint32_t killsToAdd; // things to add next time score is updated. - uint32_t scoreToAdd; -} PLAYERSTATS; +}; BOOL saveMultiStats(const char *sFName, const char *sPlayerName, const PLAYERSTATS *playerStats); // to disk BOOL loadMultiStats(char *sPlayerName, PLAYERSTATS *playerStats); // form disk PLAYERSTATS getMultiStats(UDWORD player); // get from net -BOOL setMultiStats(SDWORD player, PLAYERSTATS plStats,BOOL bLocal); // send to net. +bool setMultiStats(uint32_t player, PLAYERSTATS plStats, bool bLocal); // send to net. void updateMultiStatsDamage(UDWORD attacker, UDWORD defender, UDWORD inflicted); void updateMultiStatsGames(void); void updateMultiStatsWins(void); diff --git a/src/multisync.cpp b/src/multisync.cpp index 686174e1e..33d77ee9c 100644 --- a/src/multisync.cpp +++ b/src/multisync.cpp @@ -1,7 +1,7 @@ /* This file is part of Warzone 2100. Copyright (C) 1999-2004 Eidos Interactive - Copyright (C) 2005-2010 Warzone 2100 Project + Copyright (C) 2005-2011 Warzone 2100 Project Warzone 2100 is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -113,21 +113,19 @@ static BOOL okToSend(void) // //////////////////////////////////////////////////////////////////////////// // Droid checking info. keep position and damage in sync. -BOOL sendCheck(void) +void sendCheck() { - UDWORD i; - NETgetBytesSent(); // update stats. NETgetBytesRecvd(); NETgetPacketsSent(); NETgetPacketsRecvd(); // dont send checks till all players are present. - for(i=0;iplayer), psStats->weaponEffect, psObj->psDest); // If we are in a multi-player game and the attacker is our responsibility - if (bMultiPlayer && psObj->psSource && myResponsibility(psObj->psSource->player)) + if (bMultiPlayer && psObj->psSource) { updateMultiStatsDamage(psObj->psSource->player, psObj->psDest->player, damage); } @@ -1206,7 +1206,7 @@ static void proj_ImpactFunc( PROJECTILE *psObj ) if (bMultiPlayer) { - if (psObj->psSource && myResponsibility(psObj->psSource->player)) + if (psObj->psSource) { updateMultiStatsDamage(psObj->psSource->player, psCurrD->player, damage); } @@ -1249,7 +1249,7 @@ static void proj_ImpactFunc( PROJECTILE *psObj ) if (bMultiPlayer) { - if (psObj->psSource && myResponsibility(psObj->psSource->player)) + if (psObj->psSource) { updateMultiStatsDamage(psObj->psSource->player, psCurrS->player,damage); }