]> git.pond.sub.org Git - empserver/commitdiff
(game_reset_tick): New.
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 15 Jul 2007 09:01:58 +0000 (09:01 +0000)
committerMarkus Armbruster <armbru@pond.sub.org>
Sun, 15 Jul 2007 09:01:58 +0000 (09:01 +0000)
(prod_nat): Use it.

include/game.h
src/lib/common/game.c
src/lib/update/nat.c

index 877230d061d1957d0a021e624467e0c147cf3a0a..1a5f1f3678cb5295801156f936b4fc730e566f9a 100644 (file)
@@ -56,5 +56,6 @@ extern void game_record_update(time_t);
 extern struct gamestr *game_tick_tick(void);
 extern int game_tick_to_now(short *);
 extern int game_step_a_tick(struct gamestr *, short *);
+extern int game_reset_tick(short *);
 
 #endif
index 74318773c1aaa143282d41d25160e0c6ece9ba65..25dcea036ffc2b39b69ff07f91f411a7ff8e60ed 100644 (file)
 /*
  * On Empire Time:
  *
- * A turn is terminated by an update and consists of etu_per_update
- * ETUs.  The Empire clock counts turns and ETUs.  When updates move
- * around in real time (schedule change, downtime, etc.), the Empire
- * clock automatically adapts the length of an ETU in seconds
+ * An Empire turn is terminated by an update.  The Empire clock counts
+ * turns and ETUs, i.e. it ticks etu_per_update times per turn.  When
+ * updates move around in real time (schedule change, downtime, etc.),
+ * the Empire clock automatically adapts the duration of an ETU
  * accordingly.
  */
 
@@ -127,11 +127,27 @@ game_tick_to_now(short *tick)
 int
 game_step_a_tick(struct gamestr *game, short *tick)
 {
-    int d;
+    int etu;
 
-    d = game->game_tick - *tick;
-    if (CANT_HAPPEN(d < 0))
-       d = 0;
+    etu = game->game_tick - *tick;
+    if (CANT_HAPPEN(etu < 0))
+       etu = 0;
     *tick = game->game_tick;
-    return d;
+    return etu;
+}
+
+/*
+ * Reset ETU timestamp *TICK to zero.
+ * Return how many ETUs it had left until etu_per_update.
+ */
+int
+game_reset_tick(short *tick)
+{
+    int etu;
+
+    etu = etu_per_update - *tick;
+    if (CANT_HAPPEN(etu < 0))
+       etu = 0;
+    *tick = 0;
+    return etu;
 }
index 22a3cf19c26fd8c18b37ad4edf2df39b0d8c169e..8f8dc3d0f8318bbc9f2e4bd619560a26029990f9 100644 (file)
@@ -36,6 +36,7 @@
 
 #include <math.h>
 #include "budg.h"
+#include "game.h"
 #include "item.h"
 #include "update.h"
 
@@ -133,8 +134,7 @@ prod_nat(int etu)
     struct natstr *cnp;
 
     for (n = 0; NULL != (np = getnatp(n)); n++) {
-       grant_btus(np, etu_per_update - np->nat_access);
-       np->nat_access = 0;
+       grant_btus(np, game_reset_tick(&np->nat_access));
        if (np->nat_stat < STAT_ACTIVE)
            continue;
        /*