- 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:
parent
c9f8433d83
commit
80051e3194
|
@ -19,6 +19,7 @@
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#include "program.h"
|
#include "program.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
#include <limits>
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Graphics;
|
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 ResourceType *neededResource= NULL;
|
||||||
const TechTree *tt= aiInterface->getTechTree();
|
const TechTree *tt= aiInterface->getTechTree();
|
||||||
|
|
||||||
for(int i=0; i<tt->getResourceTypeCount(); ++i){
|
for(int i = 0; i < tt->getResourceTypeCount(); ++i) {
|
||||||
const ResourceType *rt= tt->getResourceType(i);
|
const ResourceType *rt= tt->getResourceType(i);
|
||||||
const Resource *r= aiInterface->getResource(rt);
|
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();
|
amount= r->getAmount();
|
||||||
neededResource= rt;
|
neededResource= rt;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return neededResource;
|
return neededResource;
|
||||||
}
|
}
|
||||||
|
@ -472,14 +482,14 @@ void Ai::returnBase(int unitIndex){
|
||||||
//aiInterface->printLog(1, "Order return to base pos:" + intToStr(pos.x)+", "+intToStr(pos.y)+": "+rrToStr(r)+"\n");
|
//aiInterface->printLog(1, "Order return to base pos:" + intToStr(pos.x)+", "+intToStr(pos.y)+": "+rrToStr(r)+"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ai::harvest(int unitIndex){
|
void Ai::harvest(int unitIndex) {
|
||||||
|
|
||||||
const ResourceType *rt= getNeededResource();
|
const ResourceType *rt= getNeededResource(unitIndex);
|
||||||
|
|
||||||
if(rt!=NULL){
|
if(rt != NULL) {
|
||||||
const HarvestCommandType *hct= aiInterface->getMyUnit(unitIndex)->getType()->getFirstHarvestCommand(rt);
|
const HarvestCommandType *hct= aiInterface->getMyUnit(unitIndex)->getType()->getFirstHarvestCommand(rt);
|
||||||
Vec2i resPos;
|
Vec2i resPos;
|
||||||
if(hct!=NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos)){
|
if(hct != NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos)) {
|
||||||
resPos= resPos+Vec2i(random.randRange(-2, 2), random.randRange(-2, 2));
|
resPos= resPos+Vec2i(random.randRange(-2, 2), random.randRange(-2, 2));
|
||||||
aiInterface->giveCommand(unitIndex, hct, resPos);
|
aiInterface->giveCommand(unitIndex, hct, resPos);
|
||||||
//aiInterface->printLog(4, "Order harvest pos:" + intToStr(resPos.x)+", "+intToStr(resPos.y)+": "+rrToStr(r)+"\n");
|
//aiInterface->printLog(4, "Order harvest pos:" + intToStr(resPos.x)+", "+intToStr(resPos.y)+": "+rrToStr(r)+"\n");
|
||||||
|
|
|
@ -159,7 +159,7 @@ public:
|
||||||
int getCountOfClass(UnitClass uc);
|
int getCountOfClass(UnitClass uc);
|
||||||
float getRatioOfClass(UnitClass uc);
|
float getRatioOfClass(UnitClass uc);
|
||||||
|
|
||||||
const ResourceType *getNeededResource();
|
const ResourceType *getNeededResource(int unitIndex);
|
||||||
bool isStableBase();
|
bool isStableBase();
|
||||||
bool findPosForBuilding(const UnitType* building, const Vec2i &searchPos, Vec2i &pos);
|
bool findPosForBuilding(const UnitType* building, const Vec2i &searchPos, Vec2i &pos);
|
||||||
bool findAbleUnit(int *unitIndex, CommandClass ability, bool idleOnly);
|
bool findAbleUnit(int *unitIndex, CommandClass ability, bool idleOnly);
|
||||||
|
|
|
@ -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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
// Check for random faction selection and choose the faction now
|
// Check for random faction selection and choose the faction now
|
||||||
|
if(listBoxControls[i].getSelectedItemIndex() != ctClosed) {
|
||||||
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
if(listBoxFactions[i].getSelectedItem() == formatString(GameConstants::RANDOMFACTION_SLOTNAME)) {
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line %d] i = %d\n",__FILE__,__FUNCTION__,__LINE__,i);
|
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++;
|
RandomCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(RandomCount > 0) {
|
if(RandomCount > 0) {
|
||||||
needToSetChangedGameSettings = true;
|
needToSetChangedGameSettings = true;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user