It is currently Fri Nov 16, 2018 11:37 am

All times are UTC + 9:30 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [CW2] Actions
PostPosted: Thu Mar 19, 2009 9:16 am 
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
Actions all share the same Interface 'CWAction'

public interface CWAction {
  void invoke(InGameContext context);

  boolean canUndo();

  void undo();

  String getName();

  boolean isActionCompleted();

  void update(int elapsedTime);

When creating an action you have to provide the input for that action... like
context.doAction(new SelectAction(selectLocation)) or
context.doAction(new MoveAction(from, to))
context.doAction(ActionFactory.createJoinAction(from, to, joinLocation))

Actions can be delayed, this means that each time we update the action it steps further until it is completed.
Actions can work together, move animated, wait, clean the state.. are used for a lot of different unit actions. We store multiple actions into an ActionBag.

When is an action completed:
in case of a direct executed action it is completed after the first invocation.
in case of a delayed executed action it is complete after the action sets actionComplete to true
in case of an action bag it is complete after all the actions in the bag are completed, these can be direct and delayed actions.

actions have a context they are executed in, the 'context' contains these objects: game, mapRenderer, MoveTraverse, HUD,...
actions are used in the ingame state and in the end turn state. Actions do things like moving the cursor, moving a unit, showing the popupmenu, joining 2 units, ...

Who executes actions:
Actions can be created and executed anywhere, but if it is executed through inGameContext.doAction(CWAction) then it will receive updates and if it is supported will be added to the undo manager.

Who creates actions:
from text:
ActionParser transforms
Select 0 0 into a SelectAction
Move 0 0 3 3, Join 3 4, Wait 3 4 into MoveAnimated, Join and finally the wait action all grouped together.

To make these complex action groups we provide a Factory that creates combined actions for you ie:
ActionFactory.createMoveJoinWaitAction(0,0,3,4) or
ActionFactory.createMoveJoinWaitAction(selectLocation, joinLocation)

Actions need to be updated in each game loop, to allow multiple actions and delayed actions to complete

So what's so cool about actions over simple methods?
  • You can group actions together, including delay actions reusing action code -> ActionBag
  • You can store all actions that happened in the game and just replay the list -> Replay
  • Actions are given an undo method so they can be undone -> Undo
  • If each action has a string command then we can write/load action from a replay file.

Last edited by stef569 on Fri Mar 20, 2009 1:49 am, edited 1 time in total.

 Post subject: Re: [CW2] Actions
PostPosted: Fri Mar 20, 2009 1:40 am 
Main Coder

Joined: Fri Apr 04, 2008 10:50 pm
Posts: 169
People can do multiple clicks before the action is executed ie
1. click on unit -> select tile
2. click on destination -> destination tile
3. choose [Join] click on the unit to join -> join tile

On click on unit to join execute:
Move animated from select to destination
join unit on destination with unit on join location
wait on join location
clear state

so we have to remember each clicks(max 3)
when all actions are executed all clicks should be forgotten.

How does The undo work:

There is a undoManager that stores actions. Each action can be done and undone.
As the user performs actions we add them to the undo list.
undoManager.undo() retrieves the last item from the undo list and performs undo to it.
We no longer need the last action, so we remove it from the list
Now undo, redo the last action
It uses the UndoManager in javax.swing.undo.UndoManager

-Select Unit
-add to list
-undo select
-remove select from list

-Select Unit
-add to list
-Show Unit Menu
-add to list
-undo Show unit menu
-remove Show unit menu from list
-undo Select
-redo Select

Why undo and redo Select?
Because redo Select only works when the Select action has been undone. See swing undoManager specs.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 9:30 hours

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Blue Moon by Trent © 2007
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group