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