gamedate: no negative turns allowed.

feed the beast assert.
This commit is contained in:
Enno Rehling 2017-05-07 16:11:45 +02:00
parent 29061fa4ba
commit bf935f5bb7
5 changed files with 5 additions and 5 deletions

View file

@ -921,7 +921,7 @@ static int init_data(const char *filename, const char *catalog)
if (l) { if (l) {
return l; return l;
} }
if (turn < 0) { if (turn <= 0) {
turn = first_turn(); turn = first_turn();
} }
return 0; return 0;

View file

@ -27,8 +27,7 @@ const gamedate *get_gamedate(int turn, gamedate * gd)
int t = turn - first_turn(); int t = turn - first_turn();
assert(gd); assert(gd);
if (t < 0) assert(t >= 0);
t = turn;
gd->week = t % weeks_per_month; /* 0 - weeks_per_month-1 */ gd->week = t % weeks_per_month; /* 0 - weeks_per_month-1 */
gd->month = (t / weeks_per_month + first_month) % months_per_year; /* 0 - months_per_year-1 */ gd->month = (t / weeks_per_month + first_month) % months_per_year; /* 0 - months_per_year-1 */

View file

@ -96,7 +96,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
struct settings global; struct settings global;
bool lomem = false; bool lomem = false;
int turn = -1; int turn = 0;
const char *parameters[MAXPARAMS] = { const char *parameters[MAXPARAMS] = {
"LOCALE", "LOCALE",

View file

@ -4183,6 +4183,7 @@ static void reset_game(void)
void turn_begin(void) void turn_begin(void)
{ {
assert(turn >= 0);
++turn; ++turn;
reset_game(); reset_game();
} }

View file

@ -193,7 +193,7 @@ void test_log_stderr(int flags) {
static void test_reset(void) { static void test_reset(void) {
int i; int i;
turn = 0; turn = 1;
default_locale = 0; default_locale = 0;
if (errno) { if (errno) {