1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
|
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <iostream>
#include "../actions/moveunitcommand.h"
#include "../loaders.h"
#include "../itemrepository.h"
#include "unittestutil.h"
void testMovement1()
{
auto_ptr<GameMap> game ( startMap("unittest-movement.map"));
Vehicle* veh = game->getField(0,0)->vehicle;
assertOrThrow( veh->getMovement() == 100 );
move( veh, MapCoordinate(5,10));
assertOrThrow( veh->getMovement() == 0 );
testCargoMovement( veh, 50 );
ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
assertOrThrow( res.successful() );
assertOrThrow( veh->getMovement() == 100 );
testCargoMovement( veh, 100 );
move(veh, MapCoordinate(0,1));
move(veh, MapCoordinate(1,2));
move(veh, MapCoordinate(1,3));
move(veh, MapCoordinate(2,4));
move(veh, MapCoordinate(2,5));
move(veh, MapCoordinate(3,6));
move(veh, MapCoordinate(3,7));
move(veh, MapCoordinate(4,8));
move(veh, MapCoordinate(4,9));
move(veh, MapCoordinate(5,10));
assertOrThrow( veh->getMovement() == 0 );
testCargoMovement( veh, 50 );
}
void testMovementRF()
{
auto_ptr<GameMap> game ( startMap("unittest-reactionfire.map"));
Vehicle* veh = game->getField(4,2)->vehicle;
assertOrThrow( veh != NULL );
move( veh, MapCoordinate(4,3));
assertOrThrow( veh->damage == 0 );
move( veh, MapCoordinate(5,4));
assertOrThrow( veh->damage > 50 );
}
void testMovementTracks()
{
auto_ptr<GameMap> game ( startMap("unittest-objectgeneration.map"));
Vehicle* veh = game->getField(4,9)->vehicle;
assertOrThrow( veh != NULL );
move( veh, MapCoordinate(6,12));
ObjectType* track = objectTypeRepository.getObject_byID( 7 );
assertOrThrow( game->getField(4,9)->checkForObject( track) != NULL );
assertOrThrow( game->getField(5,10)->checkForObject( track) == NULL );
ActionResult res = game->actions.undo( createTestingContext( game.get() ) );
assertOrThrow( res.successful() );
assertOrThrow( game->getField(4,9)->checkForObject( track) == NULL );
assertOrThrow( game->getField(5,10)->checkForObject( track) == NULL );
}
void testHeightChangeAI()
{
auto_ptr<GameMap> game ( startMap("unittest-heightchange.map"));
Vehicle* veh = game->getField(4,17)->vehicle;
assertOrThrow( veh != NULL );
auto_ptr<MoveUnitCommand> muc ( new MoveUnitCommand( veh ));
// this is the AI way of doing things, selecting a 3D coordinate as destination
MapCoordinate3D dest( 6,10,1<<5 );
assertOrThrow( muc->isFieldReachable3D( dest, true ));
muc->setDestination( dest );
ActionResult res = muc->execute( createTestingContext( veh->getMap() ));
if ( res.successful() )
muc.release();
else
throw ActionResult(res);
assertOrThrow( veh->height == 32 );
}
void testHeightChangeGUI()
{
auto_ptr<GameMap> game ( startMap("unittest-heightchange.map"));
Vehicle* veh = game->getField(4,17)->vehicle;
assertOrThrow( veh != NULL );
auto_ptr<MoveUnitCommand> muc ( new MoveUnitCommand( veh ));
// this is the GUI way of doing things, selecting a 2D coordinate as destination
MapCoordinate dest( 6,10 );
muc->searchFields();
assertOrThrow( muc->isFieldReachable( dest, true ));
muc->setDestination( dest );
ActionResult res = muc->execute( createTestingContext( veh->getMap() ));
if ( res.successful() )
muc.release();
else
throw ActionResult(res);
assertOrThrow( veh->height == 16 ); // because low level flight can be reached with less movement consumption
}
void testMovementFieldsReachable()
{
auto_ptr<GameMap> game ( startMap("unittest-moveback.map"));
Vehicle* veh = game->getField(15,31)->vehicle;
assertOrThrow( veh != NULL );
auto_ptr<MoveUnitCommand> muc ( new MoveUnitCommand( veh ));
muc->searchFields();
const set<MapCoordinate3D>& fields = muc->getReachableFields();
for ( set<MapCoordinate3D>::const_iterator i = fields.begin(); i != fields.end(); ++i ) {
auto_ptr<MoveUnitCommand> m2 ( new MoveUnitCommand( veh ));
m2->setDestination( *i );
ActionResult res = m2->execute( createTestingContext( veh->getMap() ));
assertOrThrow( res.successful() );
m2.release();
res = game->actions.undo( createTestingContext( game.get() ));
assertOrThrow( res.successful() );
}
}
void testMovement()
{
testMovementFieldsReachable();
testMovement1();
testMovementRF();
testMovementTracks();
testHeightChangeAI();
testHeightChangeGUI();
}
|