- more AI fixes.
#1: AI does not try to harvest resources that the unit cannot yet harvest (could be an upgrade required) #2: AI no longer tries to expand near resources that they are not yet able to harvest. (found using RealtimeFreaks test mod and map). This makes for a more aggresive CPU in scenarios where there are additional resource types since they expand much more quickly.
This commit is contained in:
parent
468340403f
commit
02e0a1302f
|
@ -200,9 +200,9 @@ const ResourceType *Ai::getNeededResource(int unitIndex) {
|
||||||
// Now MAKE SURE the unit has a harvest command for this resource
|
// Now MAKE SURE the unit has a harvest command for this resource
|
||||||
// AND that the resource is within eye-sight to avoid units
|
// AND that the resource is within eye-sight to avoid units
|
||||||
// standing around doing nothing.
|
// standing around doing nothing.
|
||||||
const HarvestCommandType *hct= aiInterface->getMyUnit(unitIndex)->getType()->getFirstHarvestCommand(rt);
|
const HarvestCommandType *hct= aiInterface->getMyUnit(unitIndex)->getType()->getFirstHarvestCommand(rt,aiInterface->getMyUnit(unitIndex)->getFaction());
|
||||||
Vec2i resPos;
|
Vec2i resPos;
|
||||||
if(hct != NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos)) {
|
if(hct != NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos, false)) {
|
||||||
amount= r->getAmount();
|
amount= r->getAmount();
|
||||||
neededResource= rt;
|
neededResource= rt;
|
||||||
}
|
}
|
||||||
|
@ -486,9 +486,9 @@ void Ai::harvest(int unitIndex) {
|
||||||
const ResourceType *rt= getNeededResource(unitIndex);
|
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,aiInterface->getMyUnit(unitIndex)->getFaction());
|
||||||
Vec2i resPos;
|
Vec2i resPos;
|
||||||
if(hct != NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos)) {
|
if(hct != NULL && aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), resPos, false)) {
|
||||||
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");
|
||||||
|
|
|
@ -371,12 +371,27 @@ const TechTree *AiInterface::getTechTree(){
|
||||||
return world->getTechTree();
|
return world->getTechTree();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AiInterface::getNearestSightedResource(const ResourceType *rt, const Vec2i &pos, Vec2i &resultPos){
|
bool AiInterface::getNearestSightedResource(const ResourceType *rt, const Vec2i &pos,
|
||||||
float tmpDist;
|
Vec2i &resultPos, bool usableResourceTypeOnly) {
|
||||||
|
float tmpDist=0;
|
||||||
|
|
||||||
float nearestDist= infinity;
|
float nearestDist= infinity;
|
||||||
bool anyResource= false;
|
bool anyResource= false;
|
||||||
|
|
||||||
|
bool canUseResourceType = (usableResourceTypeOnly == false);
|
||||||
|
if(usableResourceTypeOnly == true) {
|
||||||
|
// can any unit harvest this resource yet?
|
||||||
|
for(int i = 0; i < getMyUnitCount(); ++i) {
|
||||||
|
const Unit *unit = getMyUnit(i);
|
||||||
|
const HarvestCommandType *hct= unit->getType()->getFirstHarvestCommand(rt,unit->getFaction());
|
||||||
|
if(hct != NULL) {
|
||||||
|
canUseResourceType = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(canUseResourceType == true) {
|
||||||
const Map *map= world->getMap();
|
const Map *map= world->getMap();
|
||||||
|
|
||||||
for(int i=0; i<map->getW(); ++i){
|
for(int i=0; i<map->getW(); ++i){
|
||||||
|
@ -399,6 +414,7 @@ bool AiInterface::getNearestSightedResource(const ResourceType *rt, const Vec2i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return anyResource;
|
return anyResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ public:
|
||||||
const Unit *getOnSightUnit(int unitIndex);
|
const Unit *getOnSightUnit(int unitIndex);
|
||||||
const FactionType *getMyFactionType();
|
const FactionType *getMyFactionType();
|
||||||
const TechTree *getTechTree();
|
const TechTree *getTechTree();
|
||||||
bool getNearestSightedResource(const ResourceType *rt, const Vec2i &pos, Vec2i &resultPos);
|
bool getNearestSightedResource(const ResourceType *rt, const Vec2i &pos, Vec2i &resultPos, bool usableResourceTypeOnly);
|
||||||
bool isAlly(const Unit *unit) const;
|
bool isAlly(const Unit *unit) const;
|
||||||
bool isAlly(int factionIndex) const;
|
bool isAlly(int factionIndex) const;
|
||||||
bool reqsOk(const RequirableType *rt);
|
bool reqsOk(const RequirableType *rt);
|
||||||
|
|
|
@ -1094,12 +1094,9 @@ bool AiRuleExpand::test(){
|
||||||
|
|
||||||
for(int i= 0; i<aiInterface->getTechTree()->getResourceTypeCount(); ++i){
|
for(int i= 0; i<aiInterface->getTechTree()->getResourceTypeCount(); ++i){
|
||||||
const ResourceType *rt = aiInterface->getTechTree()->getResourceType(i);
|
const ResourceType *rt = aiInterface->getTechTree()->getResourceType(i);
|
||||||
|
|
||||||
if(rt->getClass() == rcTech){
|
if(rt->getClass() == rcTech){
|
||||||
|
|
||||||
// If any resource sighted
|
// If any resource sighted
|
||||||
if(aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), expandPos)){
|
if(aiInterface->getNearestSightedResource(rt, aiInterface->getHomeLocation(), expandPos, true)) {
|
||||||
|
|
||||||
int minDistance= INT_MAX;
|
int minDistance= INT_MAX;
|
||||||
storeType= NULL;
|
storeType= NULL;
|
||||||
|
|
||||||
|
@ -1119,8 +1116,7 @@ bool AiRuleExpand::test(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(minDistance>expandDistance)
|
if(minDistance > expandDistance) {
|
||||||
{
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -930,7 +930,7 @@ const CommandType *Unit::computeCommandType(const Vec2i &pos, const Unit *target
|
||||||
//check harvest command
|
//check harvest command
|
||||||
Resource *resource= sc->getResource();
|
Resource *resource= sc->getResource();
|
||||||
if(resource!=NULL){
|
if(resource!=NULL){
|
||||||
commandType= type->getFirstHarvestCommand(resource->getType());
|
commandType= type->getFirstHarvestCommand(resource->getType(),this->getFaction());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "unit_particle_type.h"
|
#include "unit_particle_type.h"
|
||||||
|
#include "faction.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Xml;
|
using namespace Shared::Xml;
|
||||||
|
@ -434,10 +435,15 @@ const SkillType *UnitType::getFirstStOfClass(SkillClass skillClass) const{
|
||||||
return firstSkillTypeOfClass[skillClass];
|
return firstSkillTypeOfClass[skillClass];
|
||||||
}
|
}
|
||||||
|
|
||||||
const HarvestCommandType *UnitType::getFirstHarvestCommand(const ResourceType *resourceType) const{
|
const HarvestCommandType *UnitType::getFirstHarvestCommand(const ResourceType *resourceType, const Faction *faction) const {
|
||||||
for(int i = 0; i < commandTypes.size(); ++i) {
|
for(int i = 0; i < commandTypes.size(); ++i) {
|
||||||
if(commandTypes[i]->getClass() == ccHarvest) {
|
if(commandTypes[i]->getClass() == ccHarvest) {
|
||||||
const HarvestCommandType *hct = static_cast<const HarvestCommandType*>(commandTypes[i]);
|
const HarvestCommandType *hct = static_cast<const HarvestCommandType*>(commandTypes[i]);
|
||||||
|
|
||||||
|
if (faction->reqsOk(hct) == false) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(hct->canHarvest(resourceType)) {
|
if(hct->canHarvest(resourceType)) {
|
||||||
return hct;
|
return hct;
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ class UnitParticleSystemType;
|
||||||
class ResourceType;
|
class ResourceType;
|
||||||
class TechTree;
|
class TechTree;
|
||||||
class FactionType;
|
class FactionType;
|
||||||
|
class Faction;
|
||||||
|
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
|
@ -172,7 +173,7 @@ public:
|
||||||
const SkillType *getSkillType(const string &skillName, SkillClass skillClass) const;
|
const SkillType *getSkillType(const string &skillName, SkillClass skillClass) const;
|
||||||
const SkillType *getFirstStOfClass(SkillClass skillClass) const;
|
const SkillType *getFirstStOfClass(SkillClass skillClass) const;
|
||||||
const CommandType *getFirstCtOfClass(CommandClass commandClass) const;
|
const CommandType *getFirstCtOfClass(CommandClass commandClass) const;
|
||||||
const HarvestCommandType *getFirstHarvestCommand(const ResourceType *resourceType) const;
|
const HarvestCommandType *getFirstHarvestCommand(const ResourceType *resourceType,const Faction *faction) const;
|
||||||
const AttackCommandType *getFirstAttackCommand(Field field) const;
|
const AttackCommandType *getFirstAttackCommand(Field field) const;
|
||||||
const RepairCommandType *getFirstRepairCommand(const UnitType *repaired) const;
|
const RepairCommandType *getFirstRepairCommand(const UnitType *repaired) const;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue