Commit Graph

992 Commits

Author SHA1 Message Date
Tyler Trahan 930f0a16d8 Codechange: Define Date/Year/Month/Day within TimerGameCalendar class 2023-04-26 07:14:03 -04:00
Patric Stout 7aa2b9ab0a
Codechange: move all date-related variables inside the timer (#10706) 2023-04-24 15:56:01 +00:00
Rubidium 8f24901843 Codechange: replace printf with PRINTF macros by fmt::format for scripts 2023-04-24 17:51:25 +02:00
Rubidium 8b93e45e22 Codechange: use string/fmt instead of printf for squirrel's PRINTFUNC 2023-04-24 17:51:25 +02:00
SamuXarick f8b5661d28 Change: Allow GS access to ScriptGroup functions 2023-04-17 17:59:16 +02:00
SamuXarick f225f36c3d Change: Allow GS access to ScriptGameSettings.IsDisabledVehicleType 2023-04-17 17:59:16 +02:00
SamuXarick fd26a44c9e Change: Allow GS access to more ScriptCompany functions 2023-04-17 17:59:16 +02:00
Andy 8b1960a41c Change: Allow GS access to more ScriptOrder functions 2023-04-17 17:59:16 +02:00
PeterN e97bf271dc
Codechange: Make SpriteType, CargoSortType, SourceType and ScriptType enum classes. (#10663)
This avoids a (soft) namespace conflict between the four ST_* enums.
2023-04-16 20:00:55 +01:00
Patric Stout ed83c4b0da
Change: replace per-AI "start_date" with a global "competitors_interval" (#10653)
The per-AI "start_date" is a lot of custom code, and was rarely
used in the way it was meant.

While at it, also ported this part over to the new timer system.
2023-04-16 20:14:22 +02:00
Charles Pigott 6fc28d649e Cleanup: Unused alloca definitions and includes 2023-04-15 16:57:00 +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
Patric Stout 1ba4dcc924 Codechange: migrate all Window-related timers to the new framework
This means we also say goodbye to GUITimers.
2023-04-15 13:58:55 +02:00
Peter Nelson e5af5907ec Change: Make all dropdown lists extend width if necessary.
This removes the auto_width parameter from ShowDropDown(At).
2023-04-13 20:57:47 +01:00
dP e2f1cd44dc
Change: Increase max cargo age and let min cargo payment approach zero. (#10596)
Co-authored-by: Michael Lutz <michi@icosahedron.de>
2023-04-10 12:34:28 +02:00
glx22 3a48d6e60f Fix 991a797: [Script] Allow STRINGN consumption to be different than expected 2023-04-08 00:14:12 +02:00
Loïc Guilloux e4c511d403
Fix #10578: Allow to select any version of AI/GS from GUI (#10604) 2023-04-07 19:33:07 +02:00
Peter Nelson 82c70ed3b8 Change: Expose ObjectSpec vector to simplify iteration. 2023-04-02 22:42:38 +01:00
Peter Nelson 1f46f080f0 Codechange: Store objectspecs in std::vector instead of flat array. 2023-04-02 22:42:38 +01:00
Loïc Guilloux 9642e87bc8
Fix: [Script] Access to enum/consts defined outside of main.nut (#10573) 2023-03-25 23:07:47 +01:00
PeterN 2d3250923c
Fix #10554: Let Scrollbar::SetPosition clamp instead of assert. (#10555) 2023-03-09 10:19:58 -05:00
Rubidium 1e4a89177e Fix: crashes to desktop from game scripts when companies disappear
When a game script is in company mode, it pretends to be another company. When
that company disappear (bankruptcy/merger), the game script still uses that
company and it keeps calling functions as if it is that company.

For example, ScriptEngine::IsBuildable internally dereferences Company without
checks, causing a null dereference for any ScriptEngine function when called
from a company scope of a company that has disappeared.

Guard against this by extending the ScriptCompanyScope::IsValid check to also
check for the company still being active.
2023-03-08 22:33:47 +01:00
Rubidium 717f79ff22 Add: deity mode enforcement checks to functions with command or company access
Command functions are those that call ScriptObject::Command, and functions
with company access are any that call ScriptObject::GetCompany. This is a bit
over-protective, but having the check everywhere makes it easier to validate
that no check is missing automatically instead of by review.
2023-03-08 22:33:47 +01:00
Rubidium 8d443d1379 Add: company mode enforcement checks to functions with command or company access
Command functions are those that call ScriptObject::Command, and functions
with company access are any that call ScriptObject::GetCompany. This is a bit
over-protective, but having the check everywhere makes it easier to validate
that no check is missing automatically instead of by review.
2023-03-08 22:33:47 +01:00
Rubidium 534f2419ad Add: precondition checks to functions that work with both valid company and deity
These are functions that either use ScriptObject::Command or ScriptObject::GetCompany.
This is a bit over-protective, but having the check everywhere makes it easier to
validate that no check is missing automatically instead of by review.

At this moment these checks will not do anything useful, as either IsValid or
IsDeity from ScriptCompanyMode returns true, but that will change later.
2023-03-08 22:33:47 +01:00
Rubidium a79f97c022 Change: upon an invalid company mode, set ERR_PRECONDITION_INVALID_COMPANY instead of ERR_PRECONDITION_INVALID 2023-03-08 22:33:47 +01:00
Rubidium 3287acd114 Fix 13528bfcd0: bank balance command allows int64, GS was limited to int32 2023-03-07 23:20:04 +01:00
Rubidium 83946ca31d Codechange: use GSCompanyMode::IsValid, IsDeity, and the precondition helpers
Direct 1:1 replacements in the code, and comments now refer to either
GSCompanyMode::IsValid or GSCompanyMode::IsDeity instead of several variations
on "company mode active" or "no company mode active".
2023-03-06 22:34:09 +01:00
Rubidium cada2ca310 Add: GSCompanyMode::IsValid and IsDeity, and precondition enforcement helpers 2023-03-06 22:34:09 +01:00
glx22 ca149447d7 Codechange: Use SQInteger for generic numbers in script_window 2023-03-06 00:32:12 +01:00
glx22 f752d96125 Codechange: Use SQInteger for generic numbers in script_vehicle 2023-03-06 00:32:12 +01:00
glx22 4e48bf2e16 Codechange: Use SQInteger for generic numbers in script_town 2023-03-06 00:32:12 +01:00
glx22 18fe0a4046 Codechange: Use SQInteger for generic numbers in script_tilelist 2023-03-06 00:32:12 +01:00
glx22 cada18a6f8 Codechange: Use SQInteger for generic numbers in script_tile 2023-03-06 00:32:12 +01:00
glx22 07b73a8c02 Codechange: Use SQInteger for generic numbers in script_subsidy 2023-03-06 00:32:12 +01:00
glx22 cd80b31d19 Codechange: Use SQInteger for generic numbers in script_storypage 2023-03-06 00:32:12 +01:00
glx22 a9a55f2153 Codechange: Use SQInteger for generic numbers in script_station 2023-03-06 00:32:12 +01:00
glx22 446ebaa6b9 Codechange: Use SQInteger for generic numbers in script_road 2023-03-06 00:32:12 +01:00
glx22 4f6a2f31b5 Codechange: Use SQInteger for generic numbers in script_rail 2023-03-06 00:32:12 +01:00
glx22 cb2e76aae3 Codechange: Use SQInteger for generic numbers in script_priorityqueue 2023-03-06 00:32:12 +01:00
glx22 777b4d0987 Codechange: Use SQInteger for generic numbers in script_order 2023-03-06 00:32:12 +01:00
glx22 49ea69fdef Codechange: Use SQInteger for generic numbers in script_objecttype 2023-03-06 00:32:12 +01:00
glx22 0293fd41e5 Codechange: Use SQInteger for generic numbers in script_news 2023-03-06 00:32:12 +01:00
glx22 f22903ab14 Codechange: Use SQInteger for generic numbers in script_newgrf 2023-03-06 00:32:12 +01:00
glx22 ca67075397 Codechange: Use SQInteger for generic numbers in script_map 2023-03-06 00:32:12 +01:00
glx22 a225fda9fe Codechange: Use SQInteger for generic numbers in script_list 2023-03-06 00:32:12 +01:00
glx22 74ab9ee9dd Codechange: Use SQInteger for generic numbers in script_league 2023-03-06 00:32:12 +01:00
glx22 367b2ba6d1 Codechange: Use SQInteger for generic numbers in script_infrastructure 2023-03-06 00:32:12 +01:00
glx22 5eaf9d39bf Codechange: Use SQInteger for generic numbers in script_industrytype 2023-03-06 00:32:12 +01:00
glx22 6671994655 Codechange: Use SQInteger for generic numbers in script_industry 2023-03-06 00:32:12 +01:00
glx22 8eb35633ec Codechange: Use SQInteger for generic numbers in script_group 2023-03-06 00:32:12 +01:00
glx22 6ca8499e6a Codechange: Use SQInteger for generic numbers in script_goal 2023-03-06 00:32:12 +01:00
glx22 e784915b27 Codechange: Use SQInteger for generic numbers in script_gamesettings 2023-03-06 00:32:12 +01:00
glx22 6b8b4c392f Codechange: Use SQInteger for generic numbers in script_engine 2023-03-06 00:32:12 +01:00
glx22 2f40bf8097 Codechange: Use SQInteger for generic numbers in script_date 2023-03-06 00:32:12 +01:00
glx22 424ae74504 Codechange: Use SQInteger for generic numbers in script_companymode 2023-03-06 00:32:12 +01:00
glx22 89c0841d0a Codechange: Use SQInteger for generic numbers in script_company 2023-03-06 00:32:12 +01:00
glx22 7727323dbe Codechange: Use SQInteger for generic numbers in script_cargomonitor 2023-03-06 00:32:12 +01:00
glx22 40424601c6 Codechange: Use SQInteger for generic numbers in script_cargo 2023-03-06 00:32:12 +01:00
glx22 83826b1793 Codechange: Use SQInteger for generic numbers in script_bridgelist 2023-03-06 00:32:12 +01:00
glx22 58bf2f7176 Codechange: Use SQInteger for generic numbers in script_bridge 2023-03-06 00:32:12 +01:00
glx22 73561802cb Codechange: Use SQInteger for generic numbers in script_airport 2023-03-06 00:32:12 +01:00
glx22 b6f3552e4b Fix: [Script] Inconsistent precondition failure return values 2023-03-06 00:32:12 +01:00
glx22 e06a666fa2 Fix: remove ScriptController constructor from API documentation 2023-03-06 00:32:12 +01:00
glx22 67a4c5e0db Codechange: Use {fmt} for script_admin JSON generation 2023-03-06 00:32:12 +01:00
glx22 ce8cde3b8d Fix: [Script] Detect circular references in ScriptText 2023-03-05 22:24:08 +01:00
glx22 9a957f1d4b Change: [Script] Improve ScriptText validation error messages 2023-03-05 22:24:08 +01:00
glx22 991a797e09 Change: [Script] Validate ScriptText parameters type and amount 2023-02-28 18:53:17 +01:00
Rubidium 728973859d Change: [Script] Automate the ScriptObject reference counting 2023-02-28 18:53:17 +01:00
glx22 a1fc4d5c0e Codechange: [Script] Merge the 3 ScriptText param arrays 2023-02-28 18:53:17 +01:00
Rubidium 580d0a6343 Codechange: make use of Tile in for all direct map accesses 2023-02-28 07:11:48 +01:00
Jonathan G Rennison 4c1406a4b5 Add: NewGRF road stops 2023-02-26 21:28:30 +01:00
dP c73b88ddca
Fix: Don't send unused tile field over the network (#10507) 2023-02-24 22:50:11 +01:00
Michael Lutz 9b3326e3fd Codechange: [Script] Use std::vector instead of a hand-rolled alternative. 2023-02-24 21:46:27 +01:00
Michael Lutz ca3cb4d2ef Codechange: [Script] Use a class template instead of a function template for squirrel type conversion.
Class templates allow using partial template specialization, which is useful in
case one wants to have a type conversion on a type that is itself templated.
2023-02-24 21:46:27 +01:00
SamuXarick 8351b97f52 Add: [Script] Labels for negative values of a setting 2023-02-21 00:28:21 +01:00
SamuXarick 376820c0b6 Doc: [Script] Update info descriptions 2023-02-21 00:28:21 +01:00
SamuXarick bb2ac8b3c4 Fix: [Script] Save config item values up to 10 digits + 1 for sign + 1 for termination, enough to fit min and max int 2023-02-21 00:28:21 +01:00
SamuXarick fde7028a95 Fix #10059: [Script] Let custom values on a config item be up to 10 digits + 1 for sign 2023-02-21 00:28:21 +01:00
SamuXarick 7b1fd3e37f Fix #10059: [Script] Clamp config item values to int32
Also prevent random_deviation to be below 0.
2023-02-21 00:28:21 +01:00
SamuXarick 3df9321a65 Fix: Some Script::IsValidVehicle checks need to be complemented with IsPrimaryVehicle
Add: [Script] ScriptVehicle.IsPrimaryVehicle
2023-02-18 09:58:02 +01:00
glx22 3559576166 Codechange: [Script] Don't expose static buffers outside of ScriptText 2023-02-17 21:28:14 +01:00
glx22 e735370318 Change: [Script] A ScriptText with too many parameters is now a fatal error
It should never happen as adding/setting parameters already checks that anyway.
2023-02-17 21:28:14 +01:00
dP fe2c8a1240
Codechange: Decouple INDUSTRY_CTRL into separate commands (#10475) 2023-02-14 11:29:11 +01:00
SamuXarick 43ce73db86 Fix: [Script] Use Money instead of int32 for presenting the value of a company to AIs 2023-02-11 09:43:47 +01:00
Loïc Guilloux 6b99b6672e
Fix: [Script] ScriptBase::Rand() return value was between -MIN(int32) and MAX(int32) (#10443)
Also ensure the parameters for ScriptBase::RandRange() and ScriptBase::Chance() are in [0-MAX(uint32)] range
2023-02-10 19:55:59 +01:00
glx22 b080f24bd8 Codechange: move windows common to AI and GS out of ai_gui 2023-02-05 19:27:25 +01:00
SamuXarick 1f194eb94e
Fix: [Script] Incorrect value for GOAL_INVALID (#10436)
* Fix: [Script] Incorrect value for GOAL_INVALID

* Cleanup: Remove unused static variable
2023-02-01 23:35:51 +01:00
SamuXarick d0639cdc28 Fix: [Script] Incorrect subsidy SourceID value used 2023-02-01 21:17:16 +01:00
SamuXarick 4fc4874a30 Add: [Script] Let random road layout be a choice 2023-02-01 21:15:13 +01:00
SamuXarick 184ff92057
Cleanup: [Script] Pass new_rating directly to CmdTownRating (#10441) 2023-02-01 13:48:39 -05:00
Rubidium 31869501ee Fix: make script goals work with the whole range of ClientIDs 2023-01-31 20:09:48 +01:00
Loïc Guilloux 07b40c02fe
Fix #10361, fe30f66: Don't try to give saved data to a dead script (#10433) 2023-01-29 22:27:29 +00:00
Rubidium 4e65ec1dc4 Codechange: do not declare functions in blocks 2023-01-29 20:28:45 +01:00
Rubidium 2fd99467ea Fix: scripts are not aware of nullptr, they only know null 2023-01-26 16:07:14 +01:00
Rubidium f9a473bef7 Fix: missing/duplicate documentation tags for scripts 2023-01-26 16:07:14 +01:00
Rubidium 3112b387e7 Fix: warnings about obsolete settings/setting values in Doxygen configurations 2023-01-26 16:07:14 +01:00
Rubidium 41fa94bc56 Fix: scripts cannot call constructors of ScriptEvents, so remove from the documentation 2023-01-25 22:28:30 +01:00
Rubidium fe2bcd2a58 Codechange: migrate size related functions to Map structure 2023-01-21 17:11:40 +01:00
Rubidium 22d3de8b67 Codechange: use ScriptMap size functions instead of global functions 2023-01-21 17:11:40 +01:00
Rubidium 921c6591f9 Codechange: do not use interactive random anymore for script configuration 2023-01-14 22:00:11 +01:00
Rubidium c5ff61c5f2 Add: script specific Randomizer instances 2023-01-14 22:00:11 +01:00
Rubidium 6abad681bd Codechange: move choice for randomizer of scripts to a single location 2023-01-14 22:00:11 +01:00
Rubidium 3373128233 Codechange: pass the randomizer directly to the town name generation 2023-01-14 22:00:11 +01:00
Rubidium b3b8c3fd2d Codechange: pass the randomizer to use directly to the company face generation 2023-01-14 22:00:11 +01:00
Rubidium 90f1768006 Codechange: add non-nullptr asserts in cases where it should never be nullptr
Though where similar calls are checked for nullptr as in those instances of
the use of that function it can actually return nullptr. In other words, write
down the assumption that the function never returns nullptr in an assert.
2023-01-14 21:15:23 +01:00
Jonathan G Rennison 10e76b2788 Fix #10032: Capacities of articulated vehicles in build window
See also: #9954
2023-01-14 18:52:01 +01:00
Tyler Trahan 5c64cdcb79
Feature: Press Ctrl to build a diagonal area of trees (#10342) 2023-01-13 18:04:30 -05:00
Rubidium 170f37d07f Codechange: silence some potentially uninitialized local variable errors
In these cases technically they are false positives, however dismissing the
alerts when the underlying code may make them true positives does not seem
like the safest solution.
2023-01-06 19:34:35 +01:00
Michael Lutz 150f05dc15
Change: Heading for 14 now. (#10302) 2023-01-01 22:52:23 +01:00
Loïc Guilloux fe30f66570
Fix #9720: Delay start of GS/AI to after loading of savegame (#9745) 2022-12-28 05:02:26 +01:00
Loïc Guilloux c179c10048
Fix #10263, ccefa76: [scripts] restore tile validation for commands (#10269) 2022-12-21 02:37:59 +01:00
Michael Lutz 1c205b2cda Fix #10212: [Script] Nested ScriptAccounting scopes are not restored properly. 2022-12-04 11:27:24 +01:00
dP 5e14a20b3b
Feature: [GS] Scriptable league tables (#10001) 2022-11-26 18:03:03 +01:00
Peter Nelson f5f035a22b Codechange: Make use of Rect Width/Height helpers. 2022-11-12 18:28:39 +00:00
Joel-Milligan 59645c6733
Change: Remove scrollbar from town authority actions panel (#9928) 2022-11-11 23:52:38 +01:00
Henry Wilson 89cf0d5da8 Codechange: Factor cargotype weight conversion magic numbers 2022-11-08 21:02:08 +01:00
Loïc Guilloux 0afa6f2424
Codechange: [CMake] Auto-fill list of #include in script_window.hpp (#10103) 2022-10-24 12:35:58 +02:00
Nicolas Chappe a9a21e784d Codechange: Always set the ODATFB_NEAREST_DEPOT flag for 'any depot' orders 2022-10-22 14:19:08 +02:00
SamuXarick 8d0d45c431 Add: ScriptCargo::GetWeight to get cargo weights 2022-10-16 18:28:28 +02:00
SamuXarick 3dda8c9bad Fix: ScriptRoad::HasRoadType really check for RoadType
Script::HasRoadType was only checking if the tile had the same RoadTramType as that of the RoadType provided.
Now it really checks RoadType against RoadType.
2022-10-16 18:27:23 +02:00
Tyler Trahan db98cedb7e Fix #9883: Show cost/income float over end tile of rail or road construction 2022-10-16 14:15:31 +02:00
Charles Pigott 9059215b3b Fix #10073: Stop truncating output of list_ai and friends commands 2022-10-10 13:42:07 +01:00
glx22 675cf7a8ee Fix 6fe445e: [Script] Respect joining adjacent when building an airport 2022-05-31 23:14:47 +02:00
glx22 ed1457dca3 Fix 55170ae: [Script] Building two-way signals could end up one-way 2022-05-27 19:57:50 +02:00
Loïc Guilloux 7331149dde
Codechange: [CMake] Pass API files list via a file to minimise command line length (#9874) 2022-05-01 00:39:59 +02:00
Tyler Trahan f4ca94d3f6 Codechange: Revenue is not the same as Income
Income is revenue minus costs. Let's name things correctly (without breaking the script API).
2022-04-25 21:51:51 +02:00
Niels Martin Hansen e68bf58989 Codechange: Use anonymous union for vehicle orders/old orders list 2022-02-15 20:01:10 +01:00
Andy b8a8891a86 Add: [Script] IndustryType::ResolveNewGRFID to resolve industry id from grfid and grf_local_id 2022-01-22 18:15:12 +01:00
Andy 26ac0c48f0 Add: [Script] ObjectType::ResolveNewGRFID to resolve object id from grfid and grf_local_id 2022-01-22 13:12:10 +01:00
Michael Lutz 3fede15940 Codechange: [Script] Prettify squirrel call helpers by using C++17. 2021-12-20 19:25:10 +01:00
Michael Lutz 41fa16f325 Codechange: Don't use globals for return values from vehicle command procs. 2021-12-16 22:28:32 +01:00
Michael Lutz 57b82e2e99 Codechange: Don't use globals for story/goal/sign/group command proc return values. 2021-12-16 22:28:32 +01:00
Michael Lutz 3e85e833a7 Codechange: Add support for additional command result values. 2021-12-16 22:28:32 +01:00
Michael Lutz 8503854655 Codechange: Pass unpacked command arguments to command callbacks (except Script). 2021-12-16 22:28:32 +01:00
Michael Lutz 13528bfcd0 Codechange: Un-bitstuff all remaining commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 58cff7b081 Codechange: Un-bitstuff the remaining on-map commands. 2021-12-16 22:28:32 +01:00
Michael Lutz c6d7b98808 Codechange: Un-bitstuff landscape commands. 2021-12-16 22:28:32 +01:00
Michael Lutz e6e69d5289 Codechange: Un-bitstuff goal and story page commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 1a42a8a5d5 Codechange: Un-bitstuff town-related commands. 2021-12-16 22:28:32 +01:00
Michael Lutz e08b3abe7f Codechange: Un-bitstuff group and autoreplace commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 46bd2f1ced Codechange: Un-bitstuff remaining transport infrastructure commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 55170ae703 Codechange: Un-bitstuff rail commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 6fe445e6c0 Codechange: Un-bitstuff station/depot/waypoint commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 21675ec7e2 Codechange: Un-bitstuff vehicle/engine commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 211c630cbe Codechange: Un-bitstuff order commands. 2021-12-16 22:28:32 +01:00
Michael Lutz 4f3ea3907e Codechange: Un-bitstuff commands taking a ClientID (i.e. CMD_CLIENT_ID). 2021-12-16 22:28:32 +01:00
Michael Lutz ccefa76a46 Codechange: Template DoCommandPInternal. 2021-12-16 22:28:32 +01:00
Michael Lutz 6691ee3b96 Codechange: Template script command calls. 2021-12-16 22:28:32 +01:00
Michael Lutz eab18f06a4 Codechange: Pass additional data as byte stream to command callbacks. 2021-12-16 22:28:32 +01:00
Michael Lutz e740c24eb7 Codechange: Template DoCommand to automagically reflect the parameters of the command proc.
When finished, this will allow each command handler to take individually
different parameters, obliviating the need for bit-packing.
2021-12-16 22:28:32 +01:00
Michael Lutz b0990fcff7 Codechange: Make TileIndex a "strong" typedef to give it a distinct type.
This is accomplished by changing it to a single member struct with the
appropriate operator overloads to make it all work with not too much
source modifications.
2021-12-16 22:28:32 +01:00
Michael Lutz 123c7f99c3 Codechange: Move command callback declarations to the cmd header files. 2021-12-16 22:28:32 +01:00
Michael Lutz a38bbefe1b Codechange: Untangle command code, flags and error string for DoCommand*. 2021-12-16 22:28:32 +01:00
Michael Lutz 549caca39c Codechange: Move command arguments to the back of the networked command function calls. 2021-12-16 22:28:32 +01:00
Michael Lutz b6933a2ebd Codechange: Move command arguments to the back of the DoCommand function call. 2021-12-16 22:28:32 +01:00
Loïc Guilloux eed49d7792
Fix #9626, ddafc0d: Incorrect loading of script saved data (#9629) 2021-10-20 12:23:16 +02:00
Loïc Guilloux a53cfeef13
Fix #9548, e5fedcd: [Squirrel] Crash during engine cleanup after reaching memory limit on realloc (#9592) 2021-10-02 21:08:42 +02:00
Loïc Guilloux ccd586a736
Fix #9588, 140a96b: [Squirrel] Reaching memory limit during script registration could prevent further script detections (#9589)
Also the memory allocation triggering the limit was never freed.
And if the exception was thrown in a constructor using placement new, the pre-allocated memory was not freed either.
2021-10-02 15:13:58 +02:00
Patric Stout 394c749b6b
Change: Heading for 13 now (#9573) 2021-09-25 13:48:03 +02:00
dP 39662aabef
Add: allow gamescripts to build neutral objects (#9568) 2021-09-25 13:39:40 +02:00
SamuXarick 37de878129
Feature: [AI/GS] Missing water related functions and objects (#8390) 2021-09-14 22:06:55 +02:00
Patric Stout eca73a810c Change: rebrand 1.12.0 to 12.0
One question that keeps popping up: "when do we release 2.0?".
NewGRF will force that at least 1.16 will be 2.0, but to not wait
for this, let's drop the "1." and be for ever done with that
conversation.

We are following in the footstep of giants here.
2021-08-15 12:28:51 +02:00
SamuXarick 120d216b0b
Add: [AI] Get the number of vehicles in a given group (#9462) 2021-08-12 21:29:03 +02:00
Michael Lutz b14681891d Fix 8706dcd9: [Script] Byte-swap grfids to match normal expectations. 2021-08-10 21:35:17 +02:00
Loïc Guilloux 4eb368c786
Fix 14f197c: [Script] int64 values don't fit into int (#9465) 2021-08-10 19:00:54 +02:00
Michael Lutz 8706dcd9c1
Add: [Script] Basic information about loaded NewGRFs for scripts. (#9464)
Currently, scripts use various heuristics to detect loaded NewGRFs that are inherently unreliable.
The list of loaded NewGRFs is easily accessible to a human player, and thus giving
scripts the same information is consistent with the current approach to not give scripts
more information than a human player.
2021-08-09 23:34:50 +02:00
Charles Pigott 549a58731f Codechange: Remove (unused) ability to specify min/max of OverflowSafeInt 2021-07-20 10:42:03 +01:00
Rubidium 01139d3368 Codechange: access the name of a setting via an accessor function 2021-07-09 22:53:30 +02:00
Loïc Guilloux ddafc0de05
Fix 39e90ec: Integers for scripts are 64bit, but saved as 32bit (#9415) 2021-07-06 21:09:08 +02:00
Patric Stout 7dd5fd6ed4 Feature: framework to make savegames self-descriptive
We won't be able to make it fully self-descriptive (looking at you
MAP-chunks), but anything else can. With this framework, we can
add headers for each chunk explaining how each chunk looks like
in detail.

They also will all be tables, making it a lot easier to read in
external tooling, and opening the way to consider a database
(like SQLite) to use as savegame format.

Lastly, with the headers in the savegame, you can freely add
fields without needing a savegame version bump; older versions
of OpenTTD will simply ignore the new field. This also means
we can remove all the SLE_CONDNULL, as they are irrelevant.

The next few commits will start using this framework.
2021-07-02 22:21:58 +02:00
Rubidium 281a65b3e1 Cleanup: simplify some boolean expressions 2021-06-17 16:18:30 +02:00
Rubidium 3237e97b35 Cleanup: [Script] Use nullptr instead of 0 or NULL 2021-06-17 16:18:30 +02:00
Patric Stout 97b94bdc9a Change: prefix SL_ARR with the length of the array
This means that during loading we can validate that what is saved
is also that what is expected. Additionally, this makes all list
types similar to how they are stored on disk:
First a gamma to indicate length, followed by the data.
The size still depends on the type.
2021-06-15 16:45:04 +02:00
Rubidium d31a535c87 Cleanup: remove some unneeded c_str() calls 2021-06-15 06:13:00 +02:00
rubidium42 55a11710a6 Codechange: convert printf DEBUG statements to fmt Debug statements 2021-06-13 12:45:45 +02:00
rubidium42 bf500c39c9 Codechange: make the name of SettingDesc a std::string 2021-06-13 10:26:58 +02:00
rubidium42 71f3c35288 Fix #9353: [Script] Garbage collecting on priority queues could crash the game 2021-06-12 19:58:14 +02:00
Loïc Guilloux 16ebf7861f
Fix 4079c47: Missed a file when removing generated .sq files from the repo (#9350) 2021-06-11 16:59:19 +02:00
Loïc Guilloux ee5f23382d
Fix: [Script] doxygen_filter is very strict about DOXYGEN_API usage (#9351) 2021-06-11 16:40:04 +02:00
rubidium42 2924ac48c5 Fix: [Script] Ensure the saved script strings are properly validated and terminated when being read from the savegame 2021-06-10 22:03:23 +02:00
Patric Stout 648ee88a02 Codechange: merge guiflags and flags in settings .ini files
It was rather confusing which one was for what, especially as some
SaveLoad flags were settings-only. Clean up this mess a bit by
having only Setting flags.
2021-06-06 21:45:01 +02:00
Patric Stout 28e90769f7 Codechange: use "[[maybe_unused]]" instead of a wide variety of other ways we had
While at it, replace OTTD_ASSERT with WITH_ASSERT, as this
is always set if assert() is valid. No matter if NDEBUG is set
or not.
2021-06-03 17:30:00 +02:00
Patric Stout 9fff00ba20
Codechange: C++-ify lists for SaveLoad (#9323)
Basically, this changes "SaveLoad *" to either:
1) "SaveLoadTable" if a list of SaveLoads was meant
2) "SaveLoad &" if a single entry was meant

As added bonus, this removes SL_END / SLE_END / SLEG_END. This
also adds core/span.hpp, a "std::span"-lite.
2021-05-31 22:26:44 +02:00
Patric Stout 921ab68a48
Codechange: use AsIntSetting()->Read() wrapper if possible (#9324) 2021-05-31 10:56:06 +02:00
rubidium42 e58581f1f8 Codechange: [Network] Let admin-game script use std::string 2021-05-30 10:15:22 +02:00
rubidium42 29f2bd27c4 Codechange: [Game] Pass the length instead of '\0' terminating (and undoing that) in the middle of a C-string 2021-05-30 10:15:22 +02:00
Patric Stout d70fb74ac6
Codechange: use setting name instead of index for CmdChange(Company)Setting (#9306)
This is mostly done as there are now constraints on settings.ini you might not
expected. For example, conditional settings always have to come last, as otherwise
they would influence the index.
2021-05-29 23:27:01 +02:00
glx22 5799402f7a Codechange: Rename window related DeleteXXX to match new behaviour 2021-05-29 21:08:25 +02:00
rubidium42 2e136285e1 Codechange: move from C-string to std::string for DoCommand 2021-05-29 19:02:18 +02:00
Patric Stout 7713c3e3cc Codechange: move casting a "const char *" to "char *" to the caller
It is not nice to have your definition say you won't change a value
while in fact the whole reason for your existance is to change it.
2021-05-29 16:23:59 +02:00
Patric Stout 665e3c1f45 Fix: ScriptObject::DoCommand could modify "text" while defined "const"
This could have unwanted side-effects, as it could change the
source for ever and ever.
2021-05-29 16:23:59 +02: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 86c9ef8134 Codechange: remove SettingDescType in lieu of the actual classes 2021-05-27 18:49:43 +02:00
rubidium42 425d50372f Codechange: let SettingDesc extend SettingDescBase 2021-05-27 18:49:43 +02:00
rubidium42 8ffb4122df Codechange: just pass the SettingDesc to SetSettingValue and remove distinction between (non)company 2021-05-27 18:49:43 +02:00
rubidium42 4d246cda73 Codechange: [Network] Let NetworkClientInfo use std::string 2021-05-16 10:07:51 +02:00
rubidium42 44ca7d9377 Change: Use gender-neutral pronouns 2021-05-15 10:16:48 +02:00
rubidium42 0f062b3882 Codechange: clean up C-string support from settings 2021-05-13 23:13:17 +02:00
rubidium42 a032714dc4 Codechange: move script settings to std::string 2021-05-13 23:13:17 +02:00
Rubidium 7755f81bb8 Codechange: make explicit that virtual functions in a con/destructor are resolved statically
This as during construction the sub class has not been initialized yet, and
during destruction the sub class has already been destroyed, so the overriding
virtual function would be accessing uninitialized data.
2021-05-13 10:03:26 +02:00
glx22 38c97e1492 Codechange: Replace TILE_AREA_LOOP with range-based for loops 2021-05-13 00:13:54 +02:00
William Davis 881e1da51d
Change: Use gender-neutral pronouns in console command messages (and comments) (#9203) 2021-05-08 11:02:30 +01:00
glx22 983c7ade60 Codechange: Replace FOR_ALL_SEARCHPATHS with range-based for loops 2021-05-03 19:46:57 +02:00
glx22 34215f7faa Codechange: Replace FOR_ALL_TARS with range-based for loops 2021-05-03 19:46:57 +02:00
glx22 9a8756d7ed Codechange: Replace FOR_ALL_CARGOSPECS with range-based for loops 2021-04-29 21:08:24 +02:00
Loïc Guilloux 356bbbb90a
Fix: [MinGW] Set minimum OS version to Windows XP (#9135) 2021-04-29 14:26:08 +02:00
peter1138 c56fce70b4 Codechange: Replace CMD_SET_GROUP_REPLACE_PROTECTION with generic CMD_SET_GROUP_FLAG. 2021-04-22 22:57:00 +02:00
peter1138 27a956ba62 Codechange: Replace Group::replace_protection with Group::flags 2021-04-22 22:57:00 +02:00
Rubidium e5fedcd6da Fix #6322: [Script] Try to let the script die when no memory can be allocated instead of crashing the whole game 2021-04-17 22:24:52 +02:00
Rubidium 4400bbfa96 Change: [Script] Let Script_FatalError use std::string instead of const char * 2021-04-17 22:24:52 +02:00
Patric Stout 9bfa7198fd
Change: Heading for 1.12 now (#8862) 2021-03-14 20:47:31 +01:00
Patric Stout 9a3dbf3122
Fix 02e770ff: allow estimating CloneVehicle if short on money (#8748)
CheckCompanyHasMoney() was also executed when not using DC_EXEC,
resulting in an error about shortage of money instead of the
estimation.
This mostly is a problem for AI players, as they will have no
way to know how much it would have cost.
2021-02-26 16:22:58 +01:00
dP 91cc414588 Feature: [GS] Allow non-question type windows to have no buttons 2021-02-14 23:21:43 +01:00
dP bab7de6cf2 Feature: Allow GameScripts to add additional text to Industry view window 2021-01-22 09:50:53 +00:00
Pavel Stupnikov 4b42ecb0f6
Feature: Add tile parameter for GSCompany.ChangeBankBalance to show text effect if needed (#8573) 2021-01-22 10:28:26 +01:00
SamuXarick 6298d9221a Fix 218f40e: Warning about 32-bit shift implicitly converted to 64 bits 2021-01-10 22:31:01 +01:00
Patric Stout 218f40eea2
Add: [Script] ScriptCargo::GetName, to get the human readable name of a cargo (#8544)
Of course this translates into AICargo.GetName() for AIs and
GSCargo.GetName() for GameScripts.
2021-01-09 15:15:14 +01:00
Charles Pigott 9b800a96ed
Codechange: Remove min/max functions in favour of STL variants (#8502) 2021-01-08 11:16:18 +01:00
glx22 f7e48cac87 Fix #8453: [Script] Don't truncate loan variation to 32bit 2020-12-28 16:51:15 +01:00
SamuXarick dc5b8020cc
Fix #6452: Reset only editable and visible settings from GUI (#7890)
Also enables the Reset button while in-game for AI configs.
2020-12-27 15:05:47 +01:00
Michael Lutz b408fe77f7 Codechange: Use std::string in file scanners. 2020-12-27 13:19:25 +01:00
Michael Lutz 65f65ad2ad Codechange: Convert some more FIO functions to take std::string. 2020-12-27 13:19:25 +01:00
Michael Lutz f3326d34e7 Codechange: Use std::string in FIO search path handling. 2020-12-27 13:19:25 +01:00
glx22 d8605ad18d Codechange: Replace FOR_VEHICLE_ORDERS with range-based for loops 2020-12-27 10:28:46 +00:00
Patric Stout f66baa444f
Codechange: use C++11 constructs for for-each loops (#8432) 2020-12-25 19:38:18 +01:00
Patric Stout 29e3331055 Codechange: move block a bit lower to increase readability
It was rather confusing that "library_name" was calculated, and
then not used to do the FindLibrary() call. Flipping those two
blocks around makes it a bit more sane to read.
2020-12-25 17:03:44 +01:00
Patric Stout 8c0e4ab07f
Doc: for over 10 years now, we do not load the exact AI version first (#8431)
See commit fae34ee7 for details. The documentation simply never
got updated.
2020-12-25 17:03:31 +01:00
Pavel Stupnikov 9a45a0f535
Feature: Set exclusive access to industry from GS (#8115) 2020-12-22 14:29:48 +01:00
Niels Martin Hansen b7751c483e
Feature: Influence industry production changes from GS (#7912) 2020-12-22 14:21:31 +01:00
glx22 d1fa6b129c Add: [CMake] Option to only build tools/docs 2020-12-13 22:46:46 +01:00
glx22 6fae0b83d9 Add: [CMake] targets to generate documentation 2020-12-12 15:48:04 +01:00
Rasmus Jonsson 0b2dd2c5cd Fix: [NoAI] don't notify caught exceptions 2020-12-02 17:11:36 +00:00
Charles Pigott 348c231e12 Codechange: Make codestyle for CMake files consistent for 'control' statements 2020-09-25 14:43:13 +01:00
glx 4079c47b6c Change: rewrote squirrel_export in CMake 2020-07-16 00:53:26 +02:00
glx 8794c61f25 Change: rewrote generate_widget in CMake 2020-07-16 00:53:26 +02:00
TrevorShelton c39d62c245 Update: Disuse of STR_ERROR_INCOMPATIBLE_ROAD 2020-07-10 14:47:55 +01:00
Charles Pigott dc8d0089e9 Codechange: Make sure script enums are the same size as their normal counterparts 2020-06-27 14:51:14 +01:00
Charles Pigott e5f931ef42 Fix: Warning about using the wrong enum type 2020-06-27 14:51:14 +01:00
Charles Pigott 64b1c70fdd Codechange: Add WARN_FORMAT to vseprintf and fix the cascade of warnings that followed 2020-06-27 14:51:14 +01:00
Patric Stout 56d54cf60e Add: introduce CMake for project management
CMake works on all our supported platforms, like MSVC, Mingw, GCC,
Clang, and many more. It allows for a single way of doing things,
so no longer we need shell scripts and vbs scripts to work on all
our supported platforms.

Additionally, CMake allows to generate project files for like MSVC,
KDevelop, etc.

This heavily reduces the lines of code we need to support multiple
platforms from a project perspective.

Addtiionally, this heavily improves our detection of libraries, etc.
2020-06-05 19:36:05 +02:00
Michael Lutz 1c0ba07c3c Add: [Script] Native priority queue; useful e.g. for pathfinders. 2020-06-01 21:35:13 +02:00
TechGeekNZ 16e5f610f7 Cleanup: Correct typographic errors in code comments. 2020-05-28 08:26:41 +01:00
Jonathan G Rennison f11cd8f2d0 Fix: Compilation warnings in story_gui and script_story_page
See: #7896
2020-05-27 22:22:56 +02:00
Niels Martin Hansen 800ade7702
Feature: Push-buttons on storybook pages (#7896)
Allow more direct player-initiated interaction for Game Scripts, by letting the GS put push-buttons on storybook pages. These buttons can either trigger an immediate event, or require the player to first select a tile on the map, or a vehicle.

Additionally this reworks how the storybook pages are layouted and rendered, to allow for slightly more complex layouts, and maybe speeding drawing up a bit.
2020-05-22 22:22:55 +02:00
glx e0d20a44d2 Codechange: Use a dynamic copyright year 2020-05-06 09:54:36 +01:00
Michael Lutz 1f1345de09 Codechange: [Script] Improve copying a list into another empty list. 2020-04-26 18:09:42 +02:00
SamuXarick 93a7ff6709
Fix: [Script] ScriptMarine::AreWaterTilesConnected failed for aqueducts (#8074) 2020-04-16 20:32:20 +02:00
SamuXarick e7b901462e Doc: [Script] Make it clear random_deviation and CONFIG_RANDOM range upper bounds are inclusive 2020-03-31 22:33:19 +01:00
SamuXarick 8f9654c5c6 Fix: [Script] Random deviation upper bound range should be inclusive 2020-03-31 22:33:19 +01:00