Commit Graph

738 Commits (ae27ce12a755fb9685d96a237f5ef636e8318b69)

Author SHA1 Message Date
Peter Nelson bbf3028f89 Fix #11585: Crash when cleaning AI/GS with nested AsyncMode.
Do not throw sanity check when in_shutdown is true. This is also applied to
ExecMode and TestMode as they follow the same pattern.
7 months ago
Peter Nelson c0ea0589b4
Fix: AirportGetNearestTown incorrectly assumed first TileIterator result was origin. (#11565)
Not all TileIterators are equal, and some do not start at the top-corner, so the perimeter check was wrong. As the caller already has thie origin tile, use that instead.
7 months ago
Peter Nelson 7b0afec11f Codechange: Use max_element to find highest cargo amount. 7 months ago
Peter Nelson 3f853d8003 Codechange: Use range-for to simplify getting first non-zero value.
This reduces indexed array access.
7 months ago
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.
8 months ago
Peter Nelson 9602de474d Codechange: Use iterators and/or range-for on cargo related loops. 9 months ago
Peter Nelson 49dae08a3b Codechange: Add missing override specifiers. 9 months ago
frosch b6c8f301be Codechange: Silence warnings about intentionally unused parameters. 10 months ago
Patric Stout ba67f39db6
Codechange: vendor the nlohmann-json library (#11290) 10 months ago
PeterN acd7d3c913
Codechange: Rename *Railtype* to *RailType* for consistency. (#11287) 10 months ago
Tyler Trahan 701a61c9af Codechange: Delete date_type.h 10 months ago
Tyler Trahan 77173a6a10 Codechange: Move date consts and functions to CalendarTime and TimerGameCalendar classes 10 months ago
Tyler Trahan fca2b37726 Codechange: Move Ticks into their own class 10 months ago
Patric Stout 30172fc037
Codechange: cleanup CargoPacket in terms of variable/function names (#11278)
Over the years, things got reused and changed, making the current
names somewhat unclear in what they actually mean and do.
10 months ago
Patric Stout 00f13282a9
Codechange: keep how we convert string <-> JSON private (#11269) 10 months ago
Patric Stout 5f9b8aaa95
Codechange: [Script] use nlohmann for Squirrel <-> JSON conversion (#11251) 10 months ago
Michael Lutz 0089323542 Add: [Script] Custom news message text for industry SetProductionLevel. 10 months ago
Michael Lutz 1c56991213 Add: [Script] Game script control of industry production level. 10 months ago
Patric Stout 7afd686541
Codechange: add tests for GS <-> AdminPort JSON conversion (#11252)
While at it, fix a bug where booleans were made integers.
10 months ago
Patric Stout 993e7be707
Fix: [Script] GSAdmin.Send() could generate invalid JSON (#11250) 10 months ago
Joan Josep 5e6b5d981f
Codechange: Use existing functions in GetMonthlyInfrastructureCosts. (#11237) 10 months ago
Patric Stout 07730584d7
Codechange: make explicit when a TileIndex is cast to its basetype (#11190)
This prevents people accidentially assigning a TileIndex to a Date
or any other type they shouldn't.
11 months ago
Patric Stout 299570b2c1
Codechange: make TimerGameCalendar Date and Year types strongly typed (#10761) 11 months ago
Andy ce9305a5ee
Add: [Script] GSIndustry.GetConstructionDate() method (#11145) 12 months ago
Rubidium eaae0bb5e7 Codechange: automatic adding of _t to (u)int types, and WChar to char32_t
for i in `find src -type f|grep -v 3rdparty/fmt|grep -v 3rdparty/catch2|grep -v 3rdparty/opengl|grep -v stdafx.h`; do sed 's/uint16& /uint16 \&/g;s/int8\([ >*),;[]\)/int8_t\1/g;s/int16\([ >*),;[]\)/int16_t\1/g;s/int32\([ >*),;[]\)/int32_t\1/g;s/int64\([ >*),;[]\)/int64_t\1/g;s/ uint32(/ uint32_t(/g;s/_uint8_t/_uint8/;s/Uint8_t/Uint8/;s/ft_int64_t/ft_int64/g;s/uint64$/uint64_t/;s/WChar/char32_t/g;s/char32_t char32_t/char32_t WChar/' -i $i; done
12 months ago
Rubidium af9b9327af Codechange: do not keep local variable for temporary string parameters 1 year ago
Rubidium 78f5d58dc6 Codechange: use std::string without const as return
Otherwise some compilers, e.g. MSVC, do not pick up that these are temporaries
and as such it will pass the temporaries to `const std::string &` instead of
the wanted `std::string &&`
1 year ago
PeterN 2a2443dd01
Feature: Create group of vehicles from manage vehicle list button. (#10890) 1 year ago
Rubidium d4c2043294 Codechange: remove a number of unneeded c_str() calls 1 year ago
Loïc Guilloux 1cd49bf5e5
Fix ca1e34c: [Script] Wrong value printed for {RAW_STRING} (#11011) 1 year ago
mrmbernardi 35ef6c1723
Feature: [GS] Goal destination can be updated (#10817) 1 year ago
Rubidium 2ae7367024 Codechange: replace StrMakeValidInPlace with StrValid 1 year ago
Rubidium ca1e34c121 Codechange: use std::string to build ScriptText's encoded text 1 year ago
Patric Stout 3b1407d240
Feature: allow to do a hostile takeover of an AI company (in singleplayer) (#10914)
With the removal of the share-system, you could no longer make an
AI disappear in a single player game. At least, not without going
into the console.
1 year ago
Bernard Teo 2c667b1773
Doc: Fix spelling error in ScriptTileList::RemoveRectangle (#10937) 1 year ago
Patric Stout 6b1c38e303
Fix 3effb893: mention GSAsyncMode in changelog (#10924) 1 year ago
Jonathan G Rennison 3effb8931c
Add: [Script] GSAsyncMode to set async mode of gamescript commands (#10913)
In asynchronous mode, don't wait for result of executed command,
just fire-and-forget, and return estimated cost/result
1 year ago
PeterN d086f288cd
Codechange: Remove duplicated includes. (#10888)
These are now included by stdafx.h so don't need to be included again.
1 year ago
PeterN 584faaf064
Change: Reorganise industry accept/produce arrays. (#10853)
Use a array of struct for each cargo instead of an array for each statistic.
This makes iterating for acceptance and production much simpler.
pct_transported is now calculated when needed.
1 year ago
Peter Nelson 09408e8e46 Codechange: Add IsCargoAccepted/Produced() helpers. 1 year ago
Peter Nelson 633f19419d Codechange: Make more use of GetCargoAccepted/ProducedIndex(). 1 year ago
Peter Nelson 76516d7f70 Codechange: Use IsValidCargoID/IsValidCargoType.
IsValidCargoType() is used only for unmapped IDs.
1 year ago
Rubidium 63d9bb93b8 Codechange: migrate from C-style GetString to C++-style GetString 1 year ago
Peter Nelson 56085be9bd Codechange: Move includes for common STL headers to stdafx. 1 year ago
Patric Stout 199e41c762
Codechange: use default dtor instead of empty (#10826) 1 year ago
Rubidium f9b5bc7ee6 Cleanup: the need for SQAutoFreePointers has gone 1 year ago
Rubidium d9e93edc8b Codechange: replace 'const char *' script API parameters with std::string 1 year ago
Rubidium bbcb55ebc9 Codechange: use std::string as script API return type 1 year ago
Rubidium b24a6bb8f3 Codechange: use std::string for script log calls 1 year ago
Rubidium e035705239 Codechange: introduce and use std::string variant of sq_throwerror 1 year ago
Peter Nelson 726d05b22b Fix: Don't list unavailable road types for game scripts. 1 year ago
Peter Nelson e6740046ee Codechange: Use range-for iteration. 1 year ago
Rubidium 12085d088c Cleanup: remove obsolete string_compare_type 1 year ago
Rubidium bc389a86c9 Codechange: use std::string as std::map key, instead of stredup string 1 year ago
Peter Nelson bf9caa425b Change: Units-system can convert from N to kN, don't preconvert.
This allows force to passed as is and avoid premature rounding.

The AI function "GetMaxTractiveEffort" still needs to return kN to avoid breaking the API.
1 year ago
Rubidium 68ff3fd062 Change: include fmt.h C++ headers in stdafx.h
This to prevent compilation issues between runs with and without precompiled
headers. Also remove the headers from the rest of the code base as they are
not needed there anymore, although they do relatively little harm.
1 year ago
Rubidium fb856e16c1 Codechange: replace some min/clamp constructs to ClampTo 1 year ago
PeterN b67cf7f94a
Change: Replace ScriptLog data array with std::deque. (#10770)
Due to cyclic header dependency this requires moving the data types used
by ScriptLog out of the ScriptLog class.
1 year ago
Tyler Trahan 6501f84b4a
Codechange: Move calendar date functions inside TimerGameCalendar (#10753) 1 year ago
Tyler Trahan 930f0a16d8 Codechange: Define Date/Year/Month/Day within TimerGameCalendar class 1 year ago
Patric Stout 7aa2b9ab0a
Codechange: move all date-related variables inside the timer (#10706) 1 year ago
Rubidium 8f24901843 Codechange: replace printf with PRINTF macros by fmt::format for scripts 1 year ago
SamuXarick f8b5661d28 Change: Allow GS access to ScriptGroup functions 1 year ago
SamuXarick f225f36c3d Change: Allow GS access to ScriptGameSettings.IsDisabledVehicleType 1 year ago
SamuXarick fd26a44c9e Change: Allow GS access to more ScriptCompany functions 1 year ago
Andy 8b1960a41c Change: Allow GS access to more ScriptOrder functions 1 year ago
PeterN e97bf271dc
Codechange: Make SpriteType, CargoSortType, SourceType and ScriptType enum classes. (#10663)
This avoids a (soft) namespace conflict between the four ST_* enums.
1 year ago
Charles Pigott 6fc28d649e Cleanup: Unused alloca definitions and includes 1 year ago
dP e2f1cd44dc
Change: Increase max cargo age and let min cargo payment approach zero. (#10596)
Co-authored-by: Michael Lutz <michi@icosahedron.de>
1 year ago
glx22 3a48d6e60f Fix 991a797: [Script] Allow STRINGN consumption to be different than expected 1 year ago
Peter Nelson 82c70ed3b8 Change: Expose ObjectSpec vector to simplify iteration. 1 year ago
Peter Nelson 1f46f080f0 Codechange: Store objectspecs in std::vector instead of flat array. 1 year ago
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.
1 year ago
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.
1 year ago
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.
1 year ago
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.
1 year ago
Rubidium a79f97c022 Change: upon an invalid company mode, set ERR_PRECONDITION_INVALID_COMPANY instead of ERR_PRECONDITION_INVALID 1 year ago
Rubidium 3287acd114 Fix 13528bfcd0: bank balance command allows int64, GS was limited to int32 1 year ago
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".
1 year ago
Rubidium cada2ca310 Add: GSCompanyMode::IsValid and IsDeity, and precondition enforcement helpers 1 year ago
glx22 ca149447d7 Codechange: Use SQInteger for generic numbers in script_window 1 year ago
glx22 f752d96125 Codechange: Use SQInteger for generic numbers in script_vehicle 1 year ago
glx22 4e48bf2e16 Codechange: Use SQInteger for generic numbers in script_town 1 year ago
glx22 18fe0a4046 Codechange: Use SQInteger for generic numbers in script_tilelist 1 year ago
glx22 cada18a6f8 Codechange: Use SQInteger for generic numbers in script_tile 1 year ago
glx22 07b73a8c02 Codechange: Use SQInteger for generic numbers in script_subsidy 1 year ago
glx22 cd80b31d19 Codechange: Use SQInteger for generic numbers in script_storypage 1 year ago
glx22 a9a55f2153 Codechange: Use SQInteger for generic numbers in script_station 1 year ago
glx22 446ebaa6b9 Codechange: Use SQInteger for generic numbers in script_road 1 year ago
glx22 4f6a2f31b5 Codechange: Use SQInteger for generic numbers in script_rail 1 year ago
glx22 cb2e76aae3 Codechange: Use SQInteger for generic numbers in script_priorityqueue 1 year ago
glx22 777b4d0987 Codechange: Use SQInteger for generic numbers in script_order 1 year ago
glx22 49ea69fdef Codechange: Use SQInteger for generic numbers in script_objecttype 1 year ago
glx22 0293fd41e5 Codechange: Use SQInteger for generic numbers in script_news 1 year ago
glx22 f22903ab14 Codechange: Use SQInteger for generic numbers in script_newgrf 1 year ago
glx22 ca67075397 Codechange: Use SQInteger for generic numbers in script_map 1 year ago
glx22 a225fda9fe Codechange: Use SQInteger for generic numbers in script_list 1 year ago
glx22 74ab9ee9dd Codechange: Use SQInteger for generic numbers in script_league 1 year ago
glx22 367b2ba6d1 Codechange: Use SQInteger for generic numbers in script_infrastructure 1 year ago
glx22 5eaf9d39bf Codechange: Use SQInteger for generic numbers in script_industrytype 1 year ago