/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
- * Ken Stevens, Steve McClure
+ * Copyright (C) 1986-2011, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Ken Stevens, Steve McClure, Markus Armbruster
*
- * This program is free software; you can redistribute it and/or modify
+ * Empire is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* ---
*
* ---
*
* game.c: Game file access
- *
+ *
* Known contributors to this file:
- * Markus Armbruster, 2007
+ * Markus Armbruster, 2007-2009
*/
/*
* 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.
*/
#include "prototypes.h"
#include "server.h"
+/*
+ * Enable / disable updates
+ */
+void
+game_ctrl_update(int enable)
+{
+ struct gamestr *game = getgamep();
+
+ game->game_upd_disable = !enable;
+ putgame();
+}
+
+/*
+ * Are updates disabled?
+ */
+int
+updates_disabled(void)
+{
+ return getgamep()->game_upd_disable;
+}
+
+/*
+ * Enable / disable play
+ */
+void
+game_ctrl_play(int enable)
+{
+ struct gamestr *game = getgamep();
+
+ game->game_down = !enable;
+ putgame();
+}
+
+/*
+ * Is playing enabled?
+ */
+int
+game_play_disabled(void)
+{
+ return getgamep()->game_down;
+}
+
+/*
+ * Notice that a player broke sanctuary.
+ * This starts the Empire clock if it hasn't been started yet.
+ */
+void
+game_note_bsanct(void)
+{
+ struct gamestr *game = getgamep();
+
+ if (game->game_rt == 0) {
+ game->game_rt = time(NULL);
+ putgame();
+ }
+}
+
/*
* Record an update in the game file, the current time is NOW.
+ * This starts the Empire clock if it hasn't been started yet.
*/
void
game_record_update(time_t now)
{
double secs;
- if (!update_time[0])
- return HUGE_VAL; /* no update scheduled */
+ if (!game->game_rt || !update_time[0])
+ return HUGE_VAL; /* not started or no update scheduled */
secs = update_time[0] - game->game_rt;
if (secs < 0)
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;
}