From 09cf61b4661373ee2ecaf92f807cb7f76b821b6a Mon Sep 17 00:00:00 2001 From: rubidium Date: Sun, 7 Sep 2008 21:41:47 +0000 Subject: [PATCH] (svn r14267) [0.6] -Backport from trunk: - Fix: Make the 'Transfer Credit' display aware of the entire consist, not only the first vehicle (r14098) - Fix: Do not flood a NewGRF industry when it implicitly tells that it wants to be build on water (land shape flags bit 5) [FS#2230] (r14093) - Fix: The vehicle window of articulated road vehicles would show the clone/refit button when the vehicle was not completely stopped in the depot (r14090) - Fix: Flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension [FS#2228] (r14087) - Fix: Division by 0 in NewAI [FS#2226] (r14062) - Fix: NewGRF callback 23 did not use the NewGRF compatible text stack [FS#2224] (r14058) - Fix: NewGRF text stack's "push word" didn't move the data around properly (r14057) - Fix: Long strings in the edit box would cause OpenTTD to stop drawing the string. This is especially noticable with low resolutions and the chat input box (r14054) - Fix: [OSX] changed the condition for selecting 8 or 32 bpp blitter by default. Now we will pick 32 bpp if no 8 bpp fullscreen resolutions are available on the main display (the one with the dock) (r14032) --- src/ai/trolly/trolly.cpp | 2 ++ src/aircraft_gui.cpp | 4 +++- src/blitter/factory.hpp | 16 +++++++++++----- src/gfx.cpp | 10 +++------- src/industry_cmd.cpp | 4 +++- src/newgrf_text.cpp | 28 ++++++++++++++++++---------- src/roadveh.h | 1 + src/roadveh_cmd.cpp | 12 ++++++------ src/roadveh_gui.cpp | 5 ++++- src/train_gui.cpp | 4 +++- src/vehicle_gui.cpp | 5 ++++- src/video/cocoa/fullscreen.mm | 9 +++++++++ 12 files changed, 67 insertions(+), 33 deletions(-) diff --git a/src/ai/trolly/trolly.cpp b/src/ai/trolly/trolly.cpp index e85fc36c48..da9a45fd9b 100644 --- a/src/ai/trolly/trolly.cpp +++ b/src/ai/trolly/trolly.cpp @@ -881,6 +881,7 @@ static int AiNew_HowManyVehicles(Player *p) length = _players_ainew[p->index].path_info.route_length; // Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; + if (tiles_a_day == 0) tiles_a_day = 1; // We want a vehicle in a station once a month at least, so, calculate it! // (the * 2 is because we have 2 stations ;)) amount = length * 2 * 2 / tiles_a_day / 30; @@ -897,6 +898,7 @@ static int AiNew_HowManyVehicles(Player *p) length = _players_ainew[p->index].path_info.route_length; // Calculating tiles a day a vehicle moves is not easy.. this is how it must be done! tiles_a_day = RoadVehInfo(i)->max_speed * DAY_TICKS / 256 / 16; + if (tiles_a_day == 0) tiles_a_day = 1; if (_players_ainew[p->index].from_deliver) { max_cargo = GetIndustry(_players_ainew[p->index].from_ic)->last_month_production[0]; } else { diff --git a/src/aircraft_gui.cpp b/src/aircraft_gui.cpp index 984d66e82f..6fa6d78c95 100644 --- a/src/aircraft_gui.cpp +++ b/src/aircraft_gui.cpp @@ -28,6 +28,7 @@ void DrawAircraftDetails(const Vehicle *v, int x, int y) { int y_offset = (v->Next()->cargo_cap != 0) ? -11 : 0; + Money feeder_share = 0; for (const Vehicle *u = v ; u != NULL ; u = u->Next()) { if (IsNormalAircraft(u)) { @@ -53,11 +54,12 @@ void DrawAircraftDetails(const Vehicle *v, int x, int y) SetDParam(1, cargo_count); SetDParam(2, u->cargo.Source()); DrawString(x, y + 21 + y_offset, STR_8813_FROM, TC_FROMSTRING); + feeder_share += u->cargo.FeederShare(); } } } - SetDParam(0, v->cargo.FeederShare()); + SetDParam(0, feeder_share); DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } diff --git a/src/blitter/factory.hpp b/src/blitter/factory.hpp index c9f85db00b..33e9bdc227 100644 --- a/src/blitter/factory.hpp +++ b/src/blitter/factory.hpp @@ -9,6 +9,10 @@ #include #include +#if defined(WITH_COCOA) +bool QZ_CanDisplay8bpp(); +#endif /* defined(WITH_COCOA) */ + /** * The base factory, keeping track of all blitters. */ @@ -65,13 +69,15 @@ public: { const char *default_blitter = "8bpp-optimized"; -#if defined(__APPLE__) - /* MacOS X 10.5 removed 8bpp fullscreen support. - * Because of this we will pick 32bpp by default */ - if (MacOSVersionIsAtLeast(10, 5, 0)) { +#if defined(WITH_COCOA) + /* Some people reported lack of fullscreen support in 8 bpp mode. + * While we prefer 8 bpp since it's faster, we will still have to test for support. */ + if (!QZ_CanDisplay8bpp()) { + /* The main display can't go to 8 bpp fullscreen mode. + * We will have to switch to 32 bpp by default. */ default_blitter = "32bpp-anim"; } -#endif /* defined(__APPLE__) */ +#endif /* defined(WITH_COCOA) */ if (GetBlitters().size() == 0) return NULL; const char *bname = (StrEmpty(name)) ? default_blitter : name; diff --git a/src/gfx.cpp b/src/gfx.cpp index 57f7fa4d45..5f79c6d9f2 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -568,8 +568,8 @@ Dimension GetStringBoundingBox(const char *str) /** Draw a string at the given coordinates with the given colour * @param string the string to draw - * @param x offset from left side of the screen, if negative offset from the right side - * @param y offset from top side of the screen, if negative offset from the bottom + * @param x offset from left side of the screen + * @param y offset from top side of the screen * @param real_color colour of the string, see _string_colormap in * table/palettes.h or docs/ottd-colourtext-palette.png or the enum TextColour in gfx_type.h * @return the x-coordinates where the drawing has finished. If nothing is drawn @@ -585,11 +585,7 @@ int DoDrawString(const char *string, int x, int y, uint16 real_color) byte previous_color = color; if (color != 0xFE) { - if (x >= dpi->left + dpi->width || - x + _screen.width * 2 <= dpi->left || - y >= dpi->top + dpi->height || - y + _screen.height <= dpi->top) - return x; + if (x >= dpi->left + dpi->width || y >= dpi->top + dpi->height) return x; if (color != 0xFF) { switch_color:; diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index b0d8e6db7a..66728eab31 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -407,7 +407,9 @@ static CommandCost ClearTile_Industry(TileIndex tile, byte flags) if ((_current_player != OWNER_WATER && _game_mode != GM_EDITOR && !_cheats.magic_bulldozer.value) || ((flags & DC_AUTO) != 0) || - (_current_player == OWNER_WATER && (indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER))) { + (_current_player == OWNER_WATER && + ((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) || + HasBit(GetIndustryTileSpec(GetIndustryGfx(tile))->slopes_refused, 5)))) { SetDParam(0, indspec->name); return_cmd_error(STR_4800_IN_THE_WAY); } diff --git a/src/newgrf_text.cpp b/src/newgrf_text.cpp index 9417c7d686..f69ccda2af 100644 --- a/src/newgrf_text.cpp +++ b/src/newgrf_text.cpp @@ -238,8 +238,8 @@ char *TranslateTTDPatchCodes(uint32 grfid, const char *str) case 0x80: d += Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD + c - 0x7B); break; case 0x81: { StringID string; - string = *str++; - string |= *str++ << 8; + string = ((uint8)*str++); + string |= ((uint8)*str++) << 8; d += Utf8Encode(d, SCC_STRING_ID); d += Utf8Encode(d, MapGRFStringID(grfid, string)); break; @@ -270,14 +270,22 @@ char *TranslateTTDPatchCodes(uint32 grfid, const char *str) case 0x9A: switch (*str++) { case 0: /* FALL THROUGH */ - case 1: d += Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_CURRENCY); break; + case 1: + d += Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_CURRENCY); + break; case 3: { - uint16 tmp = *str++; - tmp |= (*str++) << 8; - d += Utf8Encode(d, SCC_NEWGRF_PUSH_WORD); d += Utf8Encode(d, tmp); + uint16 tmp = ((uint8)*str++); + tmp |= ((uint8)*str++) << 8; + d += Utf8Encode(d, SCC_NEWGRF_PUSH_WORD); + d += Utf8Encode(d, tmp); } break; - case 4: d += Utf8Encode(d, SCC_NEWGRF_UNPRINT); d += Utf8Encode(d, *str++); break; - default: grfmsg(1, "missing handler for extended format code"); break; + case 4: + d += Utf8Encode(d, SCC_NEWGRF_UNPRINT); + d += Utf8Encode(d, *str++); + break; + default: + grfmsg(1, "missing handler for extended format code"); + break; } break; @@ -543,8 +551,8 @@ struct TextRefStack { if (this->position >= 2) { this->position -= 2; } else { - for (uint i = lengthof(stack) - 3; i >= this->position; i--) { - this->stack[this->position + 2] = this->stack[this->position]; + for (int i = lengthof(stack) - 1; i >= this->position + 2; i--) { + this->stack[i] = this->stack[i - 2]; } } this->stack[this->position] = GB(word, 0, 8); diff --git a/src/roadveh.h b/src/roadveh.h index fa6df94eb8..739f2aba4e 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -74,6 +74,7 @@ struct RoadVehicle : public Vehicle { int GetDisplayMaxSpeed() const { return this->max_speed * 10 / 32; } Money GetRunningCost() const { return RoadVehInfo(this->engine_type)->running_cost * GetPriceByIndex(RoadVehInfo(this->engine_type)->running_cost_class); } bool IsInDepot() const { return this->u.road.state == RVSB_IN_DEPOT; } + bool IsStoppedInDepot() const; void Tick(); void OnNewDay(); }; diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 77b94fa826..44a9f4afea 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -334,14 +334,14 @@ void ClearSlot(Vehicle *v) DEBUG(ms, 3, "Clearing slot at 0x%X", rs->xy); } -static bool CheckRoadVehInDepotStopped(const Vehicle *v) +bool RoadVehicle::IsStoppedInDepot() const { - TileIndex tile = v->tile; + TileIndex tile = this->tile; if (!IsTileDepotType(tile, TRANSPORT_ROAD)) return false; - if (IsRoadVehFront(v) && !(v->vehstatus & VS_STOPPED)) return false; + if (IsRoadVehFront(this) && !(this->vehstatus & VS_STOPPED)) return false; - for (; v != NULL; v = v->Next()) { + for (const Vehicle *v = this; v != NULL; v = v->Next()) { if (v->u.road.state != RVSB_IN_DEPOT || v->tile != tile) return false; } return true; @@ -365,7 +365,7 @@ CommandCost CmdSellRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) if (HASBITS(v->vehstatus, VS_CRASHED)) return_cmd_error(STR_CAN_T_SELL_DESTROYED_VEHICLE); - if (!CheckRoadVehInDepotStopped(v)) { + if (!v->IsStoppedInDepot()) { return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); } @@ -2150,7 +2150,7 @@ CommandCost CmdRefitRoadVeh(TileIndex tile, uint32 flags, uint32 p1, uint32 p2) v = GetVehicle(p1); if (v->type != VEH_ROAD || !CheckOwnership(v->owner)) return CMD_ERROR; - if (!CheckRoadVehInDepotStopped(v)) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); + if (!v->IsStoppedInDepot()) return_cmd_error(STR_9013_MUST_BE_STOPPED_INSIDE); if (v->vehstatus & VS_CRASHED) return_cmd_error(STR_CAN_T_REFIT_DESTROYED_VEHICLE); if (new_cid >= NUM_CARGO) return CMD_ERROR; diff --git a/src/roadveh_gui.cpp b/src/roadveh_gui.cpp index 1c95d716f8..acf579d45d 100644 --- a/src/roadveh_gui.cpp +++ b/src/roadveh_gui.cpp @@ -25,6 +25,7 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) { uint y_offset = RoadVehHasArticPart(v) ? 15 : 0; StringID str; + Money feeder_share = 0; SetDParam(0, v->engine_type); SetDParam(1, v->build_year); @@ -70,6 +71,7 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) SetDParam(1, u->cargo.Count()); SetDParam(2, u->cargo.Source()); str = STR_8813_FROM; + feeder_share += u->cargo.FeederShare(); } DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); @@ -88,12 +90,13 @@ void DrawRoadVehDetails(const Vehicle *v, int x, int y) SetDParam(1, v->cargo.Count()); SetDParam(2, v->cargo.Source()); str = STR_8813_FROM; + feeder_share += v->cargo.FeederShare(); } DrawString(x, y + 21 + y_offset, str, TC_FROMSTRING); } /* Draw Transfer credits text */ - SetDParam(0, v->cargo.FeederShare()); + SetDParam(0, feeder_share); DrawString(x, y + 33 + y_offset, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } diff --git a/src/train_gui.cpp b/src/train_gui.cpp index a32f0a6fdd..1631beefa3 100644 --- a/src/train_gui.cpp +++ b/src/train_gui.cpp @@ -231,6 +231,7 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs } else { AcceptedCargo act_cargo; AcceptedCargo max_cargo; + Money feeder_share = 0; memset(max_cargo, 0, sizeof(max_cargo)); memset(act_cargo, 0, sizeof(act_cargo)); @@ -238,6 +239,7 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs for (const Vehicle *u = v; u != NULL ; u = u->Next()) { act_cargo[u->cargo_type] += u->cargo.Count(); max_cargo[u->cargo_type] += u->cargo_cap; + feeder_share += u->cargo.FeederShare(); } /* draw total cargo tab */ @@ -253,7 +255,7 @@ void DrawTrainDetails(const Vehicle *v, int x, int y, int vscroll_pos, uint16 vs DrawString(x, y + 2, FreightWagonMult(i) > 1 ? STR_TOTAL_CAPACITY_MULT : STR_TOTAL_CAPACITY, TC_FROMSTRING); } } - SetDParam(0, v->cargo.FeederShare()); + SetDParam(0, feeder_share); DrawString(x, y + 15, STR_FEEDER_CARGO_VALUE, TC_FROMSTRING); } } diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 98ac0b877c..86cc859e2a 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -486,7 +486,10 @@ uint ShowAdditionalText(int x, int y, uint w, EngineID engine) /* STR_02BD is used to start the string with {BLACK} */ SetDParam(0, GetGRFStringID(GetEngineGRFID(engine), 0xD000 + callback)); - return DrawStringMultiLine(x, y, STR_02BD, w); + PrepareTextRefStackUsage(0); + uint result = DrawStringMultiLine(x, y, STR_02BD, w); + StopTextRefStackUsage(); + return result; } /** Display list of cargo types of the engine, for the purchase information window */ diff --git a/src/video/cocoa/fullscreen.mm b/src/video/cocoa/fullscreen.mm index d7f542009c..d24a3704ec 100644 --- a/src/video/cocoa/fullscreen.mm +++ b/src/video/cocoa/fullscreen.mm @@ -155,6 +155,15 @@ uint QZ_ListModes(OTTD_Point* modes, uint max_modes, CGDirectDisplayID display_i return count; } +/* Small function to test if the main display can display 8 bpp in fullscreen */ +bool QZ_CanDisplay8bpp() +{ + OTTD_Point p; + + /* We want to know if 8 bpp is possible in fullscreen and not anything about resolutions. + * Because of this we want to fill a list of 1 resolution of 8 bpp on display 0 (main) and return if we found one. */ + return QZ_ListModes(&p, 1, 0, 8); +} class FullscreenSubdriver: public CocoaSubdriver { int display_width;