Units Home - UQdeco2800/2022-studio-3 GitHub Wiki

Since we're making an RTS, we will likely have to have a variety of units to keep things interesting, these will likely need a specific building for their construction, a set of resources to make them and a set of internal statistics (attack, defence, health etc.) for their use in combat/work.

For the initial ideas, before we get properly set up I'll start with everything here.

Units

Units information for friendly units can be seen as follows:

Note that each of these should have an information page in accordance with this template

Creating units

There is a cap on the number of units that can be spawned, which is altered by a number of factors over the course of a game (the size of the map, buildings built, etc.)

Each unit requires a base building in order to be produced and is created with a number of 'troops' that can fight and die.

Initial list

This list was the result of brainstorming and only serves as inspiration for what can be added to the game given enough time/scope

  • workers
  • archers
  • javelin thrower?
  • light spearmen (just guys with sticks)
  • heavy spearmen (like before, but with stone spearheads and wooden shields)
  • pikemen (guys with bigger metal sticks, good against animals)
  • hoplites (guys with metal sticks, shields and armour)
  • Phalanx: They present shields and are only for defensive strategy, not offensive.
  • swordsmen (metal swords, bucklers?)
  • war elephants (reasonable speed, bulky as hell)
  • horse mounted?
  • divers/frogmen (maybe with rebreathers produced from tubers, using its own building), w/ flippers (faster swimmers & better underwater)
  • Ballistas? (add some form of artillery?)

Anatomy of a unit

(insert image when you gain brain)

Units themselves have a hitbox which collide with other friendly units (so that units do not overlap, and can be visually distinguished from one another), and a troop component. Each troop within this component has a hitbox for attacks on enemy 'troops', obstacles and game walls; they also have combat stats and a movement controller.

Code Structure

As per ECS, all units are considered to be entities and any additional properties of the units are added to the entity as components, these additional properties can include things like Entity stats (health, attack, defence, etc..), animations, AI, movement, hit-boxes, etc..

The Entity class or any of it's children must not have any internal attributes like those mentioned above, if you think it's needed, make a Component class for it.

Entity Creation

All entities are generated through a creation methods in factory classes found in source/core/src/main/com.deco2800.game/entities, these factories should load any base values from .json configuration files stored in source/core/assets/configs/, this is to make it easy to modify these values whilst minimising modifying class code directly, an example factory and creation method are provided below.

public class FooFactory {
	private static final FooConfigs configs =
      FileLoader.readClass(FooConfigs.class, "configs/Foos.json");
	
	public static Entity createFoo() {
		// Entity and config initialisation
		Entity foo = new Entity();
		FooEntityConfig config = configs.foo;
		// Component assignment
		foo
			.addComponent(new ComponentX())
			.addComponent(new ComponentY());
		// any extra code...

		return foo;
	}
}

Note: Factories can be organised based on general catagories that multiple unit types could belong too, for example, enemy units, quest giving character, merchants can all be viewed as NPCs (Non Playable Characters), as such creation methods for them can belong to the NPCFactory class

Component Creation

Components are used to store any additional attributes or aspects of the entity, they may be a component that stores combat stats for a combat entity or deal with hit-boxes, animation and AI.

Components are found in source/core/src/main/com.deco2800.game/components any new components should be created in this directory (they can be in sub-directories) and must inherit (either directly or through it's parent) the base Component class. An example component class is provided below.

public class ComponentX extends Component {
	private int foo1;
	private int foo2;

	// constructor

	// set and get functions

	// Any additional functions
}