This is a first shot at a design for coding the military model. It interfaces with stuff like user interface, AI, and economics-infrastructure for supporting units, tech for efficiency of units... The interfacing part is not detailed at all yet.
Main proposed Classes (or interfaces):
Army
Unit
UnitArchetype
Resource *(not military specific)
UnitBuilder (or something from infrastructure model)
TaskForce
General (links to AI, user interface)
Observable *
* not specific to military, and can be coded otherwise if anyone has better ideas or this rebukes too many people.
UnitOrder
MovementManager
EncounterManager
Strategies (links to AI)
Description:
Army is a class or interface from which Unit and TaskForce derive. It has the civ, movement and combat infos common to both subclasses. It also has current orders and current General info.
Unit is the class describing one unit. It contains data like current health, owner task force, experience, morale, a link to the UnitArchetype that it is a kind of, an identifier (number in civ?), a name (may be used as identifier if fast enough). May also have a base square/city information.
UnitArchetype is a class of units. Examples are trireme, phalanx, tank...
It contains data like name of unit for a given civ, movement points, combat power (attack, defense, ranged attack, scouting?...). Should be created from a resource object. There is probably one UnitArchetype per unit type and per civ. This allows to have civ-specific name and movement/combat strength based on tech computed in one place.
Resource should be an object managing the various figures used in the game.
It can be used to create the appropriate UnitArchetype objects based on a file like in civ2 for instance. Its being a class allows switching file based to hard coded resources easily. The scope of such a class is much broader than military. It has to do with macro language.
UnitBuilder is the link with infrastructure. Somehow it decides what kind of army can be built based on tech, square, existing infrastructure (barracks...) and builds them.
TaskForce is a group of armies. It links them, computes move rate and power.
General is a class in charge of an Army (or several). It gives them their orders. There are two kinds of Generals: one is the player, the other the AI. AI generals probably take their orders from other AIs. This is not discussed here (not yet). The two main subclasses are thus one AI taking orders from another, and one Player, which observes certain events. See Observable below.
Observable: Actually this is rather an event bus: Events are typically emitted thru the user interface, but they can be emitted by the AI too. I probably need a EventBus class somewhere that can emit events based on strings, so General would interpret the events it is interested in. This is based on the Observer/Observable pattern (thus the name of this section), but different from standard java implementation: I'd like to be able to send new events without having to change the code of the observed object. Thus an event bus managing events with string source = "Player"/"AI1"/..., string eventClass = "name of the class" would allow to send events and observe them without coupling military to UI: The PlayerGeneral would say it is interested in "Player"+"ArmyOrder" for instance, and the UI could send these events through the event bus.
UnitOrder is the current orders given to an army. Orders can be attack, garrison, move, maybe also scout, pillage and others... Orders are per TaskForce but a unit inside a TaskForce could have separate orders.
MovementManager manages the movement of the armies, coordinating each civ moves and calling EncounterManager when they meet.
EncounterManager manages the meeting of armies. Might also manage what happens on entering enemy squares or special events, based on strategy. For instance MovementManager moves army X into square Y. X's UnitOrder happens to be pillage so EncounterManager is called and X begins pillaging Y. Probably some observers are needed here.
Strategies are what should be evaluated by the AI. It is a goal like attacking this or that square, which can be modelled as a UnitOrder, but additionnally it includes info on who to send there, who's already there and what payoff can be expected if we do that now. It also includes how much we want to reach this goal, and how far we are from it/what we need to achieve it.
Main proposed Classes (or interfaces):
Army
Unit
UnitArchetype
Resource *(not military specific)
UnitBuilder (or something from infrastructure model)
TaskForce
General (links to AI, user interface)
Observable *
* not specific to military, and can be coded otherwise if anyone has better ideas or this rebukes too many people.
UnitOrder
MovementManager
EncounterManager
Strategies (links to AI)
Description:
Army is a class or interface from which Unit and TaskForce derive. It has the civ, movement and combat infos common to both subclasses. It also has current orders and current General info.
Unit is the class describing one unit. It contains data like current health, owner task force, experience, morale, a link to the UnitArchetype that it is a kind of, an identifier (number in civ?), a name (may be used as identifier if fast enough). May also have a base square/city information.
UnitArchetype is a class of units. Examples are trireme, phalanx, tank...
It contains data like name of unit for a given civ, movement points, combat power (attack, defense, ranged attack, scouting?...). Should be created from a resource object. There is probably one UnitArchetype per unit type and per civ. This allows to have civ-specific name and movement/combat strength based on tech computed in one place.
Resource should be an object managing the various figures used in the game.
It can be used to create the appropriate UnitArchetype objects based on a file like in civ2 for instance. Its being a class allows switching file based to hard coded resources easily. The scope of such a class is much broader than military. It has to do with macro language.
UnitBuilder is the link with infrastructure. Somehow it decides what kind of army can be built based on tech, square, existing infrastructure (barracks...) and builds them.
TaskForce is a group of armies. It links them, computes move rate and power.
General is a class in charge of an Army (or several). It gives them their orders. There are two kinds of Generals: one is the player, the other the AI. AI generals probably take their orders from other AIs. This is not discussed here (not yet). The two main subclasses are thus one AI taking orders from another, and one Player, which observes certain events. See Observable below.
Observable: Actually this is rather an event bus: Events are typically emitted thru the user interface, but they can be emitted by the AI too. I probably need a EventBus class somewhere that can emit events based on strings, so General would interpret the events it is interested in. This is based on the Observer/Observable pattern (thus the name of this section), but different from standard java implementation: I'd like to be able to send new events without having to change the code of the observed object. Thus an event bus managing events with string source = "Player"/"AI1"/..., string eventClass = "name of the class" would allow to send events and observe them without coupling military to UI: The PlayerGeneral would say it is interested in "Player"+"ArmyOrder" for instance, and the UI could send these events through the event bus.
UnitOrder is the current orders given to an army. Orders can be attack, garrison, move, maybe also scout, pillage and others... Orders are per TaskForce but a unit inside a TaskForce could have separate orders.
MovementManager manages the movement of the armies, coordinating each civ moves and calling EncounterManager when they meet.
EncounterManager manages the meeting of armies. Might also manage what happens on entering enemy squares or special events, based on strategy. For instance MovementManager moves army X into square Y. X's UnitOrder happens to be pillage so EncounterManager is called and X begins pillaging Y. Probably some observers are needed here.
Strategies are what should be evaluated by the AI. It is a goal like attacking this or that square, which can be modelled as a UnitOrder, but additionnally it includes info on who to send there, who's already there and what payoff can be expected if we do that now. It also includes how much we want to reach this goal, and how far we are from it/what we need to achieve it.
Comment