Example #1
0
/**
**  Called when training of a unit is completed.
**
**  @param unit     Unit that trained the new unit.
**  @param newUnit  The new unit.
*/
void AiTrainingComplete(CUnit *unit, CUnit *newUnit)
{
	DebugPrint("%d: %d(%s) training %s at %d,%d completed\n" _C_
		unit->Player->Index _C_ UnitNumber(unit) _C_ unit->Type->Ident.c_str() _C_
		newUnit->Type->Ident.c_str() _C_ unit->X _C_ unit->Y);

	Assert(unit->Player->Type != PlayerPerson);

	AiRemoveFromBuilt(unit->Player->Ai, newUnit->Type);

	AiPlayer = unit->Player->Ai;
	AiCleanForces();
	AiAssignToForce(newUnit);
}
Example #2
0
/**
**	Assign free units to force.
*/
global void AiAssignFreeUnitsToForce(void)
{
    Unit* table[UnitMax];
    int n;
    int f;
    int i;
    Unit* unit;
    const AiUnit* aiunit;

    AiCleanForces();

    n=AiPlayer->Player->TotalNumUnits;
    memcpy(table,AiPlayer->Player->Units,sizeof(*AiPlayer->Player->Units)*n);

    //
    //	Remove all units already in forces.
    //
    for( f=0; f<AI_MAX_FORCES; ++f ) {
	aiunit=AiPlayer->Force[f].Units;
	while( aiunit ) {
	    unit=aiunit->Unit;
	    for( i=0; i<n; ++i ) {
		if( table[i]==unit ) {
		    table[i]=table[--n];
		}
	    }
	    aiunit=aiunit->Next;
	}
    }

    //
    //	Try to assign the remaining units.
    //
    for( i=0; i<n; ++i ) {
	if( table[i]->Active ) {
	    AiAssignToForce(table[i]);
	}
    }
}