| tTies in GetNextShooter() are now broken by assigning each player a tiebreak value in chronological order (essentially increasing the time resolution of FightTimeout). - vaccinewars - be a doctor and try to vaccinate the world |
| git clone git://src.adamsgaard.dk/vaccinewars |
| Log |
| Files |
| Refs |
| README |
| LICENSE |
| --- |
| commit 0e4935ee1c40122c71f4aedf8c1c7d111b87ea2c |
| parent cc1a291a6612b1827661efce49266aedff9fd15b |
| Author: Ben Webb |
| Date: Fri, 26 Apr 2002 10:40:57 +0000
Ties in GetNextShooter() are now broken by assigning each player a tiebreak
value in chronological order (essentially increasing the time resolution
of FightTimeout).
Diffstat:
M src/dopewars.h | 1 +
M src/serverside.c | 32 +++++++++++++++++++++++++------
2 files changed, 27 insertions(+), 6 deletions(-)
--- |
| diff --git a/src/dopewars.h b/src/dopewars.h |
| t@@ -285,6 +285,7 @@ struct PLAYER_T {
Inventory *Guns, *Drugs, Bitches;
EventCode EventNum, ResyncNum;
time_t FightTimeout, IdleTimeout, ConnectTimeout;
+ guint tiebreak;
price_t DocPrice;
DopeList SpyList, TipList;
Player *OnBehalfOf; |
| diff --git a/src/serverside.c b/src/serverside.c |
| t@@ -2789,28 +2789,30 @@ Player *GetNextShooter(Player *Play)
{
Player *MinPlay, *Defend;
time_t MinTimeout;
+ guint mintie;
guint ArrayInd;
- gboolean Tie = FALSE;
if (!FightTimeout)
return NULL;
MinPlay = NULL;
MinTimeout = 0;
+ mintie = 0;
for (ArrayInd = 0; ArrayInd < Play->FightArray->len; ArrayInd++) {
Defend = (Player *)g_ptr_array_index(Play->FightArray, ArrayInd);
if (Defend == Play)
continue;
if (Defend->FightTimeout == 0)
return NULL;
- if (MinTimeout == 0 || Defend->FightTimeout <= MinTimeout) {
- Tie = (Defend->FightTimeout == MinTimeout);
+ if (MinTimeout == 0 || Defend->FightTimeout < MinTimeout
+ || (Defend->FightTimeout == MinTimeout && Defend->tiebreak < mintie)) {
MinPlay = Defend;
MinTimeout = Defend->FightTimeout;
+ mintie = Defend->tiebreak;
}
}
- return (Tie ? NULL : MinPlay);
+ return MinPlay;
}
void ResolveTipoff(Player *Play)
t@@ -3504,10 +3506,28 @@ int LoseBitch(Player *Play, Inventory *Guns, Inventory *Drugs)
*/
void SetFightTimeout(Player *Play)
{
- if (FightTimeout)
+ if (FightTimeout) {
Play->FightTimeout = time(NULL) + (time_t) FightTimeout;
- else
+
+ /* Make sure we have a higher tiebreak value than any other player with
+ * the same fight timeout (since FightTimeout only has second resolution,
+ * and possibly only microseconds have elapsed) */
+ Play->tiebreak = 0;
+ if (Play->FightTimeout) {
+ GSList *listpt;
+
+ for (listpt = FirstServer; listpt; listpt = g_slist_next(listpt)) {
+ Player *listplay = (Player *)listpt->data;
+
+ if (listplay && listplay != Play
+ && listplay->FightTimeout == Play->FightTimeout) {
+ Play->tiebreak = MAX(Play->tiebreak, listplay->tiebreak + 1);
+ }
+ }
+ }
+ } else {
Play->FightTimeout = 0;
+ }
}
/* |