2005-07-24 14:12:37 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
#ifndef FUNCTIONS_H
|
|
|
|
#define FUNCTIONS_H
|
|
|
|
|
|
|
|
/* landscape.c */
|
|
|
|
void FindLandscapeHeight(TileInfo *ti, uint x, uint y);
|
2005-03-04 10:34:44 +00:00
|
|
|
void FindLandscapeHeightByTile(TileInfo *ti, TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
void DoClearSquare(TileIndex tile);
|
|
|
|
void CDECL ModifyTile(TileIndex tile, uint flags, ...);
|
2005-01-22 20:23:18 +00:00
|
|
|
void RunTileLoop(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
uint GetPartialZ(int x, int y, int corners);
|
|
|
|
uint GetSlopeZ(int x, int y);
|
2005-03-27 18:15:27 +00:00
|
|
|
uint32 GetTileTrackStatus(TileIndex tile, TransportType mode);
|
|
|
|
void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac);
|
|
|
|
void ChangeTileOwner(TileIndex tile, byte old_player, byte new_player);
|
|
|
|
void AnimateTile(TileIndex tile);
|
|
|
|
void ClickTile(TileIndex tile);
|
|
|
|
void GetTileDesc(TileIndex tile, TileDesc *td);
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawTile(TileInfo *ti);
|
2005-02-17 10:56:19 +00:00
|
|
|
void UpdateTownMaxPass(Town *t);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-03-27 18:15:27 +00:00
|
|
|
bool IsValidTile(TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-03 07:43:00 +00:00
|
|
|
static inline Point RemapCoords(int x, int y, int z)
|
|
|
|
{
|
2004-08-09 17:04:08 +00:00
|
|
|
#if !defined(NEW_ROTATION)
|
2004-12-23 14:46:16 +00:00
|
|
|
Point pt;
|
|
|
|
pt.x = (y - x) * 2;
|
|
|
|
pt.y = y + x - z;
|
2004-08-09 17:04:08 +00:00
|
|
|
#else
|
2004-12-23 14:46:16 +00:00
|
|
|
Point pt;
|
|
|
|
pt.x = (x + y) * 2;
|
|
|
|
pt.y = x - y - z;
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif
|
2004-12-03 07:43:00 +00:00
|
|
|
return pt;
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2004-12-03 07:43:00 +00:00
|
|
|
static inline Point RemapCoords2(int x, int y)
|
|
|
|
{
|
|
|
|
return RemapCoords(x, y, GetSlopeZ(x, y));
|
|
|
|
}
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
/* clear_land.c */
|
2005-09-18 20:56:44 +00:00
|
|
|
void DrawHillyLandTile(const TileInfo *ti);
|
|
|
|
void DrawClearLandTile(const TileInfo *ti, byte set);
|
2005-07-28 19:18:27 +00:00
|
|
|
void DrawClearLandFence(const TileInfo *ti);
|
2005-03-04 10:34:44 +00:00
|
|
|
void TileLoopClearHelper(TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* road_land.c */
|
|
|
|
void DrawRoadDepotSprite(int x, int y, int image);
|
|
|
|
|
|
|
|
/* water_land.c */
|
|
|
|
void DrawShipDepotSprite(int x, int y, int image);
|
2005-06-24 12:38:35 +00:00
|
|
|
void TileLoop_Water(TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* players.c */
|
|
|
|
bool CheckPlayerHasMoney(int32 cost);
|
|
|
|
void SubtractMoneyFromPlayer(int32 cost);
|
2005-09-18 20:56:44 +00:00
|
|
|
void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost);
|
|
|
|
bool CheckOwnership(PlayerID owner);
|
2005-06-24 12:38:35 +00:00
|
|
|
bool CheckTileOwnership(TileIndex tile);
|
2005-09-30 20:37:25 +00:00
|
|
|
StringID GetPlayerNameString(PlayerID player, uint index);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* standard */
|
|
|
|
void ShowInfo(const char *str);
|
|
|
|
void CDECL ShowInfoF(const char *str, ...);
|
|
|
|
void NORETURN CDECL error(const char *str, ...);
|
|
|
|
|
2005-07-15 21:28:26 +00:00
|
|
|
/* openttd.c */
|
2004-12-04 17:54:56 +00:00
|
|
|
|
|
|
|
// **************
|
|
|
|
// * Warning: DO NOT enable this unless you understand what it does
|
|
|
|
// *
|
|
|
|
// * If enabled, in a network game all randoms will be dumped to the
|
|
|
|
// * stdout if the first client joins (or if you are a client). This
|
|
|
|
// * is to help finding desync problems.
|
|
|
|
// *
|
|
|
|
// * Warning: DO NOT enable this unless you understand what it does
|
|
|
|
// **************
|
|
|
|
|
2005-03-24 14:33:05 +00:00
|
|
|
//#define RANDOM_DEBUG
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2005-07-15 20:29:06 +00:00
|
|
|
|
|
|
|
// Enable this to produce higher quality random numbers.
|
|
|
|
// Doesn't work with network yet.
|
|
|
|
//#define MERSENNE_TWISTER
|
|
|
|
|
|
|
|
// Mersenne twister functions
|
|
|
|
void SeedMT(uint32 seed);
|
|
|
|
uint32 RandomMT(void);
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef MERSENNE_TWISTER
|
|
|
|
static inline uint32 Random(void) { return RandomMT(); }
|
|
|
|
uint RandomRange(uint max);
|
|
|
|
#else
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
#ifdef RANDOM_DEBUG
|
|
|
|
#define Random() DoRandom(__LINE__, __FILE__)
|
2005-01-23 19:02:53 +00:00
|
|
|
uint32 DoRandom(int line, const char *file);
|
2004-12-04 17:54:56 +00:00
|
|
|
#define RandomRange(max) DoRandomRange(max, __LINE__, __FILE__)
|
2005-01-23 19:02:53 +00:00
|
|
|
uint DoRandomRange(uint max, int line, const char *file);
|
2004-12-04 17:54:56 +00:00
|
|
|
#else
|
2005-01-22 20:23:18 +00:00
|
|
|
uint32 Random(void);
|
2004-12-04 17:54:56 +00:00
|
|
|
uint RandomRange(uint max);
|
|
|
|
#endif
|
2005-07-15 20:29:06 +00:00
|
|
|
#endif // MERSENNE_TWISTER
|
|
|
|
|
|
|
|
static inline TileIndex RandomTileSeed(uint32 r) { return TILE_MASK(r); }
|
|
|
|
static inline TileIndex RandomTile(void) { return TILE_MASK(Random()); }
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
uint32 InteractiveRandom(void); /* Used for random sequences that are not the same on the other end of the multiplayer link */
|
2004-09-13 22:49:11 +00:00
|
|
|
uint InteractiveRandomRange(uint max);
|
|
|
|
|
2005-07-17 12:49:00 +00:00
|
|
|
|
|
|
|
// Used for profiling
|
2005-10-02 22:39:56 +00:00
|
|
|
#define TIC() { extern uint32 _rdtsc(void); uint32 _xxx_ = _rdtsc(); static float __avg__;
|
|
|
|
#define TOC(s) _xxx_ = _rdtsc() - _xxx_; __avg__=__avg__*0.99+_xxx_*0.01; printf("%s: %8d %f\n", s, _xxx_,__avg__); }
|
2005-07-17 12:49:00 +00:00
|
|
|
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
void SetDate(uint date);
|
|
|
|
/* facedraw.c */
|
|
|
|
void DrawPlayerFace(uint32 face, int color, int x, int y);
|
|
|
|
|
|
|
|
/* texteff.c */
|
2005-01-22 20:23:18 +00:00
|
|
|
void MoveAllTextEffects(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
void AddTextEffect(StringID msg, int x, int y, uint16 duration);
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitTextEffects(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
void DrawTextEffects(DrawPixelInfo *dpi);
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitTextMessage(void);
|
|
|
|
void DrawTextMessage(void);
|
2004-12-13 11:17:59 +00:00
|
|
|
void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...);
|
2005-01-22 20:23:18 +00:00
|
|
|
void UndrawTextMessage(void);
|
|
|
|
void TextMessageDailyLoop(void);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
bool AddAnimatedTile(TileIndex tile);
|
|
|
|
void DeleteAnimatedTile(TileIndex tile);
|
2005-01-22 20:23:18 +00:00
|
|
|
void AnimateAnimatedTiles(void);
|
|
|
|
void InitializeAnimatedTiles(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* tunnelbridge_cmd.c */
|
2005-11-14 19:48:04 +00:00
|
|
|
bool CheckBridge_Stuff(byte bridge_type, uint bridge_len);
|
2004-08-09 17:04:08 +00:00
|
|
|
uint32 GetBridgeLength(TileIndex begin, TileIndex end);
|
|
|
|
int CalcBridgeLenCostFactor(int x);
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2);
|
2004-08-09 17:04:08 +00:00
|
|
|
bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd);
|
|
|
|
|
2004-12-04 17:54:56 +00:00
|
|
|
/* network.c */
|
|
|
|
void NetworkUDPClose(void);
|
2005-01-22 20:23:18 +00:00
|
|
|
void NetworkStartUp(void);
|
2004-12-04 17:54:56 +00:00
|
|
|
void NetworkShutDown(void);
|
|
|
|
void NetworkGameLoop(void);
|
|
|
|
void NetworkUDPGameLoop(void);
|
|
|
|
bool NetworkServerStart(void);
|
2005-02-06 22:25:27 +00:00
|
|
|
bool NetworkClientConnectGame(const char* host, unsigned short port);
|
2005-01-22 20:23:18 +00:00
|
|
|
void NetworkReboot(void);
|
|
|
|
void NetworkDisconnect(void);
|
2005-06-24 12:38:35 +00:00
|
|
|
void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
/* misc_cmd.c */
|
2005-01-22 20:23:18 +00:00
|
|
|
void PlaceTreesRandomly(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
void InitializeLandscapeVariables(bool only_constants);
|
|
|
|
|
|
|
|
/* misc.c */
|
|
|
|
void DeleteName(StringID id);
|
2005-02-06 20:53:31 +00:00
|
|
|
char *GetName(int id, char *buff);
|
2004-12-04 17:54:56 +00:00
|
|
|
|
|
|
|
// AllocateNameUnique also tests if the name used is not used anywere else
|
|
|
|
// and if it is used, it returns an error.
|
|
|
|
#define AllocateNameUnique(name, skip) RealAllocateName(name, skip, true)
|
|
|
|
#define AllocateName(name, skip) RealAllocateName(name, skip, false)
|
2005-02-06 20:53:31 +00:00
|
|
|
StringID RealAllocateName(const char *name, byte skip, bool check_double);
|
2004-08-09 17:04:08 +00:00
|
|
|
void ConvertDayToYMD(YearMonthDay *ymd, uint16 date);
|
|
|
|
uint ConvertYMDToDay(uint year, uint month, uint day);
|
|
|
|
uint ConvertIntDate(uint date);
|
|
|
|
|
|
|
|
/* misc functions */
|
|
|
|
void MarkTileDirty(int x, int y);
|
|
|
|
void MarkTileDirtyByTile(TileIndex tile);
|
2005-12-24 15:01:17 +00:00
|
|
|
void InvalidateWindow(WindowClass cls, WindowNumber number);
|
|
|
|
void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index);
|
|
|
|
void InvalidateWindowClasses(WindowClass cls);
|
2004-08-09 17:04:08 +00:00
|
|
|
void DeleteWindowById(WindowClass cls, WindowNumber number);
|
2005-01-13 16:50:20 +00:00
|
|
|
void DeleteWindowByClass(WindowClass cls);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-06-06 13:47:06 +00:00
|
|
|
void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w);
|
|
|
|
void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void ResetObjectToPlace(void);
|
2004-09-03 19:59:05 +00:00
|
|
|
|
|
|
|
bool ScrollWindowTo(int x, int y, Window * w);
|
|
|
|
|
2004-08-09 17:04:08 +00:00
|
|
|
bool ScrollMainWindowToTile(TileIndex tile);
|
|
|
|
bool ScrollMainWindowTo(int x, int y);
|
|
|
|
void DrawSprite(uint32 img, int x, int y);
|
2005-01-21 19:52:32 +00:00
|
|
|
uint GetCorrectTileHeight(TileIndex tile);
|
2004-08-09 17:04:08 +00:00
|
|
|
bool EnsureNoVehicle(TileIndex tile);
|
|
|
|
bool EnsureNoVehicleZ(TileIndex tile, byte z);
|
|
|
|
void MarkAllViewportsDirty(int left, int top, int right, int bottom);
|
|
|
|
void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost);
|
2005-06-15 16:58:15 +00:00
|
|
|
void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
void DrawFoundation(TileInfo *ti, uint f);
|
|
|
|
|
2005-06-24 12:38:35 +00:00
|
|
|
bool CheckIfAuthorityAllows(TileIndex tile);
|
|
|
|
Town *ClosestTownFromTile(TileIndex tile, uint threshold);
|
2004-08-09 17:04:08 +00:00
|
|
|
void ChangeTownRating(Town *t, int add, int max);
|
|
|
|
|
2005-09-18 20:56:44 +00:00
|
|
|
int GetTownRadiusGroup(const Town *t, TileIndex tile);
|
2004-12-04 17:54:56 +00:00
|
|
|
void ShowNetworkChatQueryWindow(byte desttype, byte dest);
|
|
|
|
void ShowNetworkGiveMoneyWindow(byte player);
|
2005-01-22 20:23:18 +00:00
|
|
|
void ShowNetworkNeedGamePassword(void);
|
|
|
|
void ShowNetworkNeedCompanyPassword(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
int FindFirstBit(uint32 x);
|
2005-01-13 16:28:47 +00:00
|
|
|
void ShowHighscoreTable(int difficulty, int8 rank);
|
2005-01-11 00:54:06 +00:00
|
|
|
void ShowEndGameChart(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng);
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void AfterLoadTown(void);
|
2006-03-02 02:22:15 +00:00
|
|
|
void UpdatePatches(void);
|
2005-05-12 00:18:30 +00:00
|
|
|
void GenRandomNewGame(uint32 rnd1, uint32 rnd2);
|
2005-05-12 23:46:01 +00:00
|
|
|
void StartScenarioEditor(uint32 rnd1, uint32 rnd2);
|
2005-01-22 20:23:18 +00:00
|
|
|
void AskExitGame(void);
|
|
|
|
void AskExitToGameMenu(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void RedrawAutosave(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
|
|
|
StringID RemapOldStringID(StringID s);
|
|
|
|
|
|
|
|
void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
SLD_LOAD_GAME = 0,
|
|
|
|
SLD_LOAD_SCENARIO = 1,
|
|
|
|
SLD_SAVE_GAME = 2,
|
|
|
|
SLD_SAVE_SCENARIO = 3,
|
|
|
|
SLD_NEW_GAME = 4,
|
|
|
|
};
|
|
|
|
void ShowSaveLoadDialog(int mode);
|
|
|
|
|
|
|
|
// callback from drivers that is called if the game size changes dynamically
|
2005-01-22 20:23:18 +00:00
|
|
|
void GameSizeChanged(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
bool FileExists(const char *filename);
|
|
|
|
bool ReadLanguagePack(int index);
|
2005-01-22 20:23:18 +00:00
|
|
|
void InitializeLanguagePacks(void);
|
2005-02-06 08:38:09 +00:00
|
|
|
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
|
2004-08-09 17:04:08 +00:00
|
|
|
int GetLanguageList(char **languages, int max);
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void LoadFromConfig(void);
|
|
|
|
void SaveToConfig(void);
|
2005-04-13 23:03:31 +00:00
|
|
|
void CheckConfig(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
int ttd_main(int argc, char* argv[]);
|
|
|
|
|
2005-01-22 20:23:18 +00:00
|
|
|
void DeterminePaths(void);
|
2004-08-09 17:04:08 +00:00
|
|
|
|
2005-09-02 16:05:59 +00:00
|
|
|
void CSleep(int milliseconds);
|
2004-08-09 17:04:08 +00:00
|
|
|
#endif /* FUNCTIONS_H */
|