Commit Graph

21848 Commits

Author SHA1 Message Date
fcc6bbe797 Fix d73a3f59ad - wstring_view on a temporary & wrong utf16->8 conversion.
Two issues:
- The wstring_view was created on a temporary string - the data got
overwritten sometimes.
- there was some weird UTF16->UTF8 conversion going on.


Reported by: langbart
Differential Revision: https://code.wildfiregames.com/D3828
This was SVN commit r25226.
2021-04-09 18:08:37 +00:00
fc60d80af1 Simplify GUI Proxy implementation & customisation.
This finishes 7c04ea0211 and 1b67a079fb.
GUI Proxy objects are now easier to specialize, code duplication is
reduced, code is made safer.
In details:
- the proxy private is always the IGUIObject* pointer
- the private data is accessed through a safer wrapper
- CreateJSObject returns an opaque type to allow easier extension &
prevent errors.
- The implementation of CreateJSObject is moved near the GUI Proxy
template instantiation, and both are wrapped in a convenient macro (this
makes it so that if you use the macro, you can't forget to overload the
method, and vice-versa).
- The common IGUIObject JS interface no longer needs to be repeated.
- All specialisations are again put in the same file, for improved
compile-time & clarity, given there are so few lines now.
- While at it, implement toSource which makes it possible to `uneval`
components (does the same as toString though).


Differential Revision: https://code.wildfiregames.com/D3826
This was SVN commit r25225.
2021-04-09 18:01:47 +00:00
3759fc8a98 Allow empty actor files.
This allows empty actor files -> they map to a dummy object that renders
nothing.
The use case is automatically hiding objects at lower quality levels &
LOD settings.

Differential Revision: https://code.wildfiregames.com/D3819
This was SVN commit r25224.
2021-04-09 15:45:31 +00:00
d73a3f59ad Allow arbitrary compositions in TemplateLoader template names.
- Allows compositing any two templates in TemplateLoader, and not just
filters: 'A|B|C' is now valid for any template A, B and C.
- Allows parents to be composited paths 'A|B|C'. In such a schema, if A
or B themselves specify a parent, the actual composition becomes
A|pA|B|pB|C and so on.

This allows, by leveraging the common schema of our entities, to reduce
duplication.

For convenience, templates in "special/filters/" and "mixins/" can be
included by their direct name. Others have to be completely specified.

See the two provided cases for examples:
- 'hoplite' becomes a mixin that can be used to apply the Phalanx
formation
- 'builder' becomes a mixin that can be give a template the ability to
build the standard structures, and gives the 'Builder' identity class.
This also allows deduplicating that list of tokens.

Update checkrefs & swap std::map for std::unordered_map in
TemplateLoader.

Differential Revision: https://code.wildfiregames.com/D3801
This was SVN commit r25223.
2021-04-09 15:43:50 +00:00
7321509d5f Fix crash in ActorViewer.
Fixes 76acc4e146 (and some 2007-2010 commit).
ObjectManager needs the Simulation to be initialised, thus needs to come
after it in the class.

Tested by: langbart
Differential Revision: https://code.wildfiregames.com/D3827
This was SVN commit r25222.
2021-04-09 15:34:51 +00:00
14d24e03f2 Fix promoting entities going back to default stance.
Introduced in 93d22ef16b.
Brings back the less intrusive bug of transforming while garrisoned of
turreted and unloading results in the default stance. That needs to be
fixed again.

Differential revision: D3822
This was SVN commit r25221.
2021-04-09 08:46:39 +00:00
f7f82ecf25 Use explicit functions for passing on a builders list.
Instead of relying on the assumption that an entity which transforms
only has one of the two (and the same) before and after.
Fixes 5b3bdf3647.

Differential revision: D3821
Comment by: @Stan
This was SVN commit r25220.
2021-04-09 08:42:43 +00:00
1af9a4702d Fix MSVC warning.
Introduced in 592453c62f.

Differential Revision: https://code.wildfiregames.com/D3815
This was SVN commit r25219.
2021-04-09 08:13:14 +00:00
b1c1cb1657 Fix pickup error.
Introduced by forgetting to change a line in fd1d7d5d83.

This was SVN commit r25217.
2021-04-09 07:08:33 +00:00
8f04d2ee90 Move function to perform trade to substate.
Don't pretend it to be a callable function, while it is certainly part
of the FSM.
(Also makes it easier for us to implement a duration for the trading in
the future, might we ever want to.)

