tron@2186: /* $Id$ */ tron@2186: truelight@0: #ifndef FUNCTIONS_H truelight@0: #define FUNCTIONS_H truelight@0: truelight@0: /* landscape.c */ truelight@0: void FindLandscapeHeight(TileInfo *ti, uint x, uint y); tron@1420: void FindLandscapeHeightByTile(TileInfo *ti, TileIndex tile); truelight@0: tron@1589: void DoClearSquare(TileIndex tile); tron@1589: void CDECL ModifyTile(TileIndex tile, uint flags, ...); tron@1093: void RunTileLoop(void); truelight@0: truelight@0: uint GetPartialZ(int x, int y, int corners); truelight@0: uint GetSlopeZ(int x, int y); tron@1589: uint32 GetTileTrackStatus(TileIndex tile, TransportType mode); tron@1589: void GetAcceptedCargo(TileIndex tile, AcceptedCargo ac); tron@1589: void ChangeTileOwner(TileIndex tile, byte old_player, byte new_player); tron@1589: void AnimateTile(TileIndex tile); tron@1589: void ClickTile(TileIndex tile); tron@1589: void GetTileDesc(TileIndex tile, TileDesc *td); truelight@0: void DrawTile(TileInfo *ti); celestar@1377: void UpdateTownMaxPass(Town *t); truelight@0: tron@1589: bool IsValidTile(TileIndex tile); truelight@0: tron@536: static inline Point RemapCoords(int x, int y, int z) tron@536: { truelight@0: #if !defined(NEW_ROTATION) truelight@781: Point pt; truelight@781: pt.x = (y - x) * 2; truelight@781: pt.y = y + x - z; truelight@0: #else truelight@781: Point pt; truelight@781: pt.x = (x + y) * 2; truelight@781: pt.y = x - y - z; truelight@0: #endif tron@536: return pt; tron@536: } truelight@0: tron@536: static inline Point RemapCoords2(int x, int y) tron@536: { tron@536: return RemapCoords(x, y, GetSlopeZ(x, y)); tron@536: } truelight@0: truelight@0: truelight@0: /* clear_land.c */ Darkvater@2436: void DrawHillyLandTile(const TileInfo *ti); Darkvater@2436: void DrawClearLandTile(const TileInfo *ti, byte set); tron@2220: void DrawClearLandFence(const TileInfo *ti); tron@1420: void TileLoopClearHelper(TileIndex tile); truelight@0: truelight@0: /* road_land.c */ truelight@0: void DrawRoadDepotSprite(int x, int y, int image); truelight@0: truelight@0: /* water_land.c */ truelight@0: void DrawShipDepotSprite(int x, int y, int image); tron@1977: void TileLoop_Water(TileIndex tile); truelight@0: truelight@0: /* players.c */ truelight@0: bool CheckPlayerHasMoney(int32 cost); truelight@0: void SubtractMoneyFromPlayer(int32 cost); Darkvater@2436: void SubtractMoneyFromPlayerFract(PlayerID player, int32 cost); Darkvater@2436: bool CheckOwnership(PlayerID owner); tron@1977: bool CheckTileOwnership(TileIndex tile); tron@2475: StringID GetPlayerNameString(PlayerID player, uint index); truelight@0: truelight@0: /* standard */ truelight@0: void ShowInfo(const char *str); truelight@0: void CDECL ShowInfoF(const char *str, ...); truelight@0: void NORETURN CDECL error(const char *str, ...); truelight@0: Darkvater@2075: /* openttd.c */ truelight@543: truelight@543: // ************** truelight@543: // * Warning: DO NOT enable this unless you understand what it does truelight@543: // * truelight@543: // * If enabled, in a network game all randoms will be dumped to the truelight@543: // * stdout if the first client joins (or if you are a client). This truelight@543: // * is to help finding desync problems. truelight@543: // * truelight@543: // * Warning: DO NOT enable this unless you understand what it does truelight@543: // ************** truelight@543: truelight@1539: //#define RANDOM_DEBUG truelight@543: ludde@2073: ludde@2073: // Enable this to produce higher quality random numbers. ludde@2073: // Doesn't work with network yet. ludde@2073: //#define MERSENNE_TWISTER ludde@2073: ludde@2073: // Mersenne twister functions ludde@2073: void SeedMT(uint32 seed); ludde@2073: uint32 RandomMT(void); ludde@2073: ludde@2073: ludde@2073: #ifdef MERSENNE_TWISTER ludde@2073: static inline uint32 Random(void) { return RandomMT(); } ludde@2073: uint RandomRange(uint max); ludde@2073: #else ludde@2073: truelight@543: #ifdef RANDOM_DEBUG truelight@543: #define Random() DoRandom(__LINE__, __FILE__) truelight@1120: uint32 DoRandom(int line, const char *file); truelight@543: #define RandomRange(max) DoRandomRange(max, __LINE__, __FILE__) truelight@1120: uint DoRandomRange(uint max, int line, const char *file); truelight@543: #else tron@1093: uint32 Random(void); truelight@543: uint RandomRange(uint max); ludde@2073: #endif ludde@2073: #endif // MERSENNE_TWISTER ludde@2051: ludde@2073: static inline TileIndex RandomTileSeed(uint32 r) { return TILE_MASK(r); } ludde@2073: static inline TileIndex RandomTile(void) { return TILE_MASK(Random()); } ludde@2073: ludde@2073: tron@1093: uint32 InteractiveRandom(void); /* Used for random sequences that are not the same on the other end of the multiplayer link */ signde@239: uint InteractiveRandomRange(uint max); signde@239: ludde@2091: ludde@2091: // Used for profiling Darkvater@2482: #define TIC() { extern uint32 _rdtsc(void); uint32 _xxx_ = _rdtsc(); static float __avg__; Darkvater@2482: #define TOC(s) _xxx_ = _rdtsc() - _xxx_; __avg__=__avg__*0.99+_xxx_*0.01; printf("%s: %8d %f\n", s, _xxx_,__avg__); } ludde@2091: ludde@2091: truelight@0: void SetDate(uint date); truelight@0: /* facedraw.c */ truelight@0: void DrawPlayerFace(uint32 face, int color, int x, int y); truelight@0: truelight@0: /* texteff.c */ tron@1093: void MoveAllTextEffects(void); truelight@0: void AddTextEffect(StringID msg, int x, int y, uint16 duration); tron@1093: void InitTextEffects(void); truelight@0: void DrawTextEffects(DrawPixelInfo *dpi); truelight@0: tron@1093: void InitTextMessage(void); tron@1093: void DrawTextMessage(void); truelight@619: void CDECL AddTextMessage(uint16 color, uint8 duration, const char *message, ...); tron@1093: void UndrawTextMessage(void); tron@1093: void TextMessageDailyLoop(void); truelight@543: tron@1977: bool AddAnimatedTile(TileIndex tile); tron@1977: void DeleteAnimatedTile(TileIndex tile); tron@1093: void AnimateAnimatedTiles(void); tron@1093: void InitializeAnimatedTiles(void); truelight@0: truelight@0: /* tunnelbridge_cmd.c */ tron@1977: bool CheckTunnelInWay(TileIndex tile, int z); tron@2639: bool CheckBridge_Stuff(byte bridge_type, uint bridge_len); truelight@0: uint32 GetBridgeLength(TileIndex begin, TileIndex end); truelight@0: int CalcBridgeLenCostFactor(int x); truelight@0: tron@1977: typedef void CommandCallback(bool success, TileIndex tile, uint32 p1, uint32 p2); truelight@0: bool DoCommandP(TileIndex tile, uint32 p1, uint32 p2, CommandCallback *callback, uint32 cmd); truelight@0: truelight@543: /* network.c */ truelight@543: void NetworkUDPClose(void); tron@1093: void NetworkStartUp(void); truelight@543: void NetworkShutDown(void); truelight@543: void NetworkGameLoop(void); truelight@543: void NetworkUDPGameLoop(void); truelight@543: bool NetworkServerStart(void); tron@1329: bool NetworkClientConnectGame(const char* host, unsigned short port); tron@1093: void NetworkReboot(void); tron@1093: void NetworkDisconnect(void); tron@1977: void NetworkSend_Command(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, CommandCallback *callback); truelight@0: truelight@0: /* misc_cmd.c */ tron@1093: void PlaceTreesRandomly(void); truelight@0: truelight@0: void InitializeLandscapeVariables(bool only_constants); truelight@0: truelight@0: /* misc.c */ truelight@0: void DeleteName(StringID id); tron@1328: char *GetName(int id, char *buff); truelight@543: truelight@543: // AllocateNameUnique also tests if the name used is not used anywere else truelight@543: // and if it is used, it returns an error. truelight@543: #define AllocateNameUnique(name, skip) RealAllocateName(name, skip, true) truelight@543: #define AllocateName(name, skip) RealAllocateName(name, skip, false) tron@1328: StringID RealAllocateName(const char *name, byte skip, bool check_double); truelight@0: void ConvertDayToYMD(YearMonthDay *ymd, uint16 date); truelight@0: uint ConvertYMDToDay(uint year, uint month, uint day); truelight@0: uint ConvertIntDate(uint date); truelight@0: truelight@0: /* misc functions */ truelight@0: void MarkTileDirty(int x, int y); truelight@0: void MarkTileDirtyByTile(TileIndex tile); tron@2788: void InvalidateWindow(WindowClass cls, WindowNumber number); tron@2788: void InvalidateWindowWidget(WindowClass cls, WindowNumber number, byte widget_index); tron@2788: void InvalidateWindowClasses(WindowClass cls); truelight@0: void DeleteWindowById(WindowClass cls, WindowNumber number); darkvater@999: void DeleteWindowByClass(WindowClass cls); truelight@0: Darkvater@1914: void SetObjectToPlaceWnd(CursorID icon, byte mode, Window *w); Darkvater@1914: void SetObjectToPlace(CursorID icon, byte mode, WindowClass window_class, WindowNumber window_num); truelight@0: tron@1093: void ResetObjectToPlace(void); darkvater@152: darkvater@152: bool ScrollWindowTo(int x, int y, Window * w); darkvater@152: truelight@0: bool ScrollMainWindowToTile(TileIndex tile); truelight@0: bool ScrollMainWindowTo(int x, int y); truelight@0: void DrawSprite(uint32 img, int x, int y); darkvater@1082: uint GetCorrectTileHeight(TileIndex tile); truelight@0: bool EnsureNoVehicle(TileIndex tile); truelight@0: bool EnsureNoVehicleZ(TileIndex tile, byte z); truelight@0: void MarkAllViewportsDirty(int left, int top, int right, int bottom); truelight@0: void ShowCostOrIncomeAnimation(int x, int y, int z, int32 cost); celestar@1935: void ShowFeederIncomeAnimation(int x, int y, int z, int32 cost); truelight@0: truelight@0: void DrawFoundation(TileInfo *ti, uint f); truelight@0: tron@1977: bool CheckIfAuthorityAllows(TileIndex tile); tron@1977: Town *ClosestTownFromTile(TileIndex tile, uint threshold); truelight@0: void ChangeTownRating(Town *t, int add, int max); truelight@0: truelight@0: uint GetRoadBitsByTile(TileIndex tile); Darkvater@2436: int GetTownRadiusGroup(const Town *t, TileIndex tile); truelight@543: void ShowNetworkChatQueryWindow(byte desttype, byte dest); truelight@543: void ShowNetworkGiveMoneyWindow(byte player); tron@1093: void ShowNetworkNeedGamePassword(void); tron@1093: void ShowNetworkNeedCompanyPassword(void); truelight@0: int FindFirstBit(uint32 x); darkvater@998: void ShowHighscoreTable(int difficulty, int8 rank); darkvater@983: void ShowEndGameChart(void); truelight@0: TileIndex AdjustTileCoordRandomly(TileIndex a, byte rng); truelight@0: tron@1093: void AfterLoadTown(void); Darkvater@1794: void GenRandomNewGame(uint32 rnd1, uint32 rnd2); Darkvater@1796: void StartScenarioEditor(uint32 rnd1, uint32 rnd2); tron@1093: void AskExitGame(void); tron@1093: void AskExitToGameMenu(void); truelight@0: tron@1093: void RedrawAutosave(void); truelight@0: truelight@0: StringID RemapOldStringID(StringID s); truelight@0: truelight@0: void UpdateViewportSignPos(ViewportSign *sign, int left, int top, StringID str); truelight@0: truelight@0: enum { truelight@0: SLD_LOAD_GAME = 0, truelight@0: SLD_LOAD_SCENARIO = 1, truelight@0: SLD_SAVE_GAME = 2, truelight@0: SLD_SAVE_SCENARIO = 3, truelight@0: SLD_NEW_GAME = 4, truelight@0: }; truelight@0: void ShowSaveLoadDialog(int mode); truelight@0: truelight@0: // callback from drivers that is called if the game size changes dynamically tron@1093: void GameSizeChanged(void); truelight@0: bool FileExists(const char *filename); truelight@0: bool ReadLanguagePack(int index); tron@1093: void InitializeLanguagePacks(void); tron@1310: void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize); truelight@0: int GetLanguageList(char **languages, int max); truelight@0: tron@1093: void LoadFromConfig(void); tron@1093: void SaveToConfig(void); Darkvater@1688: void CheckConfig(void); truelight@0: int ttd_main(int argc, char* argv[]); truelight@0: tron@1093: void DeterminePaths(void); truelight@0: celestar@1217: void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); Darkvater@2380: void CSleep(int milliseconds); truelight@0: #endif /* FUNCTIONS_H */