Commit graph

125 commits

Author SHA1 Message Date
Ralph Sennhauser
0baafb5375
Don't set animation for production with UnitAi
Entities with a production queue when queueing or unqueueing items for
will set an appropriate animation which is desired for structures, like
the forge producing smoke, but not so for units as it interferes with
UnitAi animation state.

Units don't have animations for training or researching so the idle
animation will be set in that case instead. If such a unit is in motion
this results in the unit gliding. To avoid this just skip setting an
animation for entities having a UnitAI.

Reported-by: wowgetoffyourcellphone
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-10-07 19:25:21 +02:00
Ralph Sennhauser
f29f0b7fd1
Enable eslint rule 'no-prototype-builtins'
Enable recommended rule 'no-prototype-builtins' [1] and manually fix violations.

[1] https://eslint.org/docs/latest/rules/no-prototype-builtins

Ref: #8068
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-17 13:47:11 +02:00
Ralph Sennhauser
0ce889ca6d
Use stylistic for deprecated eslint rules
During the eslint 8 cycle the formatting rules were split out [1],
deprecating the corresponding rules in core.

This replaces all rules that where moved to @stylistic/eslint-plugin [2]
and accounts for the difference in the indenting rule behaviour.

To allow the pre-commit import hack to continue to work with the
stylisitc plugin for a recent nodejs version to be used.

[1] https://eslint.org/blog/2023/10/deprecating-formatting-rules/
[2] https://eslint.style/packages/default

Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-06-10 21:23:23 +02:00
Ralph Sennhauser
fd27f39c20
Fix eslint rule 'prefer-const' in components/[H-P]*
eslint --no-config-lookup --fix --rule '"prefer-const": 1' \
    binaries/data/mods/public/simulation/components/[H-P]*

Ref: #7812
Signed-off-by: Ralph Sennhauser <ralph.sennhauser@gmail.com>
2025-05-11 19:24:03 +02:00
Freagarach
73f741d266 Handle researching technologies in the TechnologyManager.
Moves the work done from cmpResearcher to cmpTechnologyManager.
No functional changes.

