Collection assignment can configured.
This commit is contained in:
parent
9e3c4a3875
commit
aaddeb0867
4 changed files with 69 additions and 11 deletions
|
@ -316,6 +316,14 @@ global void AiInit(Player* player)
|
|||
pai->Script=ait->Script;
|
||||
|
||||
player->Ai=pai;
|
||||
|
||||
pai->Collect[TimeCost]=0;
|
||||
pai->Collect[GoldCost]=50;
|
||||
pai->Collect[WoodCost]=50;
|
||||
pai->Collect[OilCost]=0;
|
||||
pai->Collect[OreCost]=0;
|
||||
pai->Collect[StoneCost]=0;
|
||||
pai->Collect[CoalCost]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -227,6 +227,7 @@ typedef struct _player_ai_ {
|
|||
int Reserve[MaxCosts]; /// Resources to keep in reserve
|
||||
int Used[MaxCosts]; /// Used resources
|
||||
int Needed[MaxCosts]; /// Needed resources
|
||||
int Collect[MaxCosts]; /// Collect % of resources
|
||||
int NeededMask; /// Mask for needed resources
|
||||
|
||||
int NeedFood; /// Flag need food
|
||||
|
|
|
@ -1059,15 +1059,17 @@ local void AiCollectResources(void)
|
|||
int n;
|
||||
Unit** units;
|
||||
Unit* unit;
|
||||
int p[MaxCosts] = { 0, 50, 50, 0 };
|
||||
int pt = 100;
|
||||
int p[MaxCosts];
|
||||
int pt;
|
||||
|
||||
//
|
||||
// Collect statistics about the current assignment
|
||||
//
|
||||
pt = 100;
|
||||
for( i=0; i<MaxCosts; i++ ) {
|
||||
rn[i]=0;
|
||||
an[i]=0;
|
||||
p[i]=AiPlayer->Collect[i];
|
||||
if( (AiPlayer->NeededMask&(1<<i)) ) { // Double percent if needed
|
||||
pt+=p[i];
|
||||
p[i]<<=1;
|
||||
|
@ -1134,7 +1136,7 @@ local void AiCollectResources(void)
|
|||
for( j=0; j<tn; ++j ) {
|
||||
if( unit->Type==types[j] ) {
|
||||
if (unit->Orders[0].Action == UnitActionStill
|
||||
&& unit->OrderCount==1 ) {
|
||||
&& unit->OrderCount==1 && !unit->Removed ) {
|
||||
unassigned[un++]=unit;
|
||||
break;
|
||||
}
|
||||
|
@ -1163,7 +1165,7 @@ local void AiCollectResources(void)
|
|||
unit=unassigned[i];
|
||||
|
||||
for( o=c=0; c<MaxCosts; ++c ) {
|
||||
DebugLevel3Fn("%d, %d, %d\n",(an[c]+rn[c])*p[c],p[c],total*pt);
|
||||
DebugLevel3Fn("%d, %d, %d\n",(an[c]+rn[c])*pt,p[c],total*p[c]);
|
||||
if( (an[c]+rn[c])*pt<total*p[c] ) {
|
||||
o=c;
|
||||
break;
|
||||
|
@ -1194,18 +1196,21 @@ local void AiCollectResources(void)
|
|||
switch( c ) {
|
||||
case GoldCost:
|
||||
if( AiMineGold(unit) ) {
|
||||
DebugLevel0Fn("Assigned\n");
|
||||
assigned[an[c]++][c]=unit;
|
||||
++total;
|
||||
}
|
||||
break;
|
||||
case WoodCost:
|
||||
if( AiHarvest(unit) ) {
|
||||
DebugLevel3Fn("Assigned\n");
|
||||
assigned[an[c]++][c]=unit;
|
||||
++total;
|
||||
}
|
||||
break;
|
||||
case OilCost:
|
||||
if( AiHaulOil(unit) ) {
|
||||
DebugLevel0Fn("Assigned\n");
|
||||
assigned[an[c]++][c]=unit;
|
||||
++total;
|
||||
}
|
||||
|
@ -1217,6 +1222,28 @@ local void AiCollectResources(void)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Now look if too much workers are assigned to a resource
|
||||
// FIXME: If one resource can't be collected this is bad
|
||||
//
|
||||
#if 0
|
||||
for( c=0; c<MaxCosts; ++c ) {
|
||||
DebugLevel3Fn("%d, %d, %d\n",(an[c]+rn[c])*pt,p[c],total*p[c]);
|
||||
if( (an[c]+rn[c]-1)*pt>total*p[c] ) {
|
||||
for( i=0; i<an[c]; ++i ) {
|
||||
unit=assigned[i][c];
|
||||
if( unit->SubAction<64 ) {
|
||||
DebugLevel3Fn("Must deassign %d\n",c);
|
||||
CommandStopUnit(unit);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#else
|
||||
int c;
|
||||
int i;
|
||||
|
|
|
@ -120,7 +120,7 @@ local void PrintAiHelperTable(void)
|
|||
#endif
|
||||
|
||||
/**
|
||||
** Define helper for Ai.
|
||||
** Define helper for AI.
|
||||
**
|
||||
** @param list List of all helpers.
|
||||
**
|
||||
|
@ -297,7 +297,7 @@ local SCM CclDefineAiHelper(SCM list)
|
|||
}
|
||||
|
||||
/**
|
||||
** Define an Ai engine.
|
||||
** Define an AI engine.
|
||||
*/
|
||||
local SCM CclDefineAi(SCM list)
|
||||
{
|
||||
|
@ -380,7 +380,7 @@ local SCM CclDefineAi(SCM list)
|
|||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
-- Ai script functions
|
||||
-- AI script functions
|
||||
----------------------------------------------------------------------------*/
|
||||
|
||||
/// Get unit-type.
|
||||
|
@ -800,7 +800,7 @@ local SCM CclAiUpgradeTo(SCM value)
|
|||
}
|
||||
|
||||
/**
|
||||
** Simple restart the ai.
|
||||
** Simple restart the AI.
|
||||
*/
|
||||
local SCM CclAiRestart(void)
|
||||
{
|
||||
|
@ -830,7 +830,7 @@ local SCM CclAiPlayer(void)
|
|||
}
|
||||
|
||||
/**
|
||||
** Set ai player resource reserve.
|
||||
** Set AI player resource reserve.
|
||||
**
|
||||
** @param vec Resources vector
|
||||
** @return Old resource vector
|
||||
|
@ -850,6 +850,27 @@ local SCM CclAiSetReserve(SCM vec)
|
|||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
** Set AI player resource collect percent.
|
||||
**
|
||||
** @param vec Resources vector
|
||||
** @return Old resource vector
|
||||
*/
|
||||
local SCM CclAiSetCollect(SCM vec)
|
||||
{
|
||||
int i;
|
||||
SCM old;
|
||||
|
||||
old=cons_array(gh_int2scm(MaxCosts),NIL);
|
||||
for( i=0; i<MaxCosts; ++i ) {
|
||||
aset1(old,gh_int2scm(i),gh_int2scm(AiPlayer->Collect[i]));
|
||||
}
|
||||
for( i=0; i<MaxCosts; ++i ) {
|
||||
AiPlayer->Collect[i]=gh_scm2int(gh_vector_ref(vec,gh_int2scm(i)));
|
||||
}
|
||||
return old;
|
||||
}
|
||||
|
||||
/**
|
||||
** Dump some AI debug informations.
|
||||
*/
|
||||
|
@ -954,7 +975,7 @@ local SCM CclDefineAiWcNames(SCM list)
|
|||
#else
|
||||
|
||||
/**
|
||||
** Define helper for Ai.
|
||||
** Define helper for AI.
|
||||
*/
|
||||
local SCM CclDefineAiHelper(SCM list)
|
||||
{
|
||||
|
@ -962,7 +983,7 @@ local SCM CclDefineAiHelper(SCM list)
|
|||
}
|
||||
|
||||
/**
|
||||
** Define an Ai engine.
|
||||
** Define an AI engine.
|
||||
*/
|
||||
local SCM CclDefineAi(SCM list)
|
||||
{
|
||||
|
@ -1001,6 +1022,7 @@ global void AiCclRegister(void)
|
|||
|
||||
gh_new_procedure0_0("ai:player",CclAiPlayer);
|
||||
gh_new_procedure1_0("ai:set-reserve!",CclAiSetReserve);
|
||||
gh_new_procedure1_0("ai:set-collect!",CclAiSetCollect);
|
||||
|
||||
gh_new_procedure0_0("ai:dump",CclAiDump);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue