diff --git a/src/gamelog.cpp b/src/gamelog.cpp index 5a6e4b477b..0e251aae00 100644 --- a/src/gamelog.cpp +++ b/src/gamelog.cpp @@ -212,11 +212,13 @@ void GamelogPrint(std::function proc) switch (lc->ct) { default: NOT_REACHED(); case GLCT_MODE: + /* Changing landscape, or going from scenario editor to game or back. */ buf += seprintf(buf, lastof(buffer), "New game mode: %u landscape: %u", (uint)lc->mode.mode, (uint)lc->mode.landscape); break; case GLCT_REVISION: + /* The game was loaded in a diffferent version than before. */ buf += seprintf(buf, lastof(buffer), "Revision text changed to %s, savegame version %u, ", lc->revision.text, lc->revision.slver); @@ -230,6 +232,7 @@ void GamelogPrint(std::function proc) break; case GLCT_OLDVER: + /* The game was loaded from before 0.7.0-beta1. */ buf += seprintf(buf, lastof(buffer), "Conversion from "); switch (lc->oldver.type) { default: NOT_REACHED(); @@ -260,10 +263,12 @@ void GamelogPrint(std::function proc) break; case GLCT_SETTING: + /* A setting with the SF_NO_NETWORK flag got changed; these settings usually affect NewGRFs, such as road side or wagon speed limits. */ buf += seprintf(buf, lastof(buffer), "Setting changed: %s : %d -> %d", lc->setting.name, lc->setting.oldval, lc->setting.newval); break; case GLCT_GRFADD: { + /* A NewGRF got added to the game, either at the start of the game (never an issue), or later on when it could be an issue. */ const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum); buf += seprintf(buf, lastof(buffer), "Added NewGRF: "); buf = PrintGrfInfo(buf, lastof(buffer), lc->grfadd.grfid, lc->grfadd.md5sum, gc); @@ -274,6 +279,7 @@ void GamelogPrint(std::function proc) } case GLCT_GRFREM: { + /* A NewGRF got removed from the game, either manually or by it missing when loading the game. */ GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid); buf += seprintf(buf, lastof(buffer), la->at == GLAT_LOAD ? "Missing NewGRF: " : "Removed NewGRF: "); buf = PrintGrfInfo(buf, lastof(buffer), lc->grfrem.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr); @@ -291,6 +297,7 @@ void GamelogPrint(std::function proc) } case GLCT_GRFCOMPAT: { + /* Another version of the same NewGRF got loaded. */ const GRFConfig *gc = FindGRFConfig(lc->grfadd.grfid, FGCM_EXACT, lc->grfadd.md5sum); buf += seprintf(buf, lastof(buffer), "Compatible NewGRF loaded: "); buf = PrintGrfInfo(buf, lastof(buffer), lc->grfcompat.grfid, lc->grfcompat.md5sum, gc); @@ -300,6 +307,7 @@ void GamelogPrint(std::function proc) } case GLCT_GRFPARAM: { + /* A parameter of a NewGRF got changed after the game was started. */ GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid); buf += seprintf(buf, lastof(buffer), "GRF parameter changed: "); buf = PrintGrfInfo(buf, lastof(buffer), lc->grfparam.grfid, nullptr, gm != grf_names.End() ? gm->second.gc : nullptr); @@ -308,6 +316,7 @@ void GamelogPrint(std::function proc) } case GLCT_GRFMOVE: { + /* The order of NewGRFs got changed, which might cause some other NewGRFs to behave differently. */ GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid); buf += seprintf(buf, lastof(buffer), "GRF order changed: %08X moved %d places %s", BSWAP32(lc->grfmove.grfid), abs(lc->grfmove.offset), lc->grfmove.offset >= 0 ? "down" : "up" ); @@ -317,6 +326,7 @@ void GamelogPrint(std::function proc) } case GLCT_GRFBUG: { + /* A specific bug in a NewGRF, that could cause wide spread problems, has been noted during the execution of the game. */ GrfIDMapping::Pair *gm = grf_names.Find(lc->grfrem.grfid); switch (lc->grfbug.bug) { default: NOT_REACHED(); @@ -330,6 +340,8 @@ void GamelogPrint(std::function proc) } case GLCT_EMERGENCY: + /* At one point the savegame was made during the handling of a game crash. + * The generic code already mentioned the emergency savegame, and there is no extra information to log. */ break; } diff --git a/src/landscape.cpp b/src/landscape.cpp index eacac6be24..af70e74982 100644 --- a/src/landscape.cpp +++ b/src/landscape.cpp @@ -863,12 +863,15 @@ static void GenerateTerrain(int type, uint flag) { uint32 r = Random(); - const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + 4845, ST_MAPGEN); + /* Choose one of the templates from the graphics file. */ + const Sprite *templ = GetSprite((((r >> 24) * _genterrain_tbl_1[type]) >> 8) + _genterrain_tbl_2[type] + SPR_MAPGEN_BEGIN, ST_MAPGEN); if (templ == nullptr) usererror("Map generator sprites could not be loaded"); + /* Chose a random location to apply the template to. */ uint x = r & Map::MaxX(); uint y = (r >> Map::LogX()) & Map::MaxY(); + /* Make sure the template is not too close to the upper edges; bottom edges are checked later. */ uint edge_distance = 1 + (_settings_game.construction.freeform_edges ? 1 : 0); if (x <= edge_distance || y <= edge_distance) return; @@ -881,6 +884,9 @@ static void GenerateTerrain(int type, uint flag) const byte *p = templ->data; if ((flag & 4) != 0) { + /* This is only executed in secondary/tertiary loops to generate the terrain for arctic and tropic. + * It prevents the templates to be applied to certain parts of the map based on the flags, thus + * creating regions with different elevations/topography. */ uint xw = x * Map::SizeY(); uint yw = y * Map::SizeX(); uint bias = (Map::SizeX() + Map::SizeY()) * 16; @@ -905,11 +911,15 @@ static void GenerateTerrain(int type, uint flag) } } + /* Ensure the template does not overflow at the bottom edges of the map; upper edges were checked before. */ if (x + w >= Map::MaxX()) return; if (y + h >= Map::MaxY()) return; TileIndex tile = TileXY(x, y); + /* Get the template and overlay in a particular direction over the map's height from the given + * origin point (tile), and update the map's height everywhere where the height from the template + * is higher than the height of the map. In other words, this only raises the tile heights. */ switch (direction) { default: NOT_REACHED(); case DIAGDIR_NE: diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 6617365f9c..3c2d229468 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -860,6 +860,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const switch (scc) { default: break; + /* These control codes take one string parameter, check there are at least that many available. */ case SCC_NEWGRF_PRINT_DWORD_SIGNED: case SCC_NEWGRF_PRINT_WORD_SIGNED: case SCC_NEWGRF_PRINT_BYTE_SIGNED: @@ -889,6 +890,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const } break; + /* These string code take two string parameters, check there are at least that many available. */ case SCC_NEWGRF_PRINT_WORD_CARGO_LONG: case SCC_NEWGRF_PRINT_WORD_CARGO_SHORT: case SCC_NEWGRF_PRINT_WORD_CARGO_TINY: @@ -900,6 +902,8 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const } if (_newgrf_textrefstack.used && modify_argv) { + /* There is data on the NewGRF text stack, and we want to move them to OpenTTD's string stack. + * After this call, a new call is made with `modify_argv` set to false when the string is finally formatted. */ switch (scc) { default: NOT_REACHED(); case SCC_NEWGRF_PRINT_BYTE_SIGNED: *argv = _newgrf_textrefstack.PopSignedByte(); break; @@ -927,6 +931,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const case SCC_NEWGRF_PRINT_DWORD_DATE_SHORT: case SCC_NEWGRF_PRINT_DWORD_HEX: *argv = _newgrf_textrefstack.PopUnsignedDWord(); break; + /* Dates from NewGRFs have 1920-01-01 as their zero point, convert it to OpenTTD's epoch. */ case SCC_NEWGRF_PRINT_WORD_DATE_LONG: case SCC_NEWGRF_PRINT_WORD_DATE_SHORT: *argv = _newgrf_textrefstack.PopUnsignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break; @@ -954,7 +959,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const } } } else { - /* Consume additional parameter characters */ + /* Consume additional parameter characters that follow the NewGRF string code. */ switch (scc) { default: break; @@ -965,6 +970,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const } } + /* Emit OpenTTD's internal string code for the different NewGRF variants. */ switch (scc) { default: NOT_REACHED(); case SCC_NEWGRF_PRINT_DWORD_SIGNED: @@ -1027,6 +1033,7 @@ uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const case SCC_NEWGRF_PRINT_WORD_STATION_NAME: return SCC_STATION_NAME; + /* These NewGRF string codes modify the NewGRF stack or otherwise do not map to OpenTTD string codes. */ case SCC_NEWGRF_DISCARD_WORD: case SCC_NEWGRF_ROTATE_TOP_4_WORDS: case SCC_NEWGRF_PUSH_WORD: diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 134b488960..db9074784b 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -223,9 +223,11 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SpriteID sprite = rtl ? SPR_ARROW_LEFT : SPR_ARROW_RIGHT; Dimension sprite_size = GetSpriteSize(sprite); if (v->cur_real_order_index == order_index) { + /* Draw two arrows before the next real order. */ DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2); DrawSprite(sprite, PAL_NONE, rtl ? right - 2 * sprite_size.width : left + sprite_size.width, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2); } else if (v->cur_implicit_order_index == order_index) { + /* Draw one arrow before the next implicit order; the next real order will still get two arrows. */ DrawSprite(sprite, PAL_NONE, rtl ? right - sprite_size.width : left, y + ((int)FONT_HEIGHT_NORMAL - (int)sprite_size.height) / 2); } @@ -271,6 +273,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(2, order->GetDestination()); if (timetable) { + /* Show only wait time in the timetable window. */ SetDParam(3, STR_EMPTY); if (order->GetWaitTime() > 0) { @@ -278,6 +281,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetTimetableParams(6, 7, order->GetWaitTime()); } } else { + /* Show non-stop, refit and stop location only in the order window. */ SetDParam(3, (order->GetNonStopType() & ONSF_NO_STOP_AT_DESTINATION_STATION) ? STR_EMPTY : _station_load_types[order->IsRefit()][unload][load]); if (order->IsRefit()) { SetDParam(4, order->IsAutoRefit() ? STR_ORDER_AUTO_REFIT_ANY : CargoSpec::Get(order->GetRefitCargo())->name); @@ -291,6 +295,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int case OT_GOTO_DEPOT: if (order->GetDepotActionType() & ODATFB_NEAREST_DEPOT) { + /* Going to the nearest depot. */ SetDParam(0, STR_ORDER_GO_TO_NEAREST_DEPOT_FORMAT); if (v->type == VEH_AIRCRAFT) { SetDParam(2, STR_ORDER_NEAREST_HANGAR); @@ -300,6 +305,7 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(3, STR_ORDER_TRAIN_DEPOT + v->type); } } else { + /* Going to a specific depot. */ SetDParam(0, STR_ORDER_GO_TO_DEPOT_FORMAT); SetDParam(2, v->type); SetDParam(3, order->GetDestination()); @@ -311,10 +317,12 @@ void DrawOrderString(const Vehicle *v, const Order *order, int order_index, int SetDParam(1, (order->GetNonStopType() & ONSF_NO_STOP_AT_INTERMEDIATE_STATIONS) ? STR_ORDER_GO_NON_STOP_TO : STR_ORDER_GO_TO); } + /* Do not show stopping in the depot in the timetable window. */ if (!timetable && (order->GetDepotActionType() & ODATFB_HALT)) { SetDParam(5, STR_ORDER_STOP_ORDER); } + /* Do not show refitting in the depot in the timetable window. */ if (!timetable && order->IsRefit()) { SetDParam(5, (order->GetDepotActionType() & ODATFB_HALT) ? STR_ORDER_REFIT_STOP_ORDER : STR_ORDER_REFIT_ORDER); SetDParam(6, CargoSpec::Get(order->GetRefitCargo())->name); diff --git a/src/spritecache.cpp b/src/spritecache.cpp index 08b1ad85a9..aee8661c4d 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -51,7 +51,7 @@ static inline SpriteCache *GetSpriteCache(uint index) static inline bool IsMapgenSpriteID(SpriteID sprite) { - return IsInsideMM(sprite, 4845, 4882); + return IsInsideMM(sprite, SPR_MAPGEN_BEGIN, SPR_MAPGEN_END); } static SpriteCache *AllocateSpriteCache(uint index) diff --git a/src/table/sprites.h b/src/table/sprites.h index 407a7a2d87..907d37fdcc 100644 --- a/src/table/sprites.h +++ b/src/table/sprites.h @@ -1126,6 +1126,10 @@ static const SpriteID SPR_OTTD_N = 4839; static const SpriteID SPR_OTTD_T = 4836; /* Letters not used: R,A,S,Y,C (4837, 4838, 4840, 4843, 4844) */ +/* Range of "special" sprites that are used by the old map generation algorithm. */ +static const SpriteID SPR_MAPGEN_BEGIN = 4845; +static const SpriteID SPR_MAPGEN_END = 4882; + static const SpriteID SPR_HIGHSCORE_CHART_BEGIN = 4804; static const SpriteID SPR_TYCOON_IMG1_BEGIN = 4814; static const SpriteID SPR_TYCOON_IMG2_BEGIN = 4824;