mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-07-23 03:12:55 +00:00
59d0885d68
This allows choosing a "default formation", which is activated automatically for units given walk orders (and attack-walk etc.). Conversely, units in formation that are given a gather/build/... order are taken out of formation and given the order individually. The default formation can be selected by right-clicking on any formation icon. This leverages formations for walking, where they are quite efficient (in fact, perhaps too efficient), while circumventing issues with various orders. Choosing the "null formation" as the default formation de-activates the behaviour entirely, and plays out exactly like SVN. This makes it possible to queue a formation-order then a noformation-order (i.e. walk then repair), though the behaviour isn't very flexible. For modders, it should be relatively easy to change the setup for each order, and/or to force deactivating/activating formations in general. Tested by: Freagarach, Angen Refs #3479, #1791. Makes #3478 mostly invalid. Differential Revision: https://code.wildfiregames.com/D2764 This was SVN commit r24480.
60 lines
1.9 KiB
JavaScript
60 lines
1.9 KiB
JavaScript
/**
|
|
* Handles the logic related to the 'default formation' feature.
|
|
* When given a walking order, units that aren't in formation will be put
|
|
* in the default formation, to improve pathfinding and reactivity.
|
|
* However, when given other tasks (such as e.g. gather), they will be removed
|
|
* from any formation they are in, as those orders don't work very well with formations.
|
|
*
|
|
* Set the default formation to the null formation to disable this entirely.
|
|
*
|
|
* TODO: it would be nice to let players choose default formations for different orders,
|
|
* but that would be neater if orders where defined somewhere unique,
|
|
* instead of mostly in unit_actions.js
|
|
*/
|
|
class AutoFormation
|
|
{
|
|
constructor()
|
|
{
|
|
this.defaultFormation = Engine.ConfigDB_GetValue("user", "gui.session.defaultformation");
|
|
if (!this.defaultFormation)
|
|
this.setDefault(NULL_FORMATION);
|
|
}
|
|
|
|
/**
|
|
* Set the default formation to @param formation.
|
|
* TODO: would be good to validate, particularly since some formations aren't
|
|
* usable with any arbitrary unit type, we may want to warn then.
|
|
*/
|
|
setDefault(formation)
|
|
{
|
|
this.defaultFormation = formation;
|
|
Engine.ConfigDB_CreateValue("user", "gui.session.defaultformation", this.defaultFormation);
|
|
// TODO: It's extremely terrible that we have to explicitly flush the config...
|
|
Engine.ConfigDB_SetChanges("user", true);
|
|
Engine.ConfigDB_WriteFile("user", "config/user.cfg");
|
|
return true;
|
|
}
|
|
|
|
isDefault(formation)
|
|
{
|
|
return formation == this.defaultFormation;
|
|
}
|
|
|
|
/**
|
|
* @return the default formation, or "undefined" if the null formation was chosen,
|
|
* otherwise units in formation would disband on any order, which isn't desirable.
|
|
*/
|
|
getDefault()
|
|
{
|
|
return this.defaultFormation == NULL_FORMATION ? undefined : this.defaultFormation;
|
|
}
|
|
|
|
/**
|
|
* @return the null formation, or "undefined" if the null formation is the default.
|
|
*/
|
|
getNull()
|
|
{
|
|
return this.defaultFormation == NULL_FORMATION ? undefined : NULL_FORMATION;
|
|
}
|
|
}
|