- bugfix for AI units that do nothing when resources exist in the tech that the unit cannot harvest. (thanks RealtimeFreak for pointing this out and giving me a demo tech for testing)

- bugfix for restoring saved game settings (ignore closed slots that have faction set to random)
This commit is contained in:
Mark Vejvoda 2010-09-29 04:38:41 +00:00
parent c9f8433d83
commit 80051e3194
3 changed files with 52 additions and 40 deletions

View File

@ -19,6 +19,7 @@
#include "unit.h"
#include "program.h"
#include "config.h"
#include <limits>
#include "leak_dumper.h"
using namespace Shared::Graphics;
@ -185,20 +186,29 @@ float Ai::getRatioOfClass(UnitClass uc){
}
}
const ResourceType *Ai::getNeededResource(){
const ResourceType *Ai::getNeededResource(int unitIndex) {
int amount= -1;
int amount = numeric_limits<int>::max();
const ResourceType *neededResource= NULL;
const TechTree *tt= aiInterface->getTechTree();
for(int i = 0; i < tt->getResourceTypeCount(); ++i) {
const ResourceType *rt= tt->getResourceType(i);
const Resource *r= aiInterface->getResource(rt);
if(rt->getClass()!=rcStatic && rt->getClass()!=rcConsumable && (r->getAmount()<amount || amount==-1)){
if( rt->getClass() != rcStatic && rt->getClass() != rcConsumable &&
r->getAmount() < amount) {
// Now MAKE SURE the unit has a harvest command for this resource
// AND that the resource is within eye-sight to avoid units
// standing around doing nothing.
const HarvestCommandType *hct= aiInterface->getMyUnit(unitIndex)->getType()->getFirstHarvestCommand(rt);
Vec2i resPos;
if(hct != NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos)) {
amount= r->getAmount();
neededResource= rt;
}
}
}
return neededResource;
}
@ -474,7 +484,7 @@ void Ai::returnBase(int unitIndex){
void Ai::harvest(int unitIndex) {
const ResourceType *rt= getNeededResource();
const ResourceType *rt= getNeededResource(unitIndex);
if(rt != NULL) {
const HarvestCommandType *hct= aiInterface->getMyUnit(unitIndex)->getType()->getFirstHarvestCommand(rt);

View File

@ -159,7 +159,7 @@ public:
int getCountOfClass(UnitClass uc);
float getRatioOfClass(UnitClass uc);
const ResourceType *getNeededResource();
const ResourceType *getNeededResource(int unitIndex);
bool isStableBase();
bool findPosForBuilding(const UnitType* building, const Vec2i &searchPos, Vec2i &pos);
bool findAbleUnit(int *unitIndex, CommandClass ability, bool idleOnly);

View File

@ -602,6 +602,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
// Check for random faction selection and choose the faction now
if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i);
@ -636,6 +637,7 @@ void MenuStateCustomGame::mouseClick(int x, int y, MouseButton mouseButton){
RandomCount++;
}
}
}
if(RandomCount > 0) {
needToSetChangedGameSettings = true;