Differential revision: D3813
Comment from: @Angen
Closes: #6135

This was SVN commit r25216.
2021-04-09 06:29:49 +00:00
7ba4b1ffc8 Split dropping resources from approaching in UnitAI.
Allows for non-moving entities to drop resources. (When someone checks
those cases in the order.)
(Also makes it easier for us to implement a duration for the dropping in
the future, might we ever want to.)

Differential revision: D3817
This was SVN commit r25215.
2021-04-09 06:25:47 +00:00
6023a273df Fix phasing requirements of tutorial.
Introduced in 2ef3fd7a77.
Fixed by switching the order of task of the barracks and outpost.

Patch by: @nwtour
Differential revision: D3820
This was SVN commit r25214.
2021-04-09 06:02:22 +00:00
294d102a6f Queue techs at structure with the lowest queue length.
Instead of queueing all techs at the lowest ID.

Patch by: @n1xc0d3r
Differential revision: D3798
Tested by: @Langbart
This was SVN commit r25213.
2021-04-09 05:55:05 +00:00
f5a0ab81b6 Fix missing return in 3c4a341906.
Caused entities to walk to the edge of the map when their dropsite was
destroyed.

This was SVN commit r25211.
2021-04-08 10:34:48 +00:00
76acc4e146 Implement quality levels for actors & corresponding setting.
An actor file, as referenced by the VisualActor, can now define
different actors for different "quality level" setting.
In this initial version, the quality is handled directly by the object
manager.

Actor format impact:
- '<qualitylevels>' may be used as the root node, containing actor nodes
as children.
  - such actor nodes can refer to a file, or to an inline actor, or
simply be inlined.
  - such actor nodes may have a 'quality' attribute, specifying the
