ai-service1.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   This program is free software; you can redistribute it and/or modify  *
00004  *   it under the terms of the GNU General Public License as published by  *
00005  *   the Free Software Foundation; either version 2 of the License, or     *
00006  *   (at your option) any later version.                                   *
00007  *                                                                         *
00008  ***************************************************************************/
00009 
00010 #include <iostream>
00011 
00012 #include "ai-service1.h"
00013 #include "../loaders.h"
00014 #include "unittestutil.h"
00015 #include "../turncontrol.h"
00016 #include "../gamemap.h"
00017 
00018 void testAiService1() 
00019 {
00020    auto_ptr<GameMap> game ( startMap("unittest-ai-refuel1.map"));
00021    
00022    Vehicle* veh = game->getField(2,10)->vehicle;
00023    
00024    assertOrThrow( veh != NULL );
00025    assertOrThrow( veh->damage == 0 );
00026    
00027    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00028    
00029    assertOrThrow( veh->damage > 0 );
00030    int damage = veh->damage;
00031    
00032    /* the ammo of the attacking unit is exhausted. 
00033       The AI should service it with the service unit nearby */
00034    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00035    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00036    
00037    assertOrThrow( veh->damage > damage );
00038    
00039 }
00040 
00041 
00042 void testAiService2() 
00043 {
00044    auto_ptr<GameMap> game ( startMap("unittest-ai-refuel2.map"));
00045    
00046    Vehicle* veh = game->getField(4,6)->vehicle;
00047    
00048    assertOrThrow( veh != NULL );
00049    assertOrThrow( veh->getResource( Resources(0,0,100)).fuel <= 1 );
00050    
00051    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00052    next_turn( game.get(), NextTurnStrategy_Abort(), NULL, -1 );
00053    
00054    assertOrThrow( veh->getResource( Resources(0,0,100)).fuel >= 100 );
00055    
00056 }
00057 
00058 
00059 void testAiService() 
00060 {
00061    testAiService1();
00062    testAiService2();
00063 }

Generated on Mon May 14 01:31:39 2012 for Advanced Strategic Command by  doxygen 1.5.1