truelight@0: #ifndef FUNCTIONS_H truelight@0: #define FUNCTIONS_H truelight@0: truelight@0: /* vehicle.c */ truelight@0: truelight@0: /* window.c */ truelight@0: truelight@0: truelight@0: /* landscape.c */ truelight@0: void FindLandscapeHeight(TileInfo *ti, uint x, uint y); truelight@0: void FindLandscapeHeightByTile(TileInfo *ti, uint tile); truelight@0: uint GetTileSlope(uint tile, int *h); truelight@0: int GetTileZ(uint tile); truelight@0: truelight@0: void DoClearSquare(uint tile); truelight@0: void CDECL ModifyTile(uint 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); truelight@159: uint32 GetTileTrackStatus(uint tile, TransportType mode); tron@473: void GetAcceptedCargo(uint tile, AcceptedCargo ac); truelight@0: void ChangeTileOwner(uint tile, byte old_player, byte new_player); truelight@0: void AnimateTile(uint tile); truelight@0: void ClickTile(uint tile); truelight@0: void GetTileDesc(uint tile, TileDesc *td); truelight@0: void DrawTile(TileInfo *ti); truelight@0: truelight@0: bool IsValidTile(uint 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 */ truelight@0: void DrawHillyLandTile(TileInfo *ti); truelight@0: void DrawClearLandTile(TileInfo *ti, byte set); truelight@0: void DrawClearLandFence(TileInfo *ti, byte img); truelight@0: void TileLoopClearHelper(uint tile); truelight@0: truelight@0: /* station_land.c */ truelight@0: void StationPickerDrawSprite(int x, int y, int railtype, int image); truelight@0: truelight@0: /* track_land.c */ truelight@0: void DrawTrainDepotSprite(int x, int y, int image, int railtype); dominik@415: void DrawWaypointSprite(int x, int y, int image, int railtype); 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); truelight@0: void TileLoop_Water(uint tile); truelight@0: truelight@0: /* players.c */ truelight@0: bool CheckPlayerHasMoney(int32 cost); truelight@0: void SubtractMoneyFromPlayer(int32 cost); truelight@0: void SubtractMoneyFromPlayerFract(byte player, int32 cost); truelight@0: bool CheckOwnership(byte owner); truelight@0: bool CheckTileOwnership(uint tile); darkvater@2: StringID GetPlayerNameString(byte player, byte 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: truelight@0: /* ttd.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@543: //#define RANDOM_DEBUG truelight@543: 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); truelight@543: #endif truelight@0: tron@1093: void InitPlayerRandoms(void); signde@206: 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: 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: truelight@0: bool AddAnimatedTile(uint tile); truelight@0: void DeleteAnimatedTile(uint tile); tron@1093: void AnimateAnimatedTiles(void); tron@1093: void InitializeAnimatedTiles(void); truelight@0: truelight@0: /* tunnelbridge_cmd.c */ truelight@0: bool CheckTunnelInWay(uint tile, int z); truelight@0: bool CheckBridge_Stuff(byte bridge_type, int bridge_len); truelight@0: uint32 GetBridgeLength(TileIndex begin, TileIndex end); truelight@0: int CalcBridgeLenCostFactor(int x); truelight@0: truelight@0: typedef void CommandCallback(bool success, uint 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); truelight@543: bool NetworkClientConnectGame(const byte* host, unsigned short port); tron@1093: void NetworkReboot(void); tron@1093: void NetworkDisconnect(void); truelight@543: void NetworkSend_Command(uint32 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); truelight@0: byte *GetName(int id, byte *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) truelight@543: StringID RealAllocateName(const byte *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@543: void CSleep(int milliseconds); truelight@0: truelight@0: truelight@0: /* misc functions */ truelight@0: void MarkTileDirty(int x, int y); truelight@0: void MarkTileDirtyByTile(TileIndex tile); truelight@0: void InvalidateWindow(byte cls, WindowNumber number); truelight@0: void InvalidateWindowWidget(byte cls, WindowNumber number, byte widget_index); truelight@0: void InvalidateWindowClasses(byte cls); truelight@0: void DeleteWindowById(WindowClass cls, WindowNumber number); darkvater@999: void DeleteWindowByClass(WindowClass cls); truelight@0: truelight@0: void SetObjectToPlaceWnd(int icon, byte mode, Window *w); tron@873: void SetObjectToPlace(int icon, byte mode, WindowClass window_class, WindowNumber window_num); truelight@0: tron@1093: void ResetObjectToPlace(void); darkvater@152: darkvater@152: bool ScrollWindowToTile(TileIndex tile, Window * w); 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); truelight@0: truelight@0: void DrawFoundation(TileInfo *ti, uint f); truelight@0: truelight@0: bool CheckIfAuthorityAllows(uint tile); truelight@0: Town *ClosestTownFromTile(uint tile, uint threshold); truelight@0: void ChangeTownRating(Town *t, int add, int max); truelight@0: truelight@0: uint GetRoadBitsByTile(TileIndex tile); truelight@0: int GetTownRadiusGroup(Town *t, uint 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); darkvater@395: void ShowRenameWaypointWindow(Waypoint *cp); 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: truelight@0: enum SaveOrLoadResult { truelight@0: SL_OK = 0, // completed successfully truelight@0: SL_ERROR = 1, // error that was caught before internal structures were modified truelight@0: SL_REINIT = 2, // error that was caught in the middle of updating game state, need to clear it. (can only happen during load) truelight@0: }; truelight@0: enum SaveOrLoadMode { truelight@0: SL_INVALID = -1, truelight@0: SL_LOAD = 0, truelight@0: SL_SAVE = 1, truelight@0: SL_OLD_LOAD = 2, truelight@0: }; truelight@0: truelight@0: int SaveOrLoad(const char *filename, int mode); truelight@0: tron@1093: void AfterLoadTown(void); 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: tron@1115: void ttd_strlcpy(char *dst, const char *src, size_t size); tron@1115: void ttd_strlcat(char *dst, const char *src, size_t size); 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 CheckSwitchToEuro(void); truelight@0: tron@1093: void LoadFromConfig(void); tron@1093: void SaveToConfig(void); truelight@0: int ttd_main(int argc, char* argv[]); tron@1093: byte GetOSVersion(void); truelight@0: tron@1093: void DeterminePaths(void); truelight@0: char * CDECL str_fmt(const char *str, ...); truelight@0: celestar@1217: void bubblesort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *)); truelight@0: #endif /* FUNCTIONS_H */