maximum quality level of this actor. By default, 255 (the maximum) is
implied.
- The actor format remains valid, but 'groups', 'variants', 'material',
'castshadow' and 'float' can be given a [minquality, maxquality[ range
via XML attributes. Outside of this range, the XML node is ignored
(making it possible to define, in a single actor file, several quality
levels).

Quality is a 0-255 value, with:
- Range 0-99 intended for lower level-of-detail actors (billboards,
etc.)
- Range 100-200 the 'normal' range for models. 100 is "low", 150
"medium", and 200 "high".
- Range 201-255 used for higher quality actors that might be used for
e.g. cinematics.
The range is wide to make it easier to add intermediate levels in the
future and it seemed easier given that an integer value of some kind was
required anyways.

Engine impacts:
- A new CActorDef class is introduced, wrapping an art/actors XML file
and its different quality levels. ObjectBase remains the definition of a
given 'actor', now at a given quality level.
- CActorDef imposes a maximal # of quality level for a particular actor
definition (5 currently).
- CUnit is made to refer to an Actor Definition explicitly, not a
particular ObjectBase.
- As a minor optimisation, variation keys are calculated on
pointer-to-sets-of-selections, instead of raw sets-of-selections, as
this reduces copying.
- some refactoring, including better const-correctness and hotloading
support via std::shared_ptr.

Differential Revision: https://code.wildfiregames.com/D3787
This was SVN commit r25210.
2021-04-08 07:22:24 +00:00
e3695abe59 Build using Builder instead of UnitAI.
Moves the building logic from UnitAI to Builder.
Makes it easier for modders to change building behaviour, e.g. letting
structures build.

Differential revision: D3812
Comment by: @Angen
This was SVN commit r25208.
2021-04-08 05:50:18 +00:00
f2d5603422 Heal using Heal instead of UnitAI.
Moves the healing logic from UnitAI to Heal.
Makes it easier for modders to change healing behaviour, e.g. letting
structures heal (instead of using an aura).

Differential revision: D2680
Comments by: @Stan, @wraitii
This was SVN commit r25207.
2021-04-08 05:40:49 +00:00
3c4a341906 Gather using ResourceGatherer instead of UnitAI.
Moves the gathering logic from UnitAI to ResourceGatherer.
Makes it easier for modders to change gathering behaviour, e.g. letting
structures gather.
Refs. #4293 by optimising a bit.

Differential revision: D2662
Comments by: @bb, @Stan, @wraitii
This was SVN commit r25206.
2021-04-08 05:31:34 +00:00
48d6b84c62 Fix initial animation sync.
UpdateAnimationID → PickAnimationID

Reviewed by: @wraitii
Differential Revision: https://code.wildfiregames.com/D3747
This was SVN commit r25205.
2021-04-07 08:35:02 +00:00
a7d777d69b Don't store origin market in this.goods in cmpTrader.
It was introduced in 9b98585275 but made obselete in 98b4fe6d00.

Differential revision: D3809
This was SVN commit r25204.
2021-04-07 07:04:57 +00:00
9ee4ccd8ec Split commit from build in cmpFoundation.
Useful if e.g. a modder wants to commit a structure before building it.

Differential revision: D3806
This was SVN commit r25203.
2021-04-07 07:02:12 +00:00
ac7db9850b Move trader gain to cmpMarket.
Deletes the helper, since we need at least one market anyway.

Differential revision: D3808
Closes: #5890

This was SVN commit r25202.
2021-04-07 06:58:36 +00:00
739a63828a Suppress CppCheck "unknown macro" lint error.
Including third party libraries to the cppcheck include path is annoying
and the unknownMacro errors are generally not useful.

This was SVN commit r25200.
2021-04-06 15:20:35 +00:00
f1e4a0e6f6 Some cleaning in cmpFoundation.
- `var` -> `let`.
- Remove some comments.

Differential revision: D3803
This was SVN commit r25199.
2021-04-06 13:35:29 +00:00
e208b703ca Only tell stuff to move from foundation when trying to commit it.
It is wasteful to do and seems not needed anymore.

Differential revision: D3802
Comments by: @Angen, @Stan
Reverts b478b9742a, b478b9742a
Refs. #3410

This was SVN commit r25198.
2021-04-06 13:06:27 +00:00
5b3bdf3647 Use transform to finish construction.
Decreases duplication.

Differential revision: D3804
Comment from: @wraitii (also on IRC)

This was SVN commit r25197.
2021-04-06 12:54:33 +00:00
973de1ccd7 Fix foundation committing following 592453c62f (pushing)
592453c62f added a flag to "GetBlockMovementFlag" to return either the
current or the template value, and by default it returns the template
value.
Foundation logic needed it to return the current value.

Gates are also updated to avoid changing behaviour in unpredictable
ways.

Differential Revision: https://code.wildfiregames.com/D3796
This was SVN commit r25196.
2021-04-06 12:28:53 +00:00
80f354a125 Fix nopch / tiny hotkey optimisation
Swap an std::set for an std::vector, the set was useful only in an
earlier iteration of the diff. This fixes nopch.

Differential Revision: https://code.wildfiregames.com/D3790
This was SVN commit r25195.
2021-04-06 12:26:34 +00:00
93d22ef16b Allow to specify subunits on creation.
This basically does two things:
- Allow turrets on moving entities (fixes serialisation in cmpPos).
- Allow an entity to be present on another when the other is created.

That makes it basically a boiled down version of a prior patch, omitting
the part where orders could be passed on.
This does allow e.g. ranged units on chariots that fire while the
chariot moves.

Original diff by: @sanderd17
Redone by: @Stan
Differential revision: D1958
Comments by: @Alexandermb, @Angen, @bb, @Langbart, @Nescio, @Stan,
@wraitii
Refs. #2577 by implementing the entity on platform case.

This was SVN commit r25192.
2021-04-05 05:22:25 +00:00
e2f4ce0649 Add Upkeep component.
Adds a new component effectively handling negative resource trickles.
Prevents resources from going negative and provides an effect for not
being able to pay.
The effect chosen for 0 A.D. is having the entity not being
controllable.

Not used in the public mod itself, but it is in quite some mods.

Based on an idea of @Nescio
Differential revision: D1323
Comments by: @Angen, (@smiley,) @Stan
This was SVN commit r25191.
2021-04-04 06:52:20 +00:00
7562354c49 Don't pass owner to initialise a foundation.
As ownership is already set.
Refs. bdbd0b9dbf and 9213ee8c27.

Differential revision: D3795
This was SVN commit r25190.
2021-04-04 06:38:16 +00:00
58ec287b1f Use interval instead of timeout for healing in GarrisonHolder.
Prevents constant recreation of a timeout.

Differential revision: D3791
Refs. #6081

This was SVN commit r25189.
2021-04-04 06:32:53 +00:00
0d630fb113 Fix garrison rally point when unloading.
Revealed by f884848745. Noticed by @Langbart.
The holder was deleted after being tasked to garrison the new target,
but with still a holder we were not allowed to garrison.

Differential revision: D3794
Closes: #6128
Tested by: @Lanbart
This was SVN commit r25188.
2021-04-04 05:57:42 +00:00
7032a3c12a Further hotkey work: clear hotkeys when an input box/the console gets focus.
This is necessary following 2d53308e1b, which now handles key-up in
input to prevent hotkeys from firing then.
Hotkeys are a global system, which means opening e.g. the chat window or
the summary does't reset things. If you press "S" to scroll the in-game
camera down, then press 'return' to open the chat, the camera keeps
scrolling down. Following 2d53308e1b, it never released since it never
got the keyup.

To handle this nicely, we need to explicitly clear hotkeys when input
boxes get focus (respectively the console).

Differential Revision: https://code.wildfiregames.com/D3797
This was SVN commit r25186.
2021-04-03 20:12:40 +00:00
52e8a0c5fb Fix chasing after Motion Manager & Pushing.
The motion manager introduced in bae258f9a1 makes 'chasing' (e.g. an
entity targeting another entity, which also applies to fleeing)
behaviour symmetrical: both units see the initial state instead of it
being ID-dependent.
This allows removing hacks introduced in 6a66fb8205 (and refined in
7b88b1a0f9).

Differential Revision: https://code.wildfiregames.com/D3785
This was SVN commit r25185.
2021-04-03 07:00:58 +00:00
fb498d97d9 Fix raising alert.
After 21e866fcf0.
AllertRaiser replaced the order instead of just calling the required
function.
While at it, check for the garrisonable size when looking for buildings.

Differential revision: D3789
Tested by: @Langbart
This was SVN commit r25183.
2021-04-02 17:01:59 +00:00
592453c62f Add a simple 'pushing' logic to unit motion to improve movement.
This implements a form of crowd movement that I've generally called
'unit pushing' in the last few years.
Essentially, any two units will push each other away when they're too
close. This makes it possible to ignore unit-unit obstructions, and thus
makes movement much smoother in crowds.
This first iteration of this system only allows pushing between idle
units and between moving units (i.e. a moving unit does not affect an
idle one).
This is because the unitMotion logic to detect it is stuck & needs to
use the pathfinders starts breaking: units can fail to move because they
are pushed away from their intended movement, and the current logic
fails to handle this gracefully.
Thankfully, the most value of this patch in terms of player experience
is found in the improvements to group movements and shuttling.

Other impacts:
- As the short pathfinder is called less often, we can increase the
starting search range & reduce the # of max turns, both improving
collision recovery.
- The performance of idle units is slightly worsened, as they must be
checked for idle-idle collisions. If needed a 'sleeping' system, as used
in physics engine, could be implemented.
- In general, however, expect slight performance improvements, as fewer
short paths are computed.
- Gathering efficiency should increase slightly, since shuttling times
are likely reduced slightly.
- As a sanity change to improve some edge cases (units that say they're
moving, i.e. pushable, but don't actually move), the 'going straight'
logic is turned off if a short path has been computed. This requires a
few cascading changes to work correctly.

Technical notes:
- To reduce the cost of the n^2 comparisons that pushing requires, units
are only compared within a small square on a grid which is lazily
reconstructed each turn. The overhead seems rather small, and this is
much simpler than keeping an up-to-date grid.
- The design is intended to be parallelisable if needed someday.
- The pathfinder's CheckMovement ignores moving units in UnitMotion, as
that is now the spec. Idle units are not ignored, which is required for
the 'collision' detection to work correctly (see above).

Refs #3442 (not fixed - idle units are not pushed by moving units).
Fixes #5084 (the overlap can still happen, but units will push each
other away).

Differential Revision: https://code.wildfiregames.com/D1490
This was SVN commit r25182.
2021-04-02 16:30:59 +00:00
8ed1bc2fd1 Don't error in the network delay notifier.
Differential Revision: https://code.wildfiregames.com/D3788
This was SVN commit r25181.
2021-04-02 14:20:37 +00:00
2d53308e1b Fix console not preventing hotkeys from firing / Clean up hotkey-input conflict.
- Fix mistake in 4b46c09222 (similar to one in a4852c4c01) that allowed
hotkeys to fire while typing in the console.
- Prevent Alt+key to fire hotkeys in input boxes & console as that is
often text input.
- Split the hotkey triggering logic in two: a preparatory phase & an
actual firing phase.
This allows the GUI code to check which hotkeys are about to fire and
selectively allow them to go through. This makes it easier to change
hardcoded hotkeys, such as the console toggling one.

Differential Revision: https://code.wildfiregames.com/D3786
This was SVN commit r25180.
2021-04-02 14:18:20 +00:00
6842eacde9 Fix allowed classes on turret points.
Should use `_string` on init. Noticed by @wraitii.

Differential revision: D3783
This was SVN commit r25178.
2021-04-02 07:15:46 +00:00
0232c0d017 Fix 4b46c09222 - Mouse wheel hotkeys behaving erratically.
Mouse wheel hotkeys behave differently from other hotkeys (mouse
button/keys) in that they are transient: they're always pressed/released
in one go.
As such:
- They shouldn't be added to the stored pressedHotkeys
- They shouldn't be added to active scancodes.

This fixes these issues from 4b46c09222 & also skips un-necessary
processing in those cases.

Reported by: Imarok.
Differential Revision: https://code.wildfiregames.com/D3782
This was SVN commit r25176.
2021-04-01 14:51:22 +00:00
ae1bc9b785 Show non-default hotkeys that appear in JSON spec files in the hotkey editor.
This makes sure all hotkeys from hotkeys/spec/*.json files are displayed
in the editor, even if they are not found in configuration files.

Differential Revision: https://code.wildfiregames.com/D3767
This was SVN commit r25175.
2021-04-01 09:20:29 +00:00
28bd4f0092 Introduce a 'Builder' class for entities that can build structures.
- Increases moddability
- Increases the clarity of visible classes (gatherer & builder vs
Worker)
- Introduce an 'Idle builder' hotkey.

Patch by: Nescio
Differential Revision: https://code.wildfiregames.com/D3290
This was SVN commit r25174.
2021-04-01 07:26:59 +00:00
1b5ed5063f Cleanups CGUISprite, removes redundant method.
This was SVN commit r25172.
2021-03-31 19:26:05 +00:00
22ea79a56f Fix the 'Introductory Tutorial' found in the 'tutorial campaign'.
Some information & resources were outdated, preventing progress.

Patch by: nwtour
Differential Revision: https://code.wildfiregames.com/D3764
This was SVN commit r25171.
2021-03-31 15:58:16 +00:00
b55b236379 Remember OOS on a per-client basis.
Change the OOS notification logic to remember the OOS-ness of each
client. Reset it on client leave.
The server will thus continue checking for OOS if the OOS-client leaves.
This is convenient to ignore observer OOS, or wait for an OOS player
without restarting the game.

Also add the turn number to the OOS dump, to fix #3348: particularly
following d4c2cf4430 the turn is likely to not be the same between
different clients.

Agree by: asterix
Differential Revision: https://code.wildfiregames.com/D3753
This was SVN commit r25170.
2021-03-31 15:55:19 +00:00
4b46c09222 Do not trigger "HotkeyPress" events when releasing a key.
Follows d0a42f2f00.
Because only the most specific hotkeys can be active at any time,
releasing a key may require re-activating less specific hotkeys.
There were two issues with this behaviour:
- It was buggy, as it only checked one active key, when any still active
key can trigger hotkeys.
- "HotkeyPress" and "HotkeyDown" events where sent, as if the hotkey was
pressed, which was unexpected for most code/users (it is unusual to have
a "Press" event on key release).

This fixes these issues by "silently" re-triggering the hotkeys in such
a case. It also makes it easier for JS code to use "hotkeyPress" instead
of "hotkeyDown" for non-continuous behaviour.

Accepted By: nani
Fixes #6123
Refs #6064 (fixes the problem, but not the code weirdness)

Differential Revision: https://code.wildfiregames.com/D3766
This was SVN commit r25169.
2021-03-31 15:50:25 +00:00
457c538780 GameSetup: fix selecting a map with up/down keys.
Fixes dc18d94030.
Using down/up to change the map in the map selection dropdown in the
gamesetup has a one-element lag. The reason is that on dropdown up/down,
two events are sent:
- first the current highlighted item is selected (it's usually the
selected one).
- then the new item is selected.

Because of faulty timer logic, only the first update went through.

Differential Revision: https://code.wildfiregames.com/D3774
This was SVN commit r25168.
2021-03-31 13:10:07 +00:00
6c6204f007 Add missing player number to skirmish map names & filenames.
Patch by: langbart
Fixes #6105

Differential Revision: https://code.wildfiregames.com/D3682
This was SVN commit r25167.
2021-03-31 06:53:05 +00:00
742b636f70 Moves CRect from ps to maths to related geometric primitives.
This was SVN commit r25165.
2021-03-30 21:14:36 +00:00