For this update I'm doing purely the move action by itself and nothing else. I'll modify the architecture as I go along to implement each action.
A move command requires a few changes to the current design of Cultura. Some of these are common between all actions, some are specific to the move action.
- Some way for units to know what action they are to do and to do them
- Updating the position of a unit in all references
- Figuring how to move
Okay so what does this mean? Well we're going to add an action stack to a unit. There will then be action objects. These will be subclassed for the different type of actions. I'll refactor after for any common members between different actions, but for now the only common component is a pointer to the unit to which the action is attached to (to make it easier to manipulate the unit from the action itself rather than passing states information around or firing events). Then updateTick will be modified to carry out the action. Then we'll need the different components to actually be able to carry out the action with pathfinding.
First let's look at updateTick:
We have an outer loop based on a set timer to call the highest level updateTick which then calls it on lower and lower level components until reaching actual actions which then carry out what needs to be done and modifies the relevant variables as needed (the Unit or GameState interface allows the action to do so).
For a move action we need a pathfinder object to figure out where the unit should move. This requires information about the world; which terrain is passable and where structures are. Then it needs a way to modify the position of a unit. It makes a "moveUnit" call on GameState and the GameState updates several variables (delegating the call to Faction which updates the Faction's hashMap of units by location and then calls move on the unit itself to modify the position). The units by location hash map on a Faction is used for determining which units are selected quickly when making a selection box.
Okay, so we've already done unit selection and now UIInputManager takes in a right-click, figures out if it is an empty square and then if so, issues a move command to a unit. The unit clears its action stack and then queues the move action. Now it'll move during updateTick based on its move speed.
Oh poop balls what happened? Actually the mesh used for the humans didn't do the alpha check when rendering. Let's add that now.
Huzzah! Units are moving!
So now to polish it up, there is some jittery movement which I think is related to the main game loop (might not be designed correctly and thus not the same amount of time passes between each updateTick) and I want an x to show up where you told the unit to move.
No comments:
Post a Comment