Changeset - r2092:297c1ed07fe8
[Not reviewed]
master
0 3 0
truelight - 19 years ago 2005-07-17 13:34:19
truelight@openttd.org
(svn r2602) -Codechange: removed unused variable (disable_computer)
-Fix: Changed some stuff to make server-side AIs possible in the far future
3 files changed with 5 insertions and 6 deletions:
0 comments (0 inline, 0 general)
main_gui.c
Show inline comments
 
@@ -14,50 +14,48 @@
 
#include "command.h"
 
#include "news.h"
 
#include "town.h"
 
#include "vehicle.h"
 
#include "console.h"
 
#include "sound.h"
 
#include "network.h"
 
#include "signs.h"
 
#include "waypoint.h"
 

	
 
#include "network_data.h"
 
#include "network_client.h"
 
#include "network_server.h"
 

	
 
#include "table/animcursors.h"
 

	
 

	
 
/* Min/Max date for scenario editor */
 
static const uint MinDate = 0;     // 1920-01-01 (MAX_YEAR_BEGIN_REAL)
 
static const uint MaxDate = 29220; // 2000-01-01
 

	
 
extern void DoTestSave(void);
 
extern void DoTestLoad(void);
 

	
 
extern bool disable_computer;
 

	
 
static int _rename_id;
 
static int _rename_what;
 

	
 
static byte _terraform_size = 1;
 
static byte _last_built_railtype;
 
extern void GenerateWorld(int mode, uint size_x, uint size_y);
 

	
 
extern void GenerateIndustries(void);
 
extern void GenerateTowns(void);
 

	
 
void HandleOnEditTextCancel(void)
 
{
 
	switch(_rename_what) {
 
#ifdef ENABLE_NETWORK
 
	case 4:
 
		NetworkDisconnect();
 
		ShowNetworkGameWindow();
 
		break;
 
#endif /* ENABLE_NETWORK */
 
	}
 
}
 

	
 
void HandleOnEditText(WindowEvent *e)
 
{
openttd.c
Show inline comments
 
@@ -41,49 +41,48 @@
 
#include <gpmi.h>
 
#include <gpmi/packages/paths.h>
 
#endif /* GPMI */
 

	
 
void GenerateWorld(int mode, uint size_x, uint size_y);
 
void CallLandscapeTick(void);
 
void IncreaseDate(void);
 
void RunOtherPlayersLoop(void);
 
void DoPaletteAnimations(void);
 
void MusicLoop(void);
 
void ResetMusic(void);
 
void InitializeStations(void);
 
void DeleteAllPlayerStations(void);
 

	
 
extern void SetDifficultyLevel(int mode, GameOptions *gm_opt);
 
extern void DoStartupNewPlayer(bool is_ai);
 
extern void ShowOSErrorBox(const char *buf);
 

	
 
bool LoadSavegame(const char *filename);
 

	
 
extern void HalGameLoop(void);
 

	
 
uint32 _pixels_redrawn;
 
bool _dbg_screen_rect;
 
bool disable_computer; // We should get ride of this thing.. is only used for a debug-cheat
 
static byte _os_version = 0;
 

	
 
/* TODO: usrerror() for errors which are not of an internal nature but
 
 * caused by the user, i.e. missing files or fatal configuration errors.
 
 * Post-0.4.0 since Celestar doesn't want this in SVN before. --pasky */
 

	
 
void CDECL error(const char *s, ...) {
 
	va_list va;
 
	char buf[512];
 
	va_start(va, s);
 
	vsprintf(buf, s, va);
 
	va_end(va);
 

	
 
	ShowOSErrorBox(buf);
 
	if (_video_driver)
 
		_video_driver->stop();
 

	
 
	assert(0);
 
	exit(1);
 
}
 

	
 
void CDECL ShowInfoF(const char *str, ...)
 
{
 
	va_list va;
 
@@ -1011,49 +1010,49 @@ void StateGameLoop(void)
 
		SaveOrLoad(buf, SL_SAVE);
 
		if ((uint)_frame_counter >= _savedump_last) exit(1);
 
	}
 

	
 
	if (_game_mode == GM_EDITOR) {
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 
		CallWindowTickEvent();
 
		NewsLoop();
 
	} else {
 
		// All these actions has to be done from OWNER_NONE
 
		//  for multiplayer compatibility
 
		uint p = _current_player;
 
		_current_player = OWNER_NONE;
 

	
 
		AnimateAnimatedTiles();
 
		IncreaseDate();
 
		RunTileLoop();
 
		CallVehicleTicks();
 
		CallLandscapeTick();
 

	
 
		// To bad the AI does not work in multiplayer, because states are not saved
 
		//  perfectly
 
		if (!disable_computer && !_networking)
 
		if (!_networking)
 
			RunOtherPlayersLoop();
 

	
 
		CallWindowTickEvent();
 
		NewsLoop();
 
		_current_player = p;
 
	}
 

	
 
	_in_state_game_loop = false;
 
}
 

	
 
