int AIInterface::GetResourceRating(const MapPoint pt, AIJH::Resource res) const { //surface resource? if(res == AIJH::PLANTSPACE || res == AIJH::BORDERLAND || res == AIJH::WOOD || res == AIJH::STONES) { AIJH::Resource surfaceRes = GetSurfaceResource(pt); TerrainType t1 = gwb.GetNode(pt).t1, t2 = gwb.GetNode(pt).t2; if (surfaceRes == res || (res == AIJH::PLANTSPACE && surfaceRes == AIJH::NOTHING && TerrainData::IsVital(t1)) || (res == AIJH::BORDERLAND && (IsBorder(pt) || !IsOwnTerritory(pt)) && (TerrainData::IsUseable(t1) || TerrainData::IsUseable(t2)))) { return AIJH::RES_RADIUS[res]; } //another building using our "resource"? reduce rating! if(res == AIJH::WOOD && IsBuildingOnNode(pt, BLD_WOODCUTTER)) return -40; if(res == AIJH::PLANTSPACE && IsBuildingOnNode(pt, BLD_FORESTER)) return -40; } //so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing) else { if (GetSubsurfaceResource(pt) == res) return AIJH::RES_RADIUS[res]; } return 0; }
int AIInterface::CalcResourceValue(MapCoord x,MapCoord y,AIJH::Resource res,char direction,int lastval) const { int returnval=0; if(direction==-1) //calculate complete value from scratch (3n^2+3n+1) { for(MapCoord tx=gwb->GetXA(x,y,0), r=1;r<=AIJH::RES_RADIUS[res];tx=gwb->GetXA(tx,y,0),++r) { MapCoord tx2 = tx, ty2 = y; for(unsigned i = 2;i<8;++i) { for(MapCoord r2=0;r2<r;gwb->GetPointA(tx2,ty2,i%6),++r2) { //surface resource? if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES) { AIJH::Resource tres=GetSurfaceResource(tx2,ty2); unsigned char t1=gwb->GetNode(tx2,ty2).t1,t2=gwb->GetNode(tx2,ty2).t2; if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(tx2,ty2)||!IsOwnTerritory(tx2,ty2))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER)))) { returnval+=(AIJH::RES_RADIUS[res]); } //another building using our "resource"? reduce rating! if(res==AIJH::WOOD||res==AIJH::PLANTSPACE) { if((res==AIJH::WOOD&&IsBuildingOnNode(tx2,ty2,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(tx2,ty2,BLD_FORESTER))) returnval-=(40); } } //so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing) else { if (GetSubsurfaceResource(tx2,ty2)==res) { returnval+=(AIJH::RES_RADIUS[res]); } } } } } //add the center point value //surface resource? if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES) { AIJH::Resource tres=GetSurfaceResource(x,y); unsigned char t1=gwb->GetNode(x,y).t1,t2=gwb->GetNode(x,y).t2; if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(x,y)||!IsOwnTerritory(x,y))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER)))) { returnval+=(AIJH::RES_RADIUS[res]); } //another building using our "resource"? reduce rating! if(res==AIJH::WOOD||res==AIJH::PLANTSPACE) { if((res==AIJH::WOOD&&IsBuildingOnNode(x,y,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(x,y,BLD_FORESTER))) returnval-=(40); } } //so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing) else { if (GetSubsurfaceResource(x,y)==res) { returnval+=(AIJH::RES_RADIUS[res]); } } } else//calculate different nodes only (4n+2 ?anyways much faster) { returnval+=lastval; //add new points //first: go radius steps towards direction-1 MapCoord tx=x,ty=y; for(unsigned i=0;i<AIJH::RES_RADIUS[res];i++) gwb->GetPointA(tx,ty,(direction+5)%6); //then clockwise around at radius distance to get all new points for(int i = direction+1;i<(direction+3);++i) { //add 1 extra step on the second side we check to complete the side for(MapCoord r2=0;r2<AIJH::RES_RADIUS[res]||(r2<AIJH::RES_RADIUS[res]+1&&i==direction+2);++r2) { //surface resource? if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES) { AIJH::Resource tres=GetSurfaceResource(tx,ty); unsigned char t1=gwb->GetNode(tx,ty).t1,t2=gwb->GetNode(tx,ty).t2; if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(tx,ty)||!IsOwnTerritory(tx,ty))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER)))) { returnval+=(AIJH::RES_RADIUS[res]); } //another building using our "resource"? reduce rating! if(res==AIJH::WOOD||res==AIJH::PLANTSPACE) { if((res==AIJH::WOOD&&IsBuildingOnNode(tx,ty,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(tx,ty,BLD_FORESTER))) returnval-=(40); } } //so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing) else { if (GetSubsurfaceResource(tx,ty)==res) { returnval+=(AIJH::RES_RADIUS[res]); } } gwb->GetPointA(tx,ty,i%6); } } //now substract old points not in range of new point //go to old center point: tx=x; ty=y; gwb->GetPointA(tx,ty,(direction+3)%6); //next: go to the first old point we have to substract for(unsigned i=0;i<AIJH::RES_RADIUS[res];i++) gwb->GetPointA(tx,ty,(direction+2)%6); //now clockwise around at radius distance to remove all old points for(int i = direction+4;i<(direction+6);++i) { for(MapCoord r2=0;r2<AIJH::RES_RADIUS[res]||(r2<AIJH::RES_RADIUS[res]+1&&i==direction+5);++r2) { //surface resource? if(res==AIJH::PLANTSPACE||res==AIJH::BORDERLAND||res==AIJH::WOOD||res==AIJH::STONES) { AIJH::Resource tres=GetSurfaceResource(tx,ty); unsigned char t1=gwb->GetNode(tx,ty).t1,t2=gwb->GetNode(tx,ty).t2; if (tres==res||(res==AIJH::PLANTSPACE&&tres==AIJH::NOTHING&&t1!=TT_DESERT&&t1!=TT_MOUNTAINMEADOW&&t1!=TT_MOUNTAIN1&&t1!=TT_MOUNTAIN2&&t1!=TT_MOUNTAIN3&&t1!=TT_MOUNTAIN4)||(res==AIJH::BORDERLAND&&(IsBorder(tx,ty)||!IsOwnTerritory(tx,ty))&&((t1!=TT_SNOW&&t1!=TT_LAVA&&t1!=TT_SWAMPLAND&&t1!=TT_WATER)||(t2!=TT_SNOW&&t2!=TT_LAVA&&t2!=TT_SWAMPLAND&&t2!=TT_WATER)))) { returnval-=(AIJH::RES_RADIUS[res]); } //another building using our "resource"? reduce rating! if(res==AIJH::WOOD||res==AIJH::PLANTSPACE) { if((res==AIJH::WOOD&&IsBuildingOnNode(tx,ty,BLD_WOODCUTTER))||(res==AIJH::PLANTSPACE&&IsBuildingOnNode(tx,ty,BLD_FORESTER))) returnval+=(40); } } //so it's a subsurface resource or something we dont calculate (multiple,blocked,nothing) else { if (GetSubsurfaceResource(tx,ty)==res) { returnval-=(AIJH::RES_RADIUS[res]); } } gwb->GetPointA(tx,ty,i%6); } } } //if(returnval<0&&lastval>=0&&res==AIJH::BORDERLAND) //LOG.lprintf("AIInterface::CalcResourceValue - warning: negative returnvalue direction %i oldval %i\n", direction, lastval); return returnval; }