Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

strategy.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002                           strategy.cpp  -  description
00003                              -------------------
00004     begin                : Fri Mar 30 2001
00005     copyright            : (C) 2001 by Martin Bickel
00006     email                : bickel@asc-hq.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
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                int orgmovement = veh->getMovement();
00052                int orgxpos = veh->xpos ;
00053                int orgypos = veh->ypos ;
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 ) ) {  // the unit still lives
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 }

Generated on Tue Jun 24 01:27:52 2008 for Advanced Strategic Command by  doxygen 1.4.2