$treeview $search $mathjax
Stratagus  2.2.6
$projectbrief
$projectbrief
$searchbox
-->
         _________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
           Stratagus - A free fantasy real time strategy game engine

src/action/action_attack.cpp File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stratagus.h"
#include "unittype.h"
#include "animation.h"
#include "player.h"
#include "unit.h"
#include "missile.h"
#include "actions.h"
#include "sound.h"
#include "map.h"
#include "pathfinder.h"

action_attack.cpp - The attack action.

#define WEAK_TARGET   2
#define MOVE_TO_TARGET   4
#define ATTACK_TARGET   5
void AnimateActionAttack (CUnit &unit)
 Show attack animation.
static int CheckForDeadGoal (CUnit &unit)
static int CheckForTargetInRange (CUnit &unit)
static void MoveToTarget (CUnit &unit)
static void AttackTarget (CUnit &unit)
void HandleActionAttack (CUnit &unit)
 Handle command attack.

Define Documentation

#define ATTACK_TARGET   5

#define MOVE_TO_TARGET   4

#define WEAK_TARGET   2

Todo:
FIXME: I should rewrite this action, if only the new orders are supported.


Function Documentation

void AnimateActionAttack ( CUnit unit  ) 

Show attack animation.

Animate unit attack!

Parameters:
unit Unit, for that the attack animation is played.
Todo:
manage correctly unit with no animation attack.

static void AttackTarget ( CUnit unit  )  [static]

Handle attacking the target.

Parameters:
unit Unit, for that the attack is handled.

static int CheckForDeadGoal ( CUnit unit  )  [static]

Check for dead goal.

Warning:
The caller must check, if he likes the restored SavedOrder!
Todo:
If a unit enters an building, than the attack choose an other goal, perhaps it is better to wait for the goal?
Parameters:
unit Unit using the goal.
Returns:
1 if order have changed, 0 else.

static int CheckForTargetInRange ( CUnit unit  )  [static]

Change invalid target for new target in range.

Parameters:
unit Unit to check if goal is in range
Returns:
1 if order(action) have changed, 0 else (if goal change retrun 0).

void HandleActionAttack ( CUnit unit  ) 

Handle command attack.

Unit attacks!

I added a little trick, if SubAction&WEAK_TARGET is true the goal is a weak goal. This means the unit AI (little AI) could choose a new better goal.

Todo:
Lets do some tries to reach the target. If target place is not reachable, choose better goal to reduce the pathfinder load.
Parameters:
unit Unit, for that the attack is handled.

static void MoveToTarget ( CUnit unit  )  [static]

Controls moving a unit to its target when attacking

Parameters:
unit Unit that is attacking and moving

(C) Copyright 1998-2011 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.