Commit Graph

914 Commits

Author SHA1 Message Date
Peter Nelson f14479d27d Codechange: Use std::optional for GRF Parameter list. 2023-05-18 20:48:37 +01:00
Peter Nelson c38df2d589 Codechange: Use std::map instead of custom SmallMap. 2023-05-18 12:18:30 +01:00
Peter Nelson 83f2ad500e Codechange: stdarg.h include not needed as cstdarg is included. 2023-05-17 10:14:41 +01:00
Peter Nelson 56085be9bd Codechange: Move includes for common STL headers to stdafx. 2023-05-17 10:14:41 +01:00
Peter Nelson 0b72297d57 Feature: Increase number of stations/roadstops per NewGRF. 2023-05-05 07:08:40 +01:00
Peter Nelson bc7dfd7b46 Add: Station property 1C/1D to set name/classname.
These are an alternative to the original "generic" C4xx/C5xx method,
which can only assign strings to IDs up to 256.
2023-05-05 07:08:40 +01:00
Peter Nelson d6f35a9fd6 Change: Add placeholders for unimplemented NewGRF station properties. 2023-05-05 07:08:40 +01:00
Peter Nelson e5c9a3e527 Change: Read Action 3 IDs as extended-bytes for all features.
This can be done because previous the value 0xFF (which indicates an
extended byte) was reserved for this purpose. Other features which may
not have mentioned reserving 0xFF do not allow this many IDs anyway.

