Advanced Strategic Command
attacktest.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * *
3  * This program is free software; you can redistribute it and/or modify *
4  * it under the terms of the GNU General Public License as published by *
5  * the Free Software Foundation; either version 2 of the License, or *
6  * (at your option) any later version. *
7  * *
8  ***************************************************************************/
9 
10 #include "../gamemap.h"
11 #include "../actions/attackcommand.h"
12 #include "../loaders.h"
13 #include "unittestutil.h"
14 #include "../itemrepository.h"
15 #include "../spfst.h"
16 
17 
18 void testAttack1()
19 {
20  auto_ptr<GameMap> game ( startMap("unittest-attack.map"));
21 
22  Vehicle* veh = game->getField(3,6)->vehicle;
23  assertOrThrow( veh != NULL );
24  assertOrThrow( veh->getMovement() == 100 );
25 
28 
29  attack( veh, MapCoordinate( 3,5) );
30 
31  assertOrThrow( veh->getMovement() == 0 );
34 
35  testCargoMovement( veh, 50 );
36 
37  ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
38  assertOrThrow( res.successful() );
39 
40  assertOrThrow( veh->getMovement() == 100 );
41  testCargoMovement( veh, 100 );
42 
43 
44  Vehicle* mam = game->getField(4,4)->vehicle;
45  assertOrThrow( mam != NULL );
46  assertOrThrow( mam->getMovement() == 100 );
49 
50  attack( mam, MapCoordinate( 3,5) );
53 
54  assertOrThrow( mam->getMovement() == 100 );
55  testCargoMovement( mam, 100 );
56 
57  Vehicle* v2 = game->getField(9,14)->vehicle;
58  assertOrThrow( v2 != NULL );
59 
60  Vehicle* a2 = game->getField(9,17)->vehicle;
61  assertOrThrow( a2 != NULL );
62 
63  attack( a2, MapCoordinate( 9, 14 ) );
64 
65  assertOrThrow( game->getField(9,14)->vehicle == NULL );
66  res = game->actions.undo( createTestingContext( game.get() ) );
67  assertOrThrow( res.successful() );
68  assertOrThrow( game->getField(9,14)->vehicle != NULL );
69 }
70 
72 {
73  auto_ptr<GameMap> game ( startMap("unittest-objectattack.map"));
74 
75  Vehicle* buggy = game->getField(0,3)->vehicle;
76  assertOrThrow( buggy != NULL );
77 
78  Vehicle* assault = game->getField(1,2)->vehicle;
79  assertOrThrow( assault != NULL );
80 
81  MapCoordinate h ( 3, 8 );
82  MapCoordinate cry( 3,9);
83 
84  move( buggy, h);
85  attack( buggy, cry );
86  move( buggy, MapCoordinate( 0,3 ));
87 
88  move( assault, h );
89 
90  ObjectType* cryst = objectTypeRepository.getObject_byID( 2105 );
91  assertOrThrow( cryst != NULL );
92 
93  MapField* fld = game->getField( cry );
94  assertOrThrow( fld->checkForObject( cryst ) != NULL );
95 
96  MapField* view = game->getField( MapCoordinate( 4,11 ));
97  assertOrThrow( fieldvisiblenow(view) == false );
98 
99  attack( assault, cry );
100 
101  assertOrThrow( fld->checkForObject( cryst ) == NULL );
102 
103  assertOrThrow( fieldvisiblenow(view) == true );
104 
105  ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
106  assertOrThrow( res.successful() );
107 
108  assertOrThrow( fld->checkForObject( cryst ) != NULL );
109  assertOrThrow( fieldvisiblenow(view) == false );
110 
111  assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
112  assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
113  assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
114  assertOrThrow ( game->actions.undo( createTestingContext( game.get() ) ).successful() ) ;
115 
116 }
117 
118 
120 {
121  auto_ptr<GameMap> game ( startMap("unittest-attack-view.map"));
122 
123  Vehicle* assault = game->getField(4,9)->vehicle;
124  assertOrThrow( assault != NULL );
125 
126  Vehicle* ari = game->getField(4,11)->vehicle;
127  assertOrThrow( ari != NULL );
128 
129  MapCoordinate r( 5, 8);
130  MapCoordinate j( 5,11);
131 
132  MapField* fld = game->getField( MapCoordinate(0,0));
133  assertOrThrow( fieldvisiblenow(fld) == true );
134 
135  attack( assault, r );
136 
137  assertOrThrow( fieldvisiblenow(fld) == true );
138 
139 
140  MapField* fld2 = game->getField( MapCoordinate(6,8));
141  assertOrThrow( fieldvisiblenow(fld2) == false );
142 
143  attack( ari, j );
144 
145  assertOrThrow( fieldvisiblenow(fld2) == true );
146 
147  ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
148  assertOrThrow( res.successful() );
149 
150  assertOrThrow( fieldvisiblenow(fld2) == false );
151 
152 }
153 
154 
155 void testAttack() {
156  testAttack3();
157  testAttack2();
158  testAttack1();
159 }
ItemRepositoryLoader< ObjectType > objectTypeRepository("objecttype")
void testCargoMovement(Vehicle *veh, int movement)
int getExperience_defensive() const
Definition: vehicle.cpp:258
void move(Vehicle *veh, const MapCoordinate &dest)
void testAttack1()
Definition: attacktest.cpp:18
void testAttack()
Definition: attacktest.cpp:155
#define assertOrThrow(expr)
Definition: errors.h:69
Context createTestingContext(GameMap *gamemap)
a single field of the map
Definition: mapfield.h:26
void testAttack3()
Definition: attacktest.cpp:119
bool fieldvisiblenow(const MapField *pe, Vehicle *veh, int player)
{@
Definition: spfst.cpp:399
An object that can be placed on fields. Roads, pipelines and ditches are examples of objects...
Definition: objecttype.h:30
Coordinate on the twodimensional map.
Definition: typen.h:202
GameMap * startMap(const ASCString &filename)
bool successful() const
void attack(Vehicle *veh, const MapCoordinate &target)
Object * checkForObject(const ObjectType *o)
checks if there are objects from the given type on the field and returns them
Definition: mapfield.cpp:648
int getMovement(bool checkFuel=true, bool checkRF=true) const
returns the movement points the unit has left for this turn. CheckFuel should almost always be true...
Definition: vehicle.cpp:558
int getExperience_offensive() const
Definition: vehicle.cpp:253
void testAttack2()
Definition: attacktest.cpp:71