2
// / __ )____ _____ | | / /___ ___________
3
// / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4
// / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5
// /_____/\____/____/ |__/|__/\__,_/_/ /____/
7
// A futuristic real-time strategy game.
8
// This file is part of Bos Wars.
10
/**@name action_patrol.cpp - The patrol action. */
12
// (c) Copyright 1998-2007 by Lutz Sammer and Jimmy Salmon
14
// This program is free software; you can redistribute it and/or modify
15
// it under the terms of the GNU General Public License as published by
16
// the Free Software Foundation; only version 2 of the License.
18
// This program is distributed in the hope that it will be useful,
19
// but WITHOUT ANY WARRANTY; without even the implied warranty of
20
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
// GNU General Public License for more details.
23
// You should have received a copy of the GNU General Public License
24
// along with this program; if not, write to the Free Software
25
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
31
/*----------------------------------------------------------------------------
33
----------------------------------------------------------------------------*/
38
#include "stratagus.h"
42
#include "pathfinder.h"
45
/*----------------------------------------------------------------------------
47
----------------------------------------------------------------------------*/
49
extern bool AutoRepair(CUnit *unit);
53
** Swap the patrol points.
55
static void SwapPatrolPoints(CUnit *unit)
59
tmp = unit->Orders[0]->Arg1.Patrol.X;
60
unit->Orders[0]->Arg1.Patrol.X = unit->Orders[0]->X;
61
unit->Orders[0]->X = tmp;
62
tmp = unit->Orders[0]->Arg1.Patrol.Y;
63
unit->Orders[0]->Arg1.Patrol.Y = unit->Orders[0]->Y;
64
unit->Orders[0]->Y = tmp;
71
** The unit patrols between two points.
72
** Any enemy unit in reaction range is attacked.
74
** Should do some tries to reach the end-points.
75
** Should support patrol between more points!
76
** Patrol between units.
78
** @param unit Patroling unit pointer.
80
void HandleActionPatrol(CUnit *unit)
87
if (!unit->SubAction) { // first entry.
92
switch (DoActionMove(unit)) {
97
// Increase range and try again
99
if (unit->Orders[0]->Range <= Map.Info.MapWidth ||
100
unit->Orders[0]->Range <= Map.Info.MapHeight) {
101
unit->Orders[0]->Range++;
107
unit->Orders[0]->Range = 0;
108
SwapPatrolPoints(unit);
111
// Wait for a while then give up
113
if (unit->SubAction == 5) {
115
unit->Orders[0]->Range = 0;
116
SwapPatrolPoints(unit);
124
if (!unit->Anim.Unbreakable) {
126
// Attack any enemy in reaction range.
127
// If don't set the goal, the unit can then choose a
128
// better goal if moving nearer to enemy.
130
if (unit->Type->CanAttack) {
131
const CUnit *goal = AttackUnitsInReactRange(unit);
133
DebugPrint("Patrol attack %d\n" _C_ UnitNumber(goal));
134
CommandAttack(unit, goal->X, goal->Y, NULL, FlushCommands);
135
// Save current command to come back.
136
unit->SavedOrder = *unit->Orders[0];
138
unit->Orders[0]->Goal = NoUnitP;
143
// Look for something to auto repair
144
if (AutoRepair(unit)) {