This makes Action 3 consistent across all features. The allowable limits
for each feature do not change.
2023-05-05 07:08:40 +01:00
Peter Nelson 10baecd81f Change: Make Action 3 debug messages more consistent. 2023-05-05 07:08:40 +01:00
Rubidium 3901ef9760 Codechange: use std::string for the GRF filenames 2023-05-04 23:23:32 +02:00
Rubidium f78aa1e720 Codechange: use std::unique_ptr to manager GRFErrors in GRFConfig 2023-05-04 23:23:32 +02:00
Tyler Trahan 6501f84b4a
Codechange: Move calendar date functions inside TimerGameCalendar (#10753) 2023-05-04 13:14:12 +00:00
Tyler Trahan 930f0a16d8 Codechange: Define Date/Year/Month/Day within TimerGameCalendar class 2023-04-26 07:14:03 -04:00
Peter Nelson 20d2558f1b Fix: Clear church/stadium flags when copying house substitute specs. 2023-04-26 06:46:07 +01:00
Peter Nelson 64782cf005 Fix #10627: Houses subsitute specs should only be copied on first definition.
Before #10627, substitue specs were always copied despite redefinition.
2023-04-26 06:46:07 +01:00
PeterN 7535eb65e2
Codechange: Use vector instead of mallloc/free for Action 6 data. (#10713) 2023-04-26 06:45:11 +01:00
Rubidium f74e26ca7e Codechange: replace error/usererror printf variant with fmt variant and rename 2023-04-25 17:55:09 +02:00
Patric Stout 31ad990831
Codechange: move tick-counter into TimerGameTick (#10712) 2023-04-24 16:55:40 +00:00
Patric Stout 7aa2b9ab0a
Codechange: move all date-related variables inside the timer (#10706) 2023-04-24 15:56:01 +00:00
Rubidium 7b539fa7c9 Fix: fmt's {:#04X} yields '0X00', not '0x0000'
Technically the 0X vs 0x is not a big problem, just not pretty. However, the
length also including the 0x results in unexpected behaviour, so it probably
better to not use it.
2023-04-20 21:39:57 +02:00
PeterN 27b4b5d0a0
Codechange: Make GRF temporary engine data a vector. (#10685)
This replaces manual C-style realloc/memset/free.
2023-04-20 19:38:48 +00:00
Rubidium 7088f5b7c7 Codechange: use string/fmt instead of printf for grfmsg 2023-04-18 23:21:08 +02:00
PeterN d949cfab24
Codechange: Use std:: features for NewGRF town names (#10631)
This removes manual memory (de-)allocation and list counting.
2023-04-16 21:24:54 +01:00
Peter Nelson 7b0797d1cd Codechange: Use unique ptrs for NewGRF specs. 2023-04-16 15:09:10 +01:00
Peter Nelson ef6b307465 Change: Use std::vector for NewGRF spec tables.
Pointer space is allocated only for the number of IDs used, instead of
the max number of IDs for each feature.
2023-04-16 15:09:10 +01:00
Peter Nelson 15e6fc4eeb Codechange: Use iterator when mapping sprite groups. 2023-04-16 15:09:10 +01:00
Charles Pigott b282664242 Codechange: Replace all usages of alloca/AllocaM with more modern/less discouraged alternatives 2023-04-15 16:57:00 +01:00
PeterN 246ba6f00a
Fix 8361cf5a73: Missing bounds check for house specs. (#10625) 2023-04-10 15:00:34 +00:00
Peter Nelson 08977828cc Fix: Check ID for name is within bounds. 2023-04-07 22:09:28 +01:00
Peter Nelson cd6c04a663 Fix: Check station ID is within bounds when copying layouts. 2023-04-07 22:09:28 +01:00
Peter Nelson 8361cf5a73 Fix: Check sprite group mapping ID is within bounds of feature. 2023-04-07 22:09:28 +01:00
Peter Nelson 96f4eb3681 Codechange: Check NewGRF feature is defined before processing any sprite group mapping.
Previously this was checked after loading ids, or repeatedly checked for
each item.
2023-04-07 22:09:28 +01:00
Peter Nelson 04215afe3f Codechange: Replace roadstop spec limit magic number with constant. 2023-04-07 22:09:28 +01:00
Peter Nelson 93197f58b7 Codechange: Bind objectspecs to classes once all finalised. 2023-04-02 22:42:38 +01:00
Joan Josep d80f193e74
Fix: Improve grfmessage for ShipVehicleChangeInfo. (#10558) 2023-03-08 20:59:01 +00:00
Jonathan G Rennison 5d0ad5625b
Fix : [NewGRF] Object and road stop ignore property handlers (#10525)
* Fix: IgnoreObjectProperty did not handle object property 0x18

* Fix: IgnoreRoadStopProperty did not handle properties 0x0E - 0x12, 0x15
2023-03-01 01:19:39 +01:00
Jonathan G Rennison 4c1406a4b5 Add: NewGRF road stops 2023-02-26 21:28:30 +01:00
Michael Lutz 2d73076056 Add: [NewGRF] Second vehicle property for additional callback flags. 2023-01-30 22:00:56 +01:00
Michael Lutz f5394ed2ef Change: [NewGRF] Extend the D8xx (DCxx) string area up to FFFF.
This adds the Exxx and Fxxx blocks to the usable range for NewGRF
local strings. TTDPatch uses these ranges for internal strings, but as
we don't support any of them anyway, it is "free" real estate for us.
2023-01-30 22:00:56 +01:00
rubidium42 6ba55e663e Codechange: do not hide variables with other variables 2023-01-29 07:21:34 +01:00
Rubidium fe2bcd2a58 Codechange: migrate size related functions to Map structure 2023-01-21 17:11:40 +01:00
Francis Herne 01be423237 Fix #10362: NewGRF bridges without speed limits.
For bridges, a max speed of 0xFFFF (i.e. no effective limit)
 is no longer displayed as a limit in the UI.

A max speed of 0 is also considered unlimited, for similarity to the
 roadtype and railtype interface.
2023-01-19 22:24:33 +01:00
PeterN 2355882ec1
Codechange: Remove object `enabled` flag and shuffle members. (#10358)
`enabled` flag is replaced with IsEnabled() which checks if views is
non-zero.

ObjectSpec is shuffled to reduce its memory footprint.
2023-01-15 10:58:03 +00:00
PeterN 6a0d1c7c19
Fix: Link variants to parents when finalising engines. (#10346)
This ensures that definition-order of engines within the NewGRF does not matter.
2023-01-13 19:22:31 +00:00
PeterN 1b1aa682a6
Fix: Don't assume engclass 2 should be elrail. (#10315)
When disabling/enabling elrail, there is an assumption that `engclass` of 2
means the engine will run on elrail. While this holds for default engines,
NewGRFs can do other things.

To resolve this we store the intended railtype so that toggling elrail will
restore to the correct type.
2023-01-06 00:44:57 +00:00
Francis Herne 6caed5f15e
Add: Slope-aware and roadtype-specific one-way sprites. (#10282) 2022-12-26 15:06:21 -05:00
PeterN 4f26f6b8aa
Cleanup: Simplify GRFLabel linked-list with std::vector. (#10284) 2022-12-25 22:32:22 +00:00
Peter Nelson 3485709f53 Add: Additional vehicle flags to control variants. 2022-12-25 16:41:58 +00:00
Peter Nelson 85814b29d4 Feature: Vehicle add-ons can now group engines in purchase list.
Grouped engines are collapsed by default but can be expanded. This allows
similar engines to be grouped together to avoid cluttering the list.

Suggested uses for this are e.g.:
* Liveries; same stats but different paint job.
* Re-gearing; engine design is mostly the same but different stats.

... but avoiding complex hidden cargo subtype refit systems.

Grouped engines are otherwise separate, so can be independently
autoreplaced, even between variants.
2022-12-25 16:41:58 +00:00
peter1138 d7f561a400 Change: Add variant property to engines. 2022-12-25 16:41:58 +00:00
PeterN 7b5edba76c
Change: Support flipping shorter engines without NewGRF support. (#10262)
* Change: Support flipping shorter engines without NewGRF support.
* Cleanup: Remove write-only prop27_set temporary flag.
2022-12-23 21:02:14 +00:00
PeterN f24286a1ae
Fix: Ensure 31-bit shifts are unsigned. (#10128)
Shifting a signed 32-bit integer by 31 bits is undefined behaviour.
A few more than necessary are switched to unsigned for consistentency.
2022-11-04 07:15:59 +00:00
Michael Lutz bd357656ba Codechange: [NewGRF] Replace magic number for default object size by a constant. 2022-10-16 18:28:08 +02:00
frosch f4e2a462fe Cleanup: Remove unused flag sprites. 2022-10-16 14:56:52 +02:00
dP 548f0496a9
Change: Make _tick_counter 64bit to avoid wrapping (#10035) 2022-09-21 12:42:29 +02:00
frosch e2c46fda3f Fix: [NewGRF] Ensure that stations always have an even number of sprite layouts.
The drawing code has a special fallbacks for zero layouts, but fails hard for one layout.
(odd numbers >= 3 are weird, but do not fail as badly as 1)
2022-09-11 21:26:06 +02:00
Jonathan G Rennison 4acccc232a Fix #9925: Industry tile layout validation for layouts of only one tile 2022-06-18 22:02:08 +02:00
Niels Martin Hansen 5587e439a9 Fix: Industry layouts with zero regular tiles should be invalid 2022-05-29 16:34:30 +02:00
Michael Lutz 08a5478a93 Add: [NewGRF] Map seed as global variable.
This is useful to provide a feature-agnostic, stable random value that differs between games.
One of the possible uses is to e.g. use it to create pseudo-random regions for towns or industries.
2022-03-13 14:20:23 +01:00
Jonathan G Rennison fc58ed9987
Codechange: Remove CargoSpec::multipliertowngrowth which is unused (#9701)
This is set by cargo property 19.
This property is only implemented in TTDPatch.
2021-11-16 22:48:21 +00:00
Michael Lutz 95c8467670 Fix 65cbde4b: Writing to uninitialized string when loading a currency NewGRF. 2021-11-06 19:15:29 +01:00
PeterN 7e70ead396
Fix #9562: Handle case of invalid action2 with zero results. (#9564) 2021-09-19 21:52:08 +01:00
Charles Pigott 16dca0d7bc Codechange: Object non-zero dimension check was not logically correct 2021-09-11 23:10:50 +01:00
Vít Šefl 2183fd4dab
Feature: [NewGRF] Maximum curve speed modifier for rail vehicles (#9346) 2021-08-15 11:17:05 +02:00
Rubidium 178ea3196b Remove: includes to network/core/config.h from headers when only three cpp files need it 2021-07-11 22:13:59 +02:00
Patric Stout 6f0c6fb2ae Fix a4987233: NewGRFs could no longer be loaded from the NewGRF folder.
This statement was removed by accident, as it felt it could be removed.
But it is used to know if the NewGRF is from the baseset folder or
from the NewGRF folder.
2021-07-11 12:16:07 +02:00
rubidium42 a498723345
Remove: arbitrary limit on number of statically loaded NewGRFs (#9431) 2021-07-11 11:23:47 +02:00
glx22 a543a4b7bb Codechange: Remove FOR_EACH_SET_CARGO_ID 2021-07-09 21:36:09 +02:00
glx22 89ab8b79a5 Codechange: Remove FOR_EACH_SET_BIT 2021-07-09 21:36:09 +02:00
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 2021-06-13 12:45:45 +02:00
Peter Nelson 40cec34836 Change: Skip creating a RealSpriteGroup when there is only one result.
This avoids checking RSG for empty sets every time they are evaluated.
This might alter behaviour in cases of a malformed NewGRF file.
2021-06-12 08:05:59 +01:00
Patric Stout ca9a7df752
Codechange: rename str_validate to StrMakeValid(InPlace) (#9304)
This to be more explicit the function changes the value, and not
returns yes/no.
2021-05-29 11:21:38 +02:00
rubidium42 ae85af98eb Codechange: Use std::string GetString where convenient 2021-05-15 10:20:50 +02:00
rubidium42 44ca7d9377 Change: Use gender-neutral pronouns 2021-05-15 10:16:48 +02:00
Rubidium e6f0d63e25 Codechange: comparison result is always the same due to earlier check
Practically the length of the handlers not being equal to the number of
features is the problem as it means something was forgotten when adding
a new feature, so static assert to that and let the existing check on
the feature number take care of invalid data from the NewGRFs.
2021-05-15 10:16:10 +02:00
frosch 1da0ba95b2 Feature: Define refittability of default vehicles using cargo classes.
This ensures that default vehicles can transport any NewGRF defined cargos, albeit with weird graphics and vehicle names.
This also changes the refittability of default vehicles with default industries.
2021-05-13 23:28:43 +02:00
frosch 9f8d0b1bee Fix: Resolve cargo-types of default vehicles via their cargo label.
Default vehicles now behave as if they had a cargo translation table. This fixes default vehicles carrying seemingly random cargos, if NewGRF industry sets are present.
This behavior is disabled, when a NewGRF touches any of the cargo-type or refitting properties. In that case it's up to the NewGRF to define its own cargo translation table.
2021-05-13 23:28:43 +02:00
rubidium42 65cbde4b30 Codechange: move currency settings to std::string 2021-05-13 23:13:17 +02:00
Rubidium 296194ad36 Fix: memory leak due to assigning result of strdup to a std::string 2021-05-10 16:03:31 +02:00
Rubidium 10e35ca8e4 Codechange: let NewGRF make use of SpriteFile instead of most of the FIO slot functions 2021-05-08 12:39:34 +02:00
Rubidium fdc11a9f94 Codechange: introduce SpriteFile to be used by the sprite loader instead of the global FIO slot functionality 2021-05-08 12:39:34 +02:00
Rubidium c097bc9d7d Codechange: let NewGRF sounds make use of RandomAccessFile instead of the FIO slot functions 2021-05-08 12:39:34 +02:00
Peter Nelson 756034fa27 Codechange: Validate custom station platform layout tiles are permitted values only. 2021-05-02 17:15:27 +01:00
Peter Nelson a3e49178d1 Codechange: Use std::vector for NewGRF station tile sprite layouts. 2021-05-02 17:15:27 +01:00
Peter Nelson bd1a20f6ee Codechange: Use std::vector for NewGRF station platform layouts.
This avoids the need to custom memory management and additional members.

This also resolves use-after-free if modifying copied layouts, so presumably nobody has ever done that.
2021-05-02 17:15:27 +01:00
Peter Nelson 18fb1c3866 Codechange: Warn if randomaction2 group count is not a power of 2.
Previously noted by a comment, this does not need to be guarded against as non-powers of 2 will not cause issues beyond the choice of results being reduced.
2021-05-02 09:41:01 +01:00
Peter Nelson 913d8a7f28 Cleanup: Use std::vector in RandomSpriteGroup. 2021-05-02 09:41:01 +01:00
Peter Nelson 1aeaf39954 Cleanup: Use std::vector in DeterministicSpriteGroup. 2021-05-02 09:41:01 +01:00
Peter Nelson f785a70a2b Cleanup: Use std::vector in RealSpriteGroup. 2021-05-02 09:41:01 +01:00
glx22 9a8756d7ed Codechange: Replace FOR_ALL_CARGOSPECS with range-based for loops 2021-04-29 21:08:24 +02:00
Jonathan G Rennison 83ac5aa27a
Fix: Memory leak of airport tile layout in AirportChangeInfo (prop 0A) (#8928) 2021-04-02 10:13:53 +02:00
Patric Stout 1a1049bc0d Change: rename setting "max_heightlevel" to "map_height_limit"
This better reflects what it is, and hopefully removes a bit of
the confusion people are having what this setting actually does.

Additionally, update the text on the setting to better inform
users what it is doing exactly, so they can make an educated
decision on how to change it.

Next commit will introduce an "auto" value, which should be the
new default. The rename has as added benefit that everyone will
start out on the "auto" value.
2021-03-26 12:22:32 +01:00
Charles Pigott 8157af6d68 Fix #8276: Crash when a NewGRF object's size was not set 2021-02-21 18:16:09 +00:00
Charles Pigott 9b800a96ed
Codechange: Remove min/max functions in favour of STL variants (#8502) 2021-01-08 11:16:18 +01:00
Charles Pigott 860c270c73 Codechange: Replace assert_compile macro with static_assert 2020-12-27 10:55:42 +00:00
Michael Lutz 1478fa93b3 Add: [NewGRF] Patch flag to test if inflation is on or off. 2020-12-27 10:28:39 +00:00
frosch d5f05fb781
Fix: [NewGRF] Action 7/9 conditions 0x0F to 0x12 failed, if 'param' was 0x88. (#8382)
Fix: [NewGRF] Action 7/9 conditions 0x0B to 0x12 failed, if 'param' was 0x85.
These conditions are supposed to ignore 'param' entirely.
2020-12-15 22:42:03 +01:00
Michael Lutz 79240eab1e Codechange: Make use of the improved C++17 emplace_back function. 2020-12-15 00:29:30 +01:00
Yexo 1507902d00 Codechange: remove has_newindustries global 2020-06-01 22:46:06 +02:00
Yexo a82572d0f5 Codechange: remove has_newhouses global 2020-06-01 22:46:06 +02:00