It allows fancy stuff in the future (#6364).

Differential revision: https://code.wildfiregames.com/D4438
This was SVN commit r26252.
2022-01-26 07:42:36 +00:00
Freagarach
2c33c28a09 Add the ability to do simple (de)serialisation cycle in the JS unit tests. (And change the PQ, Trainer and Researcher serialisation.)
To catch e.g. typos.

- Use the same structure in the ProductionQueue item (de)serialisation
as in Trainer and Researcher.
- Also iterate over the serialisable attributes on deserialize, as
proposed by @elexis (on IRC), for its symmetry.

Proposed by: @Stan
Differential revision: D4388
This was SVN commit r26133.
2021-12-28 08:23:59 +00:00
Freagarach
8d80a2186e Some fixes after the ProductionQueue split.
0c4f59d0a7 / 8475c16c31 introduced a serialisation error (#6391).
Also the templates and the code could be improved.

Differential revision: https://code.wildfiregames.com/D4352
Comments by: @Silier, @Stan
Fixes: #6391

This was SVN commit r26015.
2021-11-26 17:12:26 +00:00
Freagarach
0c4f59d0a7 Split tasks from ProductionQueue.
The task of the production queue should first and foremost be that; a
queue for production items.
Hence, the specifics of training/researching are delegated to specific
components.

As a side effect, this improves the test coverage and fixes:
- Resource not refunding when hitting the entity limit. Introduced in
b8758c8941.
- Autoqueue changing when unable to spawn. Introduced in 956b3f96db.

Modders can change their templates using
https://code.wildfiregames.com/P256.

Differential revision: https://code.wildfiregames.com/D4333
Fixes: #6363
Comments by: @Silier
Refs. #6364

This was SVN commit r26000.
2021-11-16 07:08:39 +00:00
Freagarach
75aa2091b7 Allow to push items to the front of the ProductionQueue.
Refs. #6104
Differential revision: https://code.wildfiregames.com/D4241
Comments by: @bb, @Langbart, @Stan
This was SVN commit r25958.
2021-10-10 19:07:42 +00:00
Freagarach
2c4427b488 A bit more refactoring in the ProductionQueue's item logic.
Remove some duplication.
Split tech and entity data.

Differential revision: https://code.wildfiregames.com/D4227
This was SVN commit r25875.
2021-08-29 05:38:23 +00:00
Freagarach
68e40575a4 Disable autoqueue when changing ownership.
PetraAI can't cope with that and it may be a suprise for other players
as well, when a captures production entity has autoqueue enabled.

Differential revision: https://code.wildfiregames.com/D4185
Refs: #6213

This was SVN commit r25819.
2021-07-05 06:18:26 +00:00
wraitii
956b3f96db Improvement to autoqueue usability
The graphical interface will show autoqueued units as 'ghost' units so
the player gets immediate feedback on what's happening.
The autoqueue disengages if it runs out of resources or entity limits:
this reflects that the autoqueue cannot resume on its own.

By changing the spot where the autoqueue pushes items, the autoqueue no
longer 'buffers' one unit in advance, but remains very slightly less
efficient than manual queuing. This also prevents cheats from leading to
a ton of units accidentally being created.

Accepted By: Freagarach
Refs #6213

Differential Revision: https://code.wildfiregames.com/D4144
This was SVN commit r25779.
2021-06-12 09:43:57 +00:00
wraitii
b8758c8941 Prevent ProductionQueue.AddItem for going over the entity limits / Fix autoqueue being able to train infinite heroes.
Autoqueue can ignore entity limits like Heroes, because AddItem does not
check for them, only commands.js. This changes that, fixing the
autoqueue.

Reported by: Player of 0AD
Tested by: langbart
Refs #6213

Differential Revision: https://code.wildfiregames.com/D4133
This was SVN commit r25753.
2021-06-09 06:33:52 +00:00
Freagarach
51ab4315ff Enable production entities to autoqueue.
This adds a new command button that enables training of units
automatically.
Use:
- Enable auto-queue.
- Train an entity.

This adds a new item to the queue whenever the previous item starts,
such that good micro is more resource-efficient.

Patch by: @azayrahmad
Differential revision: https://code.wildfiregames.com/D3865
Comments by: @Langbart, @nani, @Stan, @wraitii
This was SVN commit r25381.
2021-05-05 06:12:31 +00:00
wraitii
c0157d613d Simplify trigger event naming scheme.
Reduces confusion and string manipulation.

Refs #52.

Differential Revision: https://code.wildfiregames.com/D3913
This was SVN commit r25373.
2021-05-04 09:46:38 +00:00
Freagarach
db21f246f1 A bit more cleanup in ProductionQueue.
- Removed some useless comments.
- Don't assume an item only has either a tech or a unit in
ProgressTimeout.
- Don't initialise boolean values (refs. #5979).

Differential revision: D3739
Comment by: @wraitii
This was SVN commit r25119.
2021-03-25 15:55:54 +00:00
Freagarach
8cdfc107b7 Let garrisoned entities be IDLE.
The "GARRISONED"-state was quite strange, for entities being garrisoned
can just as well perform other tasks (see e.g. turrets).
Also, the need for keeping a "garrison" order on the stack is removed.

Fixes: #6022
Differential revision: D3656
Refs. #6081

This was SVN commit r25069.
2021-03-17 14:53:09 +00:00
Freagarach
a72423d3dc Clean up SpawnUnits in ProductionQueue.
Have an entity cache per item (refs. #6104) (which means it doesn't need
to be created at init; refs. #5979).
Cache the PQ-position instead of querying it for every spawned entity.
One could use any arbitrary player for spawning entities now, increasing
mod support.

Differential revision: D3669
Comment by: @wraitii
This was SVN commit r25064.
2021-03-16 06:01:23 +00:00
Freagarach
df45f538df Clean up AddBatch (AddItem) in ProductionQueue.
Removes indentation.
Adds return value.
Cache owner instead of querying often.

This function can be cleaned even more later.

Differential revision: D3670
Comments by: @wraitii
This was SVN commit r25063.
2021-03-16 05:55:04 +00:00
Freagarach
93fe2ffa8a Handle aura and production pause on GarrisonedStateChanged message.
This reduces hard-coupling between the components.

Refs. #6081
Differential revision: D3683
Reviewed by: @wraitii
This was SVN commit r25062.
2021-03-16 05:49:36 +00:00
Freagarach
533e78b2e5 Clean up RemoveBatch -> RemoveItem code in ProductionQueue.
- Rename `RemoveBatch` to `RemoveItem`.
- Refactor that function. (Don't clear the cached entities when *any*
item is removed.)

Fixes the bug that the training is still blocked when a tech is the next
in the queue and the blocking item is removed.

Based on a patch by: @Polakrity
Differential revision: D1843
Comments by: @Angen, @bb
This was SVN commit r25040.
2021-03-12 08:45:39 +00:00
Freagarach
cd705967ce Clean up timer code in production queue.
- Use an interval instead of requesting a timeout every timeout.
- Integrate the lateness-parameter.
- Some other cleanup.
- Don't create objects for null values in messages.
- Don't create this.timer on init.

Based on a patch by: @Polakrity
Differential revision: D1906
Comments by: @Angen, @Stan
This was SVN commit r25038.
2021-03-12 07:22:52 +00:00
Freagarach
979636cc57 Ungarrison entities using cmpGarrisonable.
Follow-up to e18001e897.
This moves responsibilities even further to the garrisoning entity.

Fixes the garrison flag when renaming entities cannot garrison (#5906).
Allows easy fixing of #6087.

Ticket: #6081
Differential revision: D3628
Comments by: @Stan, @wraitii (also in length on IRC)
This was SVN commit r25019.
2021-03-06 06:07:32 +00:00
Freagarach
a79a47effe Allow to limit unit count per match.
This allows to limit the number of times a specific template can be
constructed/trained/created during a match.

Part of:
https://wildfiregames.com/forum/index.php?/topic/27214-borg-expansion-pack-mod-implementation-in-0ad-alpha-24-release/
Refs.
https://wildfiregames.com/forum/topic/24682-champions-and-civilisations-balance-mod-for-a23/

Differential revision: D2411
Reviewed by: @wraitii
Comments by: @Angen, @Stan
This was SVN commit r24468.
2020-12-29 11:00:54 +00:00
Freagarach
6ee43b6bcd Allow free upgrades and technologies.
And use that for the seleucids reform/traditional tech.

Noticed by @wraitii
Differential revision: D2654
Reviewed by: @bb
Comments by: @Stan
This was SVN commit r24431.
2020-12-19 20:11:57 +00:00
Freagarach
b57abe806c Move civ-specific templates to subfolders.
See also
https://wildfiregames.com/forum/index.php?/topic/28614-template-folder-structure/.

Differential Revision: D2952
Reviewed By: @Nescio
This was SVN commit r24216.
2020-11-19 10:20:25 +00:00
Angen
0bfaedb78d Do not allow upgrading when entity is producing and vice versa.
Before this patch, when entity was upgrading and producing and finished
upgrading before production, production was canceled. That meant player
assumed unit/tech will be ready in certain time but it will not. Also
fixing interference between upgrade and production animations.

Differential Revision: D2652
Reviewed by: bb
Comments by: Stan, Freagarach
Fixes: #5749
Refs: #2706

This was SVN commit r24088.
2020-10-04 10:20:20 +00:00
bb
c2b97cdba0 Safeguard QueryPlayerIDInterface calls
Similar to 31df44673a

This was SVN commit r24060.
2020-09-21 18:54:32 +00:00
bb
31df44673a Add safeguards for all queryOwnerInterface calls
Comments By: Angen, wraitii
Reviewed By: Freagarach
Differential Revision: D2973
This was SVN commit r24050.
2020-09-19 17:55:34 +00:00
wraitii
70c71bff0f Allow Modifiers to affect tokens.
This adds a new mode to modifications called "tokens" which allows
clever token parsing.
Technologies, auras and modifiers in general can use this to switch out,
add or delete tokens dynamically.

Currently implemented are production and builder queue tokens.

Reviewed By: Freagarach
Differential Revision: https://code.wildfiregames.com/D270
This was SVN commit r23843.
2020-07-17 08:23:45 +00:00
wraitii
759bc754c3 Fix arrow count not being properly calculated when autogarrisoning.
423b3cbcaa Moved the message sent that an entity garrisons from
`PerformGarrison` to `Garrison`. However, when an entity is
autogarrisoned from `ProductionQueue` `PerformGarrison` is called thus
not triggering the message. When ejecting the entity from the structure
there is a message sent that the entity is removed, thus allowing for a
negative amount of archers/arrows in `BuildingAI` (see
423b3cbcaa#42654).

Note that `PerformGarrison` was explicitly split in 2102648f7c when
introducing autogarrisoning. It probably has something to do with the
position, since that was split. But I couldn't find any reason why it
cannot be used now.

A side effect of this is that when autogarrisoning an entity with
visible garrison points those will be occupied as well now.

Reviewed By: wraitii
Differential Revision: https://code.wildfiregames.com/D2790
This was SVN commit r23743.
2020-06-06 10:19:42 +00:00
Angen
616a6db6b3 Fix style, Cc and slightly refactor ProductionQueue
Fix redeclarations of variables
Fix variable shadowing
Remove duplicated cmpPlayer
Move querying of the same components out of loop
Change if (foo.length > 0)  to if (foo.length)
Change if (foo == 0) to if(!foo)
Fix remaining var -> let
Remove white space from empty object { } to {}
Restyle more complicated objects

Differential Revision: https://code.wildfiregames.com/D2470
Comments by: elexis, Stan, nani
This was SVN commit r23322.
2020-01-02 20:29:07 +00:00
Stan
6ada1d015d Allow modders to play an animation when objects with production queues are researching techs.
Reviewed by: @Angen
Comments by: @Krinkle, @bb
Thread:
https://wildfiregames.com/forum/index.php?/topic/27329-visual-feedback-for-researching/&tab=comments#comment-389598

Differential Revision: https://code.wildfiregames.com/D2459
This was SVN commit r23239.
2019-12-14 20:49:04 +00:00
wraitii
026ce76e3f Update the fast-actions cheat and AI bonuses to use the modifiers manager
This deletes custom-code and shows how to use this system component for
triggers.

Differential Revision: https://code.wildfiregames.com/D1011
This was SVN commit r22964.
2019-09-22 07:46:29 +00:00
wraitii
190f8d3566 Calculate entity limit counts correctly when SpawnUnits fails in ProductionQueue.
When adding a batch of unit, these in-training units get added to the
production queue and to the entity limit count.
These in-training units need to be removed from the entity limit counts
when spawning them, or we would be double-counting them. This was done
when creating the cached entities, but this was too early: entities
might fail to spawn, for example when there is no room around the
foundation.

Change that so the entity limit count is now decremented right before
giving spawned entities the correct owner (which triggers EntityLimits
OnGlobalOwnershipChanged, which adds the spawned entities to the entity
limit count).

Additionally, add Init to TrainingRestrictions so that the test setup
doesn't complain. Other components have an empty Init instead of
checking for Init in the test setup (and 61/67 have an Init function) so
it seems more standard this way.


Reported By: elexis
Reviewed By: wraitii
Patch By: Angen
Tests By: wraitii
Differential Revision: https://code.wildfiregames.com/D1879
This was SVN commit r22375.
2019-06-15 17:27:24 +00:00
mimo
787345a8db fix error when using salad-bowl on gaia, fixes #4603
This was SVN commit r21661.
2018-04-04 19:27:19 +00:00
mimo
5b314fc0ac Add a time multiplier for AI levels
Differential Revision: https://code.wildfiregames.com/D1350
This was SVN commit r21423.
2018-03-03 10:05:04 +00:00
temple
37d317e01a Remove the alert status on units
Differential Revision: https://code.wildfiregames.com/D681
Reviewed by: causative
Fixes: #4185, #4656

This was SVN commit r21074.
2018-01-30 01:47:12 +00:00
elexis
d5af005a00 Expose INVALID_PLAYER to the JS simulation and use it instead of -1 for consistency with the C++ counterpart.
This was SVN commit r20953.
2018-01-22 01:02:29 +00:00
elexis
c90d72deb5 Replace DataTemplateManager simulation component with a globalscript, refs #4868.
Removes the serialization of JSON files, shrinking savegame files and
rejoin states sent across the network, refs #3834, #4239, #3909,
f24523dc8f.
Removes the AI C++ code to read JSON files from e33d4a52e9 since the AI
can now use the globalscript.
Allows the AI to read Aura templates and removal of GUIInterface code to
improve performance.
Serialization of the JSON objects in other simulation components was
removed in 9c0e37f2c0 / D1109, a6f14f5631 / D1130.

Serialization removal planned by sanderd17
AI part proofread by mimo
Simulation part proofread by bb
Discussed with Itms on irc

Differential Revision: https://code.wildfiregames.com/D1108
This was SVN commit r20737.
2017-12-31 01:02:21 +00:00
mimo
2a6fcafbae Add a {native} civ replacement in buildable and trainable template names
Reviewed By: wraitii, elexis, with inputs from s0600204
Differential Revision: https://code.wildfiregames.com/D1084
This was SVN commit r20603.
2017-12-07 18:33:08 +00:00
elexis
8582dcf47f Check for Technology existence by looking up loaded technologies rather than performing disk access ingame, refs D1024 / 8de5c26540.
Differential Revision: https://code.wildfiregames.com/D1105
Discussed with: mimo

This was SVN commit r20587.
2017-12-04 23:58:44 +00:00
mimo
8de5c26540 Allow civ specific techs with {civ}
Discussed with leper

Reviewed By: bb
Trac Tickets: #4589

Differential Revision: https://code.wildfiregames.com/D1024
This was SVN commit r20551.
2017-11-28 20:43:00 +00:00
mimo
f84d195b9d Fix Builder and ProductionQueue schemas inconsistencies
Reviewed By: bb
Differential Revision: https://code.wildfiregames.com/D1070
This was SVN commit r20540.
2017-11-27 18:42:46 +00:00
elexis
235f452765 Let units face away from the building they were trained or ungarrisoned from.
Uses the vector functions from 8ee2a8aca2 and fixes the TODO from
08db7ebe13 / 0aaddf62aa.

Differential Revision: https://code.wildfiregames.com/D1037
Patch By: temple
This was SVN commit r20497.
2017-11-21 16:22:09 +00:00
mimo
76a2cd43d0 Fix broken Autogarrison in 1638727c23
Patch by Stan

Reviewed By: mimo
Differential Revision: https://code.wildfiregames.com/D885
This was SVN commit r20137.
2017-09-08 18:04:19 +00:00
elexis
2e3ac4cf20 Prevent players from gaining unlimited resources by setting the batch-train-modifier to a non numeric value.
Differential Revision: https://code.wildfiregames.com/D66
Refs #4459
Reviewed By: fatherbushido (wraitii, leper)
This was SVN commit r19826.
2017-06-25 16:05:06 +00:00
mimo
e8c6b09c4f Reset the alert of ProductionQueues when ownerShip changes, fixes #4571
This was SVN commit r19570.
2017-05-13 14:52:23 +00:00
elexis
51d189c767 Display a chat notification if an ally has reached a new phase, optionally also if started or aborted.
Remove the equivalent AI chat notifications.

Differential Revision: https://code.wildfiregames.com/D354
Patch By: Polakrity
Fixes #3512

This was SVN commit r19445.
2017-04-23 00:00:14 +00:00
Itms
83a2e810da Remove all occurrences of for each in JS scripts.
This will allow us to use some linters that would otherwise crash on
this non-standard SpiderMonkey feature. Refs #4419.

Special thanks to elexis for thoroughly checking and testing all the
changes!
Reviewed By: leper, elexis
Differential Revision: https://code.wildfiregames.com/D40
This was SVN commit r19191.
2017-01-30 12:47:08 +00:00