static void DoAutosave(void)
 
{
 
	char buf[200];
 

	
 
	if (_patches.keep_all_autosave && _local_player != OWNER_SPECTATOR) {
 
		const Player *p = GetPlayer(_local_player);
 
		char *s;
 
		sprintf(buf, "%s%s", _path.autosave_dir, PATHSEP);
 

	
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
 
		SetDParam(2, _date);
 
		s = (char*)GetString(buf + strlen(_path.autosave_dir) + strlen(PATHSEP), STR_4004);
 
		strcpy(s, ".sav");
players.c
Show inline comments
 
@@ -500,53 +500,55 @@ Player *DoStartupNewPlayer(bool is_ai)
 
	InvalidateWindow(WC_TOOLBAR_MENU, 0);
 
	InvalidateWindow(WC_CLIENT_LIST, 0);
 

	
 
	return p;
 
}
 

	
 
void StartupPlayers(void)
 
{
 
	// The AI starts like in the setting with +2 month max
 
	_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1;
 
}
 

	
 
static void MaybeStartNewPlayer(void)
 
{
 
	uint n;
 
	Player *p;
 

	
 
	// count number of competitors
 
	n = 0;
 
	for(p=_players; p!=endof(_players); p++)
 
		if (p->is_active && p->is_ai)
 
			n++;
 

	
 
	// when there's a lot of computers in game, the probability that a new one starts is lower
 
	if (n < (uint)_opt.diff.max_no_competitors && n < RandomRange(_opt.diff.max_no_competitors + 2))
 
	if (n < (uint)_opt.diff.max_no_competitors)
 
		if (n < (!_network_server) ? RandomRange(_opt.diff.max_no_competitors + 2) : InteractiveRandomRange(_opt.diff.max_no_competitors + 2))
 
		DoStartupNewPlayer(true);
 

	
 
	// The next AI starts like the difficulty setting said, with +2 month max
 
	_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + RandomRange(60 * DAY_TICKS) + 1;
 
	_next_competitor_start = _opt.diff.competitor_start_time * 90 * DAY_TICKS + 1;
 
	_next_competitor_start += (!_network_server) ? RandomRange(60 * DAY_TICKS) : InteractiveRandomRange(60 * DAY_TICKS);
 
}
 

	
 
void InitializePlayers(void)
 
{
 
	int i;
 
	memset(_players, 0, sizeof(_players));
 
	for(i = 0; i != MAX_PLAYERS; i++)
 
		_players[i].index=i;
 
	_cur_player_tick_index = 0;
 
}
 

	
 
void OnTick_Players(void)
 
{
 
	Player *p;
 

	
 
	if (_game_mode == GM_EDITOR)
 
		return;
 

	
 
	p = GetPlayer(_cur_player_tick_index);
 
	_cur_player_tick_index = (_cur_player_tick_index + 1) % MAX_PLAYERS;
 
	if (p->name_1 != 0) GenerateCompanyName(p);
 

	
 
	if (!_networking && _game_mode != GM_MENU && !--_next_competitor_start) {
 
		MaybeStartNewPlayer();
0 comments (0 inline, 0 general)