1
0
Fork 0
Commit Graph

1029 Commits (fe9dfa2b085764d6dad7949d7b4574af7f5e1376)

Author SHA1 Message Date
Peter Nelson 2f0b52d5b3
Codechange: Use sorted vector for NewGRF parameter value names. (#13326)
This replaces use of a std::map per GRF-parameter.
2025-01-17 19:33:11 +00:00
Peter Nelson 74bd064d10
Codechange: Pass first and last ID range instead of first and count. (#13319)
This allows range checks and loops to be slightly simplified.
2025-01-14 21:22:52 +00:00
Rubidium 3541ba4d0c Codechange: use unique_ptr over CallocT and avoid copying table 2025-01-13 23:13:28 +01:00
Peter Nelson 11529d865b
Codefix: [NewGRF] Don't read an extended byte into uint8_t. (#13302) 2025-01-11 15:53:24 +00:00
Peter Nelson 2d372fa516 Codechange: NewGRF strings are not StringIDs.
Add GRFStringID type and use it when dealing with GRF-local string IDs.
2025-01-02 20:03:40 +00:00
Peter Nelson 4edde7d6de
Change: [NewGRF] Use deferred string mapping for bridge and currency names. (#13230)
This means that the strings can now be defined after the properties using them, as is the case with all other features.
2025-01-02 09:35:15 +00:00
Peter Nelson 0464e6bd13
Codefix: Remove obsolete industry string mapping. (#13229)
These strings are already correctly mapped by the deferred AddStringForMapping() system.
2025-01-01 22:37:43 +00:00
Rubidium c0df898ac5 Codechange: do not implicitly convert during assignment to StrongType 2025-01-01 21:32:51 +01:00
Rubidium 3956ed086a Codechange: use Date/Year constructor explicitly 2025-01-01 16:25:32 +01:00
Rubidium 9b3f4dff4c Codechange: swap `int + year` to `year + int`
This way the operator+ without implicit constructor call is used
2025-01-01 00:10:35 +01:00
Rubidium 54d58a08f3 Codechange: use (better) named constants for the bridge sprite table 2024-12-22 13:59:18 +01:00
Peter Nelson 7af16bff11
Codechange: Use vector for GRFFile parameters instead of array. (#13157)
This simplifies assigning default parameters and removes the param_end member.
2024-12-07 22:08:59 +00:00
Peter Nelson f5d78f9eba
Change: [NewGRF] Install translation tables into overridden NewGRF. (#12879)
When a NewGRF overrides another, any translation table that the overriding NewGRF installs will also be installed in the target file.

This allows the overridden NewGRF to make use of a cargo or rail/road type translation table without directly modifying the original file.
2024-12-07 11:26:53 +00:00
Peter Nelson ce5279a8dc Codechange: Implement SoundLoader interface and cache loaded sounds in memory.
Sounds are loaded into memory on first use, using the SoundLoader interface to support format conversion. Sounds are retained in memory to avoid reloading every time a sound is played.

This deduplicates WAV header parsing between NewGRF and baseset sounds, and will allow different audio formats to be supported.
2024-12-06 18:41:35 +00:00
Peter Nelson f56b6756f1 Codechange: Sort EngineOverrideManager for fast lookups.
Allows quickly finding the EngineID given the type, grfid and local id of an engine, instead a linear scan.

This can reduce loading time when lots of engines are present and also affects performance in-game.
Lookup can be on the order of 10000 times faster.
2024-12-05 18:17:58 +00:00
Peter Nelson bc2513975f Codechange: Don't inherit EngineOverrideManager from std::vector.
Inheriting from std::vector means some operations are needlessly complex, and shouldn't really be done anyway.
2024-12-05 18:17:58 +00:00
Peter Nelson e73d6fcaac Codechange: Store grfid with entity grfprops.
This allows using the grfid without having to dereference the grffile pointer.

Uses no extra storage as it fits within otherwise wasted padding space.
2024-12-05 18:17:58 +00:00
Peter Nelson e750d10cee
Codechange: Use std::array for per-NewGRF rail/road type maps. (#13142)
This allows initialisation to be simplified.
2024-12-05 18:17:25 +00:00
Peter Nelson 3a310f1802
Codechange: Store GRFConfig parameters in a vector. (#13137)
All GRFConfigs have space allocated for parameters, but only configured GRFConfigs need them.

Using a vector instead means that space is only used when parameters are used.
2024-12-01 15:15:21 +00:00
Peter Nelson b6aece5b88
Fix 51bd344f10: Incorrect translation table used for older NewGRFs. (#13131)
Incorrect logic was used to select the default translation table for older GRFs.
2024-11-29 07:46:08 +00:00
Peter Nelson 9bc64b553b
Codechange: Cache callback spritegroups. (#13111)
Each callback result requires a pool memory allocation, each of which is 24 bytes.

Build a cache of results so that if the same result is used later it refers to the same group.
2024-11-27 23:25:35 +00:00
Jonathan G Rennison f5a6a31e4a
Codefix: Avoid divide by 0 in div/mod type varaction2 adjusts (#13123) 2024-11-27 23:24:46 +00:00
Peter Nelson f9b5f78b8a Codechange: Use std::visit for GetActiveCargoLabel. 2024-11-19 18:27:19 +00:00
Michael Lutz d2496b6ec4 Add: [NewGRF] Callback for custom refit mask for engines/vehicles. 2024-11-18 22:10:38 +01:00
Michael Lutz a3ee05737f Add: [NewGRF] Vehicle prop that allows refittability based on cargo class intersection. 2024-11-18 22:10:38 +01:00
Peter Nelson 14e2839087
Codechange: Let's use this new emplace_back() thing. (#13081) 2024-11-15 20:28:17 +00:00
Peter Nelson 98c8445519
Codechange: Limit house default cargo label lists to original slot counts. (#13079)
Same as for IndustrySpec and IndustryTileSpec.
2024-11-15 08:07:02 +00:00
Peter Nelson 61aff3fa49
Codechange: Limit industry default cargo label lists to original slot counts. (#13072)
IndustrySpec and IndustryTileSpec cargo label lists are only used for original industries. Original industries can only have up to 2 inputs and 3 outputs. Therefore having space for 16 input/outputs slots is unnecessary

This saves 216 bytes per industry type, and 164 bytes per industry tile type.
2024-11-14 19:05:18 +00:00
Peter Nelson e076aaf740
Codefix: Use SpriteID when passing sprite IDs. (#13037) 2024-10-27 18:54:49 +00:00
Peter Nelson 51bd344f10
Change: Use default NewGRF cargo translation table. (#12646)
Instead of falling back to bitnum lookup or climate-dependent cargo types, install a default cargo translation table that performs either of these functions instead.

This allows better mapping of climate-dependent or bitnum cargo slots, falling back to INVALID_CARGO if they are not defined, and reduces special-casing.
2024-09-23 23:48:03 +01:00
Peter Nelson 9631c68ce6
Codefix: Implement explicit ByteReader::PeekDWord() instead of type-punning pointer. (#12928) 2024-09-12 06:49:20 +01:00
Jonathan G Rennison e477706bf5
Codechange: Add AssignBit function to assign the value of a single bit (#12934)
* Codechange: Add AssignBit function to assign the value of a single bit

* Codechange: Replace various uses of SB with AssignBit

* Codechange: Replace various uses of SB with a constant with SetBit
2024-09-10 08:36:58 -04:00
Peter Nelson b5264a72ae
Codechange: [NewGRF] Use reference to unique_ptr instead of .get() (#12919)
This allows assignment to reference when creating a new spec instead of setting and refetching.
2024-08-24 22:10:39 +01:00
Peter Nelson ff972ec4ff
Codechange: Store custom station layouts in a map instead of nested vectors. (#12898)
The map key is the platforms and length combined. This simplifies allocation and searching for layouts.
2024-08-14 19:58:56 +01:00
Peter Nelson a03ddb3ccb Add: [NewGRF] Station property 1E, extended station tile flags.
Properties 11, 14 and 15 to set pylons/nowires/blocked intrinsically only support 8 station tiles.

Add new property to define all three flags for each station tile layout.
2024-08-03 14:57:34 +01:00
Peter Nelson 6e553410d3 Feature: [NewGRF] Allow fixed layout up to 256 tiles per NewGRF rail station.
Allow using up to 256 tile layouts in property 0E or callback 24, which defines the layout to be saved into the map.

This was originally limited to 8, because station graphics above 8 referred to other station types but that was changed in 2007.

1) More efficient than using callback 14, as that needs to be checked every time a station tile is rendered.
2) The layout does not get changed when the station is changed (this may or may not be desirable!)

Using more than 256 layouts still requires callback 14.
2024-08-03 14:57:34 +01:00
Peter Nelson 3176de3f1d
Codefix: cargo_(dis)allowed for default refit masks are cargo classes, not CargoTypes. (#12884)
Use an alias for CargoClasses to avoid ambiguity.
2024-07-29 20:58:53 +01:00
Peter Nelson e22eb89b92 Codechange: Call BSWAP32() in the default_grf_overrides initializer.
This causes the BSWAP32 calls to happen only on first initialisation (BSWAP32 is not constexpr), instead of every time GRFs are reloaded.
2024-07-10 20:56:35 +01:00
Peter Nelson b090c8e9bd Codechange: Replace default overrides arrays with std::pair and use range-for.
This avoids indexed array access and use of lengthof.
2024-07-10 20:56:35 +01:00
Peter Nelson ba0acb87eb Fix #12832: Sanitise strings from NewGRF before logging them in Debug output.
NewGRF strings may not be UTF-8 encoded, which causes issues on Windows.
2024-07-10 12:53:23 +01:00
Jonathan G Rennison a43dacd988 Add: NewGRF custom road waypoint support 2024-06-24 22:12:08 +02:00
Jonathan G Rennison eebd5e47db Add: Road waypoint default graphics 2024-06-24 22:12:08 +02:00
Peter Nelson 22d70f9334
Codechange: Pass NewGRF ByteReader by reference. (#12786)
ByteReader must be present and not null, so don't use a pointer.
2024-06-15 10:55:26 +01:00
Peter Nelson 66044472d7 Codechange: Use std::unordered_map for NewGRF language_map.
NewGRFs only use a small subset of the available language IDs. Using an unordered_map allows only the reference languages to have space allocated.

This avoids manual new/delete of array.
2024-06-06 19:53:10 +01:00
Peter Nelson 579ce8eae0
Codefix: Find GRF override entries properly. (#12743)
My naive code from 16 years ago tested for GRF overrides in a way that will create empty 0 entries for each source GRF tested.
2024-06-04 18:06:19 +01:00
Peter Nelson 5fd23a2d70
Codechange: Pre-reserve vectors during NewGRF loading. (#12748)
Call reserve when we are given the number of elements up front. This reduces the number of reallocations and over-allocations done during loading.
2024-06-03 18:40:27 +01:00
Peter Nelson 96fc367bcf
Change: [NewGRF] Treat house max year 0xFFFF as MAX_YEAR. (#12740) 2024-06-01 12:54:49 +01:00
Peter Nelson 856ec901ca
Fix #12685: nullptr dereference when checking for equal loaded/loading groups. (#12686)
Always treat empty groups as non-equal. Given that the case of both being empty is handled earlier, they cannot both be equal and empty.

Additionally if a loaded or loading set are all the same, only add one reference.
2024-05-18 09:17:06 +01:00
Peter Nelson d5671030b1 Codechange: Add NewGRFSpecsBase class to hold class/index information.
Standardises how the class index is stored in the spec, instead of relying ot the Spec structs having the same members.

This allows retrieving class_index and index without searching or using pointer arithmetic.

'cls_id' is renamed to 'class_index' to make it clearer that it is an index rather than the multichar label of the class.
2024-05-11 02:12:41 +01:00
Peter Nelson cf96d49ced
Codechange: Use vector for airport tile layouts. (#12607)
Simplify AirportSpec data by storing layout information together in a vector, instead of separate arrays.

This removes manual memory management and separate count members.

The default layouts will be copied instead of always referring to the originals.
2024-05-02 11:37:54 +00:00
Peter Nelson f146680121
Codechange: Use vector for industry random sounds. (#12606)
Use a vector to store the list of random sounds played for an industry.

The removes manual memory allocation, flags to control memory management, a separate count member, and a try/catch block.
2024-05-01 19:55:00 +00:00
Peter Nelson 7147fe9e7a
Codechange: Use range-for when loading NewGRF deterministic sprite groups. (#12605) 2024-05-01 18:59:46 +00:00
Peter Nelson 1424a184d8
Codechange: Use vector/span when loading wagon overrides. (#12604)
Replaces manual memory allocation and passing pointer with size.
2024-05-01 18:23:27 +01:00
Peter Nelson 72c55128d2
Codechange: Remove write-only spec_id from RoadStopSpec. (#12582)
Comment is incorrect about its value too.
2024-04-26 21:56:30 +01:00
Peter Nelson d465257dd0
Fix 952d111: Houses and industry tiles could accept incorrect cargo. (#12547)
Default cargo label was not cleared (set to CT_INVALID) when using older 3-slot acceptance properties for house and industry tiles.

Missed in #12053 and #12062.
2024-04-21 19:46:05 +01:00
Peter Nelson 959ced71bb
Codechange: Add constants for original input/output cargo counts. (#12548)
This replaces some magic 3s and 2s.
2024-04-20 20:50:48 +01:00
Rubidium e441033d68 Codechange: use std::array instead of C-style array for produced/accepts cargo 2024-04-20 11:29:55 +02:00
Peter Nelson 1c31e4b68c
Change: Disallow using Action A to load sprites above the baseset unless reserved. (#12435)
Using Action A above the baseset is error prone as the sprites are not fixed and can be moved around.

Any NewGRF doing so is likely to break in the future, so force it to break instead.
2024-04-20 10:23:36 +01:00
Peter Nelson 052f421327 Change: Use vector/iterators/algorithms instead of C-array/loops for NewGRF classes. 2024-04-09 21:46:59 +01:00
Peter Nelson 34758d0921 Change: Allow string mapping by function instead of pointer.
This allows mapping of strings to objects that may be moved between loading stages.
2024-04-09 21:46:59 +01:00
Peter Nelson 2976a46d06
Fix 54be756: Terminating NUL byte was not skipped in ReadString(). (#12462) 2024-04-09 15:15:09 +01:00
Peter Nelson 54be756aae
Codechange: Pass NewGRF strings as std::string_view instead of char *. (#12461) 2024-04-09 08:40:27 +01:00
Peter Nelson 34ba969c74
Change: Display more useful information in sprite aligner than sprite ID. (#12439)
Sprite IDs are not useful information given they change don't refer to anything outside the loaded game.

Instead, include the filename and nfo line at minimum, and include action A or action 5 sprite replacement information if applicable.
2024-04-06 21:16:02 +01:00
Rubidium c544a2be0a Fix: do not use lengthof() for non C-style arrays 2024-04-06 07:21:31 +02:00
Peter Nelson e16b982b6a Codechange: Use iteration when dealing with all HouseSpecs. 2024-03-28 23:23:00 +01:00
Peter Nelson 88cf99017a
Fix #12302: Allow empty train engines to use an invalid cargo type. (#12325)
The cargo type will be forced to the first available type (usually passengers) instead of the engine being disabled.
2024-03-17 16:23:14 +00:00
Patric Stout a3cfd23cf9
Codechange: rename byte to uint8_t (#12308) 2024-03-16 23:59:32 +01:00
Peter Nelson 00b442d6f9
Fix: Maximum permitted sound volume from NewGRF is 128. (#12222) 2024-03-05 18:31:04 +00:00
Rubidium 4c117dd2d8 Revert #11993: new number format system does not and cannot work for CJK languages
There are too many intricacies that I am unaware of that are popping up after
asking whether things are right or not.
I do not want to keep playing whack-a-mole, so just revert the whole thing.

This reverts:
15be383b93
360fe8b0b6
1aa9a5c0ab
59f56941e5
7e2eefb91f
b741b2ba6f
609d0071d5
9f8fd80112
a253205b93
819c6c756e
2024-02-22 20:40:12 +01:00
Rubidium 15be383b93 Fix a253205: remove (now) unused currency separator 2024-02-18 16:56:52 +01:00
Peter Nelson 9ec9c8d8b5
Fix: Industry tiles and houses could accept incorrect cargo types. (#12062)
Ensure the default label is cleared when NewGRFs set industry tile or house acceptance.

This was missed by #12053.
2024-02-11 17:42:04 +00:00
Peter Nelson 8db08da148
Fix #12052: NewGRFs clearing industry cargo slots could fallback to default instead of empty. (#12053)
Ensure the default label is cleared when NewGRF sets a produced/accepted cargo slot, so that default fallback isn't used.
2024-02-11 00:43:13 +00:00
Peter Nelson ae30ad7802
Fix #12001: Use correct valid cargo check for old-style NewGRF town house 3rd cargo set up. (#12006) 2024-02-05 23:12:56 +00:00
Peter Nelson 5c630e10b7
Fix 2fd90960: Missing default vehicles and industry acceptance/production. (#12000)
* Fix 2fd90960: Missing default vehicles and industry acceptance/production.

Some default definitions are used across multiple climate types and relied on climate-independent cargo slot even though they specified a climate-dependent cargo type.

Add MixedCargoType that indirectly allows multiple labels to be specified for these.
2024-02-05 23:11:32 +00:00
Peter Nelson 2fd9096070
Change: Decouple and remove landscape-dependent cargo types. (#11719)
Cargo types of default engines, industries and houses are now specified in terms of label.
2024-02-04 10:16:08 +00:00
Peter Nelson 17d02ed45f
Feature: NewGRF properties to set town production effect and multiplier. (#11947)
Town production effect is modelled on town acceptance (growth) effect, and so takes an original cargo slot for behaviour instead of a direct value.

NewGRF feature 0x0B, property 0x1E, takes 1 byte.

Valid values are:
- 0x00 to behave like passengers
- 0x02 to behave like mail
- 0xFF to behave like other cargo (i.e. not produced.)

If not set, town production effect is set based on the cargo label ('PASS' or 'MAIL').

Town production multiplier allows adjusting the amount of cargo produces when Town Production Effect is set, without needing to use callbacks.

NewGRF feature 0x0B (cargo), property 0x1F, accepts a 2 byte (word) value, similar to the cargo capacity multiplier property. The default value is 256 which means 100%, i.e. normal rate.
2024-02-03 13:58:31 +00:00
frosch b1718478c8 Codechange: Replace old non-standard attributes with C++17/20 standard attributes. 2024-02-02 22:29:28 +01:00
Peter Nelson 8d69d0549d Codechange: Add town production effect type and assign to cargo types. 2024-02-02 20:37:49 +00:00
Peter Nelson 60dcf3b5e2 Codechange: Rename TownEffect to TownAcceptanceEffect.
This makes it clearer that TownEffect only affects acceptance behaviour.
2024-02-02 20:37:49 +00:00
Koen Bussemaker 5a55c4a934 Feature: [NewGRF] Allow higher max speeds for ships 2024-01-28 14:54:51 +01:00
Tyler Trahan 735abfe111
Codechange: Split dates and timers into Economy and Calendar time (#10700) 2024-01-22 09:04:34 -05:00
Peter Nelson c0ab436077
Codechange: Store Colours in Colours type. (#11625)
This reduces casts, some magic numbers, and introduces a bit of type-safety.
2024-01-21 13:23:04 +00:00
Peter Nelson 903119115b
Fix 9602de4: FinaliseCargoArray did nothing. (#11839)
`CargoSpec::Iterate()` deliberately skips invalid cargo types, but `FinaliseCargoCarry()` is only interested in them.
2024-01-19 20:07:47 +00:00
Peter Nelson 8f2266f0ed
Codechange: Use range-for when validating and finalising industries. (#11744) 2024-01-09 22:36:09 +00:00
Peter Nelson 97e2bc612c Codechange: Rename and move SpriteGroup-specific cargo types into a namespace.
These 'cargo types' have special defined uses and must not be used elsewhere. This makes it clearer that they are special.
2024-01-09 18:56:05 +00:00
Peter Nelson 952d111b94 Codechange: Split CT_INVALID into CT_INVALID and INVALID_CARGO.
INVALID_CARGO is a CargoID and should be used for most purposes in game.
CT_INVALID is a CargoType used for defining default properties.
2024-01-09 18:56:05 +00:00
Peter Nelson 33ff64ef74
Codechange: Simplify ConvertDateToYMD by returning YearMonthDay instead of outputting to a pointer. (#11637) 2023-12-28 21:34:08 +00:00
Peter Nelson e5aed24395
Codechange: Use std::array for industry tile cargo acceptance. (#11498)
This avoids use of memcpy/memset to copy or fill.
2023-11-27 23:17:55 +00:00
Tyler Trahan 235ac0bceb
Codechange: Reword rail/road type label constants (#11451) 2023-11-10 17:37:22 -05:00
Peter Nelson ab535c0a86
Codechange: Add base() method to StrongType to allow access to the base type without casting. (#11445)
This removes the ability to explicitly cast to the base type, but the requirement
to use .base() means the conversion is still explicit.
2023-11-06 20:29:35 +00:00
Rubidium c6411168d8 Cleanup: missing spaces before continuation * in some comments 2023-11-01 22:56:11 +01:00
Rubidium 37f84b7372 Codechange: replace x.size() != 0 with !x.empty() 2023-10-20 23:05:43 +02:00
Rubidium f16399f4c9 Codechange: replace x.size() > 0 with !x.empty() 2023-10-20 23:05:43 +02:00
Rubidium c9276c2959 Codechange: replace x.size() == 0 with x.empty() 2023-10-20 23:05:43 +02:00
Peter Nelson bc8e26f4e7
Codechange: Simplify usage of GRFFile cargo_map. (#11349) 2023-10-20 18:38:54 +01:00
Peter Nelson 9602de474d Codechange: Use iterators and/or range-for on cargo related loops. 2023-10-19 17:03:25 +01:00
Peter Nelson 5869f790d8
Fix: Check for engine variant loops during NewGRF initialization. (#11343)
Invalid NewGRFs could set up an engine variant loop that never ends. This
was checked for in some places that evaluated variants, but not all. In
most cases this would result in the engines not appearing, but could
potentially cause an infinite loop and crash.

Instead, during NewGRF initialization detect loops and remove invalid
variants before setting display flags.
2023-10-03 12:14:32 +01:00
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 2023-09-19 22:49:59 +02:00
PeterN acd7d3c913
Codechange: Rename *Railtype* to *RailType* for consistency. (#11287) 2023-09-11 08:55:12 +00:00
Tyler Trahan 77173a6a10 Codechange: Move date consts and functions to CalendarTime and TimerGameCalendar classes 2023-09-10 08:40:25 -04:00