00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include "ai_common.h"
00021
00022 #include "../actions/moveunitcommand.h"
00023
00024
00025 void AI::findStratPath ( vector<MapCoordinate>& path, Vehicle* veh, int x, int y )
00026 {
00027 StratAStar stratAStar ( this, veh );
00028 stratAStar.findPath ( AStar::HexCoord ( veh->xpos, veh->ypos ), AStar::HexCoord ( x, y ), path );
00029 }
00030
00031 int aiDebugInterruptHelper = -1;
00032
00033 AI::AiResult AI::strategy( void )
00034 {
00035 AiResult result;
00036
00037
00038
00039 map<MapCoordinate,int> destinationCounter;
00040
00041 int stratloop = 0;
00042 AiResult localResult;
00043 do {
00044 localResult.unitsMoved = 0;
00045 localResult.unitsWaiting = 0;
00046 stratloop++;
00047
00048 int counter = 0;
00049
00050 vector<int> units;
00051 for ( Player::VehicleList::iterator vi = getPlayer().vehicleList.begin(); vi != getPlayer().vehicleList.end(); ++vi )
00052 units.push_back( (*vi)->networkid );
00053
00054 for ( vector<int>::iterator vi = units.begin(); vi != units.end(); ++vi ) {
00055 Vehicle* veh = getMap()->getUnit(*vi);
00056 if ( veh ) {
00057 ++counter;
00058
00059 if ( unitsWorkedInTactics.find( veh) != unitsWorkedInTactics.end() )
00060 continue;
00061
00062 if ( veh->aiparam[ getPlayerNum() ]->getJob() == AiParameter::job_fight ) {
00063 if ( veh->weapexist() && veh->aiparam[ getPlayerNum() ]->getTask() != AiParameter::tsk_tactics
00064 && veh->aiparam[ getPlayerNum() ]->getTask() != AiParameter::tsk_serviceRetreat ) {
00065
00066
00067
00068
00069
00070
00071 if ( veh->networkid == aiDebugInterruptHelper ) {
00072 cout << "debug point hit with unit " << aiDebugInterruptHelper << " \n";
00073 }
00074
00075 if ( MoveUnitCommand::avail ( veh )) {
00076 MapCoordinate3D dest;
00077
00078 AI::Section* sec = sections.getBest ( 0, veh, &dest, true, false, &destinationCounter );
00079 if ( sec ) {
00080 if( stratloop < 3 )
00081 destinationCounter[dest]+=1;
00082
00083 int nwid = veh->networkid;
00084 int movement = veh->getMovement();
00085 moveUnit ( veh, dest, false, false );
00086
00087 if ( getMap()->getUnit(nwid)) {
00088 AiParameter& aip = *veh->aiparam[getPlayerNum()];
00089
00090 aip.dest = dest;
00091 if ( getMap()->getUnit(nwid)->getMovement() < movement )
00092 localResult.unitsMoved++;
00093 } else
00094 localResult.unitsMoved++;
00095 }
00096 }
00097 }
00098 } else {
00099 int nwid = veh->networkid;
00100 if ( runUnitTask ( veh ) )
00101 if ( getMap()->getUnit( nwid ) ) {
00102 if ( veh->aiparam[getPlayerNum()]->resetAfterJobCompletion )
00103 veh->aiparam[getPlayerNum()]->reset( veh );
00104 }
00105 }
00106
00107 displaymessage2("strategy loop %d ; moved unit %d / %d ... ", stratloop, counter, localResult.unitsMoved );
00108
00109 checkKeys();
00110 }
00111 }
00112 result += localResult;
00113 } while ( localResult.unitsMoved );
00114
00115 displaymessage2("strategy completed ... ");
00116
00117 return result;
00118 }