____                _       __
    / __ )____  _____   | |     / /___ ___________
   / __  / __ \/ ___/   | | /| / / __ `/ ___/ ___/
  / /_/ / /_/ (__  )    | |/ |/ / /_/ / /  (__  )
 /_____/\____/____/     |__/|__/\__,_/_/  /____/

       A futuristic real-time strategy game.
          This file is part of Bos Wars.
(C) Copyright 2001-2007 by the Bos Wars and Stratagus Project. Distributed under the "GNU General Public License"

action_attack.cpp File Reference

The attack action. More...

#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"

Go to the source code of this file.

Defines

#define WEAK_TARGET   2
 Weak target, could be changed.
#define MOVE_TO_TARGET   4
 Move to target state.
#define ATTACK_TARGET   5
 Attack target state.

Functions

void AnimateActionAttack (CUnit *unit)
 Handle command attack.
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 board.


Detailed Description

The attack action.

Definition in file action_attack.cpp.


Define Documentation

#define ATTACK_TARGET   5

Attack target state.

Definition at line 61 of file action_attack.cpp.

Referenced by HandleActionAttack(), and MoveToTarget().

#define MOVE_TO_TARGET   4

Move to target state.

Definition at line 60 of file action_attack.cpp.

Referenced by AttackTarget(), and HandleActionAttack().

#define WEAK_TARGET   2

Weak target, could be changed.

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

Definition at line 59 of file action_attack.cpp.

Referenced by AttackTarget(), CheckForTargetInRange(), HandleActionAttack(), and MoveToTarget().


Function Documentation

void AnimateActionAttack ( CUnit unit  ) 

Handle command attack.

Animate unit attack!

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

Definition at line 74 of file action_attack.cpp.

References CUnitType::Animations, CAnimations::Attack, FireMissile(), CUnit::Type, and UnitShowAnimation().

Referenced by ActionStillGeneric(), and AttackTarget().

static void AttackTarget ( CUnit unit  )  [static]

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.

Definition at line 98 of file action_attack.cpp.

References COrder::Action, CUnit::ClearAction(), COrder::Goal, CUnit::IsVisibleAsGoal(), NewResetPath, NoUnitP, CUnit::Orders, CUnit::Player, CUnit::RefsDecrease(), CUnit::SavedOrder, CUnit::State, UnitActionStill, CUnit::X, and CUnit::Y.

Referenced by AttackTarget(), and CheckForTargetInRange().

static int CheckForTargetInRange ( CUnit unit  )  [static]

void HandleActionAttack ( CUnit unit  ) 

Handle command board.

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.

Definition at line 464 of file action_attack.cpp.

References COrder::Action, Assert, ATTACK_TARGET, ATTACKRANGE_INDEX, AttackTarget(), CanMove(), CheckForTargetInRange(), DebugPrint, COrder::Goal, MapDistanceBetweenUnits(), CUnitType::MinAttackRange, MOVE_TO_TARGET, MoveToTarget(), NewResetPath, NoUnitP, CUnit::Orders, CUnit::SavedOrder, CUnit::State, CUnit::SubAction, CUnit::Type, UnitActionAttack, UnitActionAttackGround, UnitActionStill, UnitHeadingFromDeltaXY(), CUnit::Wait, WEAK_TARGET, CUnit::X, and CUnit::Y.

static void MoveToTarget ( CUnit unit  )  [static]


Generated on Sat Feb 21 00:28:15 2009 for Bos Wars by  doxygen 1.5.6