summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpasky <pasky@openttd.org>2005-03-27 00:28:14 +0000
committerpasky <pasky@openttd.org>2005-03-27 00:28:14 +0000
commit0c5d61bd56cb8ec4c2caa8aadb9c397c6931b544 (patch)
treefa4b74ffb1e7fe3ea3fcd1105aa17c0490f7a41c
parente416fe8066a4f959212391333ca4dbec1595e007 (diff)
downloadopenttd-0c5d61bd56cb8ec4c2caa8aadb9c397c6931b544.tar.xz
(svn r2080) - Fix: [OldAI] p->ai.state_counter was uint16 but could hold a tile index, therefore overflowing - changed that to uint32 and bumped the savegame revision to 32. It *MIGHT* close bug 1151374 - it certainly caused AI to stop building anything sometimes.
- While at it, use TileIndex as the tile index type in AiRemovePlayerRailOrRoad() and AiStateRemoveTrack(). - Make the number of tiles scanned 4*MapSizeX() instead of 1000. It *MIGHT* close bug 1116614.
-rw-r--r--ai.c7
-rw-r--r--player.h2
-rw-r--r--players.c3
-rw-r--r--saveload.c2
4 files changed, 8 insertions, 6 deletions
diff --git a/ai.c b/ai.c
index 18bdc162f..f740cb28d 100644
--- a/ai.c
+++ b/ai.c
@@ -3640,7 +3640,7 @@ static void AiStateRemoveStation(Player *p)
}
-static void AiRemovePlayerRailOrRoad(Player *p, uint tile)
+static void AiRemovePlayerRailOrRoad(Player *p, TileIndex tile)
{
byte m5;
@@ -3758,10 +3758,11 @@ pos_3:
static void AiStateRemoveTrack(Player *p)
{
- int num = 1000;
+ /* Was 1000 for standard 8x8 maps. */
+ int num = MapSizeX() * 4;
do {
- uint tile = ++p->ai.state_counter;
+ TileIndex tile = ++p->ai.state_counter;
// Iterated all tiles?
if (tile >= MapSize()) {
diff --git a/player.h b/player.h
index 2c93c2b0e..2fc8fd89b 100644
--- a/player.h
+++ b/player.h
@@ -27,7 +27,7 @@ typedef struct AiBuildRec {
typedef struct PlayerAI {
byte state;
byte tick; // Used to determine how often to move
- uint16 state_counter;
+ uint32 state_counter; // Can hold tile index!
uint16 timeout_counter;
byte state_mode;
diff --git a/players.c b/players.c
index 64c6c5252..eb5733494 100644
--- a/players.c
+++ b/players.c
@@ -974,7 +974,8 @@ static const byte _player_economy_desc[] = {
static const byte _player_ai_desc[] = {
SLE_VAR(PlayerAI,state, SLE_UINT8),
SLE_VAR(PlayerAI,tick, SLE_UINT8),
- SLE_VAR(PlayerAI,state_counter, SLE_UINT16),
+ SLE_CONDVAR(PlayerAI,state_counter, SLE_FILE_U16 | SLE_VAR_U32, 0, 12),
+ SLE_CONDVAR(PlayerAI,state_counter, SLE_UINT32, 13, 255),
SLE_VAR(PlayerAI,timeout_counter, SLE_UINT16),
SLE_VAR(PlayerAI,state_mode, SLE_UINT8),
diff --git a/saveload.c b/saveload.c
index d436e97f3..e9e504a5c 100644
--- a/saveload.c
+++ b/saveload.c
@@ -8,7 +8,7 @@
#include "saveload.h"
enum {
- SAVEGAME_MAJOR_VERSION = 0xC,
+ SAVEGAME_MAJOR_VERSION = 13,
SAVEGAME_MINOR_VERSION = 0x1,
SAVEGAME_LOADABLE_VERSION = (SAVEGAME_MAJOR_VERSION << 8) + SAVEGAME_MINOR_VERSION