Пример #1
0
static void GetFromReservesShipsOfShipType(AITeam *team,ShipType shiptype,sdword equivvalue,sdword *numPointsLeftToGet)
{
    SelectCommand *selection;
    sdword i;
    Ship *ship;

    while (*numPointsLeftToGet > 0)
    {
        selection = aiCurrentAIPlayer->newships.selection;
        for (i=0;i<selection->numShips;i++)
        {
            ship = selection->ShipPtr[i];
            if (ship->staticinfo->shiptype == shiptype)
            {
                growSelectRemoveShipIndex(&aiCurrentAIPlayer->newships,i);
                aitAddShip(team,ship);
                *numPointsLeftToGet -= equivvalue;
                goto foundship;
            }
        }
        // no ships found, so return
        return;
foundship:;
    }
}
Пример #2
0
/*-----------------------------------------------------------------------------
    Name        : airAddedResourceCollector
    Description : called when a resource collector is added
    Inputs      :
    Outputs     :
    Return      :
----------------------------------------------------------------------------*/
void airAddedResourceCollector(Ship *ship)
{
    Resource *resource;
    SelectCommand selectone;
    udword new_team_num = aiCurrentAIPlayer->numSupportTeams;
    AITeam *team;

    growSelectAddShip(&aiCurrentAIPlayer->airResourceCollectors, ship);

    aiCurrentAIPlayer->airNumRCollectors++;
    if (aiCurrentAIPlayer->NumRCollectorsBeingBuilt > 0) aiCurrentAIPlayer->NumRCollectorsBeingBuilt--;

    if (aiuResourceFeatureEnabled(AIR_ACTIVE_RESOURCE_COLLECTION))
    {
        //add the resource collector to an existing team, or make a new team
        team = aitFindNextTeamWithFlag(NULL, RESOURCECOLLECT_TEAM);

        while (team)
        {
            if (team->shipList.selection->numShips < 3)
            {
                aitAddShip(team, ship);
                break;
            }
            team = aitFindNextTeamWithFlag(team, RESOURCECOLLECT_TEAM);
        }

        if (!team)
        {
            team = aiCurrentAIPlayer->supportTeam[new_team_num] = aitCreate(ResourceTeam);
            bitSet(aiCurrentAIPlayer->supportTeam[new_team_num]->teamFlags, RESOURCECOLLECT_TEAM);
            growSelectAddShip(&aiCurrentAIPlayer->supportTeam[new_team_num]->shipList, ship);
            aioCreateResourcer(aiCurrentAIPlayer->supportTeam[new_team_num]);
            aiCurrentAIPlayer->numSupportTeams++;
        }
        if (aiuResourceFeatureEnabled(AIR_AGGRESSIVE_RESOURCING))
        {
            aiuWrapSetTactics(team->shipList.selection, Aggressive);
        }
    }
    else
    {
        resource = univFindNearestResource(ship, 0, NULL);

        selectone.numShips = 1;
        selectone.ShipPtr[0] = ship;

        if (aiuResourceFeatureEnabled(AIR_AGGRESSIVE_RESOURCING))
        {
            aiuWrapSetTactics(&selectone, Aggressive);
        }
        aiuWrapCollectResource(&selectone,resource);
    }
}
Пример #3
0
void aioCreateFancyTakeoutTarget(struct AITeam *team,Ship *target)
{
    ShipStaticInfo *shipsToBuy;
    sdword numShipsToBuy;
    SelectCommand *selectone;
    bool goodEnough;
    AITeam *secondaryteam;
    SelectCommand *nearbydangerousships;
    AITeamMove *move;

    // check reserves first:
    SelectCommand *useTheseShips = statsBestShipsToUseToKillTarget(aiCurrentAIPlayer->newships.selection,target->staticinfo,&goodEnough);

    aiplayerLog((aiIndex, "%x Issuing Fancy Takeout Target Order - Target %i", target->shiptype, team));

    if (goodEnough)
    {
treatasgoodenoughfancy:;
        if (useTheseShips)
        {
            // let's put useTheseShips into the team from reserve
            sdword i;
            Ship *ship;
            sdword numShips = useTheseShips->numShips;

            for (i=0;i<numShips;i++)
            {
                ship = useTheseShips->ShipPtr[i];

                growSelectRemoveShip(&aiCurrentAIPlayer->newships,ship);
                aitAddShip(team,ship);
            }
        }
    }
    else
    {
        Ship *playerMothership = aiCurrentAIPlayer->player->PlayerMothership;
        ShipRace race;
        if (playerMothership == NULL)
        {
            aiplayerLog((aiIndex, "Warning: could not build ships to takeout target"));
            goto treatasgoodenoughfancy;
        }

        race = playerMothership->shiprace;
        if ((race == P3) || (race == Traders))
        {
            aiplayerLog((aiIndex, "Warning: Pirates3Traders could not build ships to takeout target"));
            goto treatasgoodenoughfancy;
        }

        // we have to build them
        if (aiCurrentAIPlayer->player->PlayerMothership->shiptype == Mothership)
        {
            shipsToBuy = statsBestShipToBuyToKillShip(race,statShipConstraintsFightingShipsCB,target->staticinfo);
        }
        else
        {
            shipsToBuy = statsBestShipToBuyToKillShip(race,statShipConstraintsCarrierFightingShipsCB,target->staticinfo);
        }
        dbgAssert(shipsToBuy);
        numShipsToBuy = statsNumShipsNeededToKillTarget(shipsToBuy,target->staticinfo);

        if (numShipsToBuy == 0)
        {
            // we don't know what ships to buy, so just arbitrarily pick some.
            switch (race)
            {
                case R1:
                case R2:
                    shipsToBuy = GetShipStaticInfo(StandardFrigate,race);
                    break;

                case P1:
                    shipsToBuy = GetShipStaticInfo(P1MissileCorvette,race);
                    break;
                case P2:
                    shipsToBuy = GetShipStaticInfo(P2AdvanceSwarmer,race);
                    break;

                default:
                    dbgAssert(FALSE);
            }
            numShipsToBuy = 1;
            aiplayerLog((aiIndex,"Taking out unknown target %d.  Guessing on ship to use",target->shiptype));
        }

        aiplayerLog((aiIndex,"Taking out with %i of shiptype %i", numShipsToBuy, shipsToBuy->shiptype));
        aimCreateGetShips(team, shipsToBuy->shiptype, (sbyte)numShipsToBuy, 0, TRUE, FALSE);
    }

    if (useTheseShips != NULL)
    {
        memFree(useTheseShips);
    }

    // we now have primary team.  Do we need a secondary team?

    nearbydangerousships = aiuFindNearbyDangerousEnemyShips(target,1600.0f);

    if (nearbydangerousships->numShips == 0)
    {
nosecondaryteamnecessary:
        {
        AITeamMove *attackmove;

//        aimCreateFormation(team, BROAD_FORMATION, FALSE, FALSE);

        aimCreateVarDec(team, aiCurrentAIPlayer->attackVarLabel, TRUE, FALSE);
//        aimCreateVarWait(team, aiCurrentAIPlayer->attackVarLabel, -1, TRUE, FALSE);
        aimCreateTempGuard(team, AIO_TOUT_TARG_FANCY_TGRD_FORMATION, AIO_TOUT_TARG_FANCY_TGRD_TACTICS, TRUE, FALSE);

//        aimCreateFormation(team, BROAD_FORMATION, FALSE, FALSE);

        selectone = memAlloc(sizeofSelectCommand(1),"takeoutsel",0);
        selectone->numShips = 1;
        selectone->ShipPtr[0] = target;
        attackmove = aimCreateAttack(team, selectone, BROAD_FORMATION, TRUE, FALSE);
        aieHandlerSetGettingRocked(attackmove, TRUE, aihGenericGettingRockedHandler);
        aieHandlerSetFuelLow(attackmove, 15, TRUE, TRUE, aihGenericFuelLowHandler);

        aimCreateMoveDone(team, FALSE, FALSE);
        }
    }
    else
    {
        AIVar *Var0;
        AIVar *Var1;
        sdword secondary_num_ships_to_buy;
        ShipStaticInfo *secondary_ships_to_buy;
        char label[AIVAR_LABEL_MAX_LENGTH+1];

        if (aiCurrentAIPlayer->player->PlayerMothership && (aiCurrentAIPlayer->player->PlayerMothership->shiptype == Mothership))
        {
            secondary_ships_to_buy = statsBestShipToBuyToKillFleet(aiCurrentAIPlayer->player->race,statShipConstraintsFightingShipsCB,nearbydangerousships);
        }
        else
        {
            secondary_ships_to_buy = statsBestShipToBuyToKillFleet(aiCurrentAIPlayer->player->race,statShipConstraintsCarrierFightingShipsCB,nearbydangerousships);
        }

        secondary_num_ships_to_buy = statsNumShipsNeededToKillFleet(secondary_ships_to_buy,nearbydangerousships);

        if (secondary_num_ships_to_buy == 0)
        {
            goto nosecondaryteamnecessary;
        }

        if (secondary_num_ships_to_buy > 20)
        {
            secondary_ships_to_buy = statsBestShipToBuyToKillFleet(aiCurrentAIPlayer->player->race,statShipConstraintsFrigatesOrBetterCB,
                                                                   nearbydangerousships);

            secondary_num_ships_to_buy = statsNumShipsNeededToKillFleet(secondary_ships_to_buy,nearbydangerousships);

            if (secondary_num_ships_to_buy == 0)
            {
                goto nosecondaryteamnecessary;
            }

            if (secondary_num_ships_to_buy > 20)
            {
                secondary_num_ships_to_buy = 20;
            }
        }

        secondaryteam = aitCreate(team->teamType);
        secondaryteam->cooperatingTeam = team;

        Var0 = aivarCreate(aivarLabelGenerate(label));
        aivarValueSet(Var0, 0);

        Var1 = aivarCreate(aivarLabelGenerate(label));
        aivarValueSet(Var1, 0);

        aimCreateGetShips(secondaryteam, secondary_ships_to_buy->shiptype, (sbyte)secondary_num_ships_to_buy, 0, TRUE, FALSE);

        aimCreateVarSet(secondaryteam, aivarLabelGet(Var1), TRUE, FALSE, FALSE);

        move = aimCreateVarWait(secondaryteam, aivarLabelGet(Var0), TRUE, TRUE, FALSE);
        aieHandlerSetTeamDied(move, aihRemoveTeamDiedHandler);

        aimCreateVarDestroy(secondaryteam, aivarLabelGet(Var0), FALSE, FALSE);

//        aimCreateFormation(secondaryteam, SPHERE_FORMATION, FALSE, FALSE);

        move = aimCreateGuardCooperatingTeam(secondaryteam, FALSE, FALSE);
        aieHandlerSetFuelLow(move, 15, TRUE, TRUE, aihGenericFuelLowHandler);

        aimCreateMoveDone(secondaryteam, FALSE, FALSE);


//        aimCreateFormation(team, BROAD_FORMATION, FALSE, FALSE);

        aimCreateVarSet(team, aivarLabelGet(Var0), TRUE, FALSE, FALSE);

        move = aimCreateVarWait(team, aivarLabelGet(Var1), TRUE, TRUE, FALSE);
        aieHandlerSetTeamDied(move, aihRemoveTeamDiedHandler);

        aimCreateVarDestroy(team, aivarLabelGet(Var1), FALSE, FALSE);

        aimCreateVarDec(team, aiCurrentAIPlayer->attackVarLabel, TRUE, FALSE);
//        aimCreateVarWait(team, aiCurrentAIPlayer->attackVarLabel, -1, TRUE, FALSE);
        aimCreateTempGuard(team, AIO_TOUT_TARG_FANCY_TGRD_FORMATION, AIO_TOUT_TARG_FANCY_TGRD_TACTICS, TRUE, FALSE);

//        aimCreateFormation(team, BROAD_FORMATION, FALSE, FALSE);

        selectone = memAlloc(sizeofSelectCommand(1),"takeoutsel",0);
        selectone->numShips = 1;
        selectone->ShipPtr[0] = target;
        move = aimCreateAttack(team, selectone, BROAD_FORMATION, TRUE, FALSE);
        aieHandlerSetFuelLow(move, 15, TRUE, TRUE, aihGenericFuelLowHandler);

        aimCreateMoveDone(team, FALSE, FALSE);
    }

    aiumemFree(nearbydangerousships);
}
Пример #4
0
void aioCreateTakeoutTarget(struct AITeam *team,Ship *target)
{
    ShipStaticInfo *shipsToBuy;
    sdword numShipsToBuy;
    SelectCommand *selectone;
    bool goodEnough;
    AITeamMove *attackmove;

    // check reserves first:
    SelectCommand *useTheseShips = statsBestShipsToUseToKillTarget(aiCurrentAIPlayer->newships.selection,target->staticinfo,&goodEnough);

    aiplayerLog((aiIndex, "%x Issuing Takeout Target Order - Target Type %i", target->shiptype, team));

    if (goodEnough)
    {
treatasgoodenough:;
        if (useTheseShips)
        {
            // let's put useTheseShips into the team from reserve
            sdword i;
            Ship *ship;
            sdword numShips = useTheseShips->numShips;

            for (i=0;i<numShips;i++)
            {
                ship = useTheseShips->ShipPtr[i];

                growSelectRemoveShip(&aiCurrentAIPlayer->newships,ship);
                aitAddShip(team,ship);
            }
        }
    }
    else
    {
        Ship *playerMothership = aiCurrentAIPlayer->player->PlayerMothership;
        ShipRace race;
        if (playerMothership == NULL)
        {
            aiplayerLog((aiIndex, "Warning: could not build ships to takeout target"));
            goto treatasgoodenough;
        }

        race = playerMothership->shiprace;
        if ((race == P3) || (race == Traders))
        {
            aiplayerLog((aiIndex, "Warning: Pirates3Traders could not build ships to takeout target"));
            goto treatasgoodenough;
        }

        // we have to build them
        if (aiCurrentAIPlayer->player->PlayerMothership->shiptype == Mothership)
        {
            shipsToBuy = statsBestShipToBuyToKillShip(race,statShipConstraintsFightingShipsCB,target->staticinfo);
        }
        else
        {
            shipsToBuy = statsBestShipToBuyToKillShip(race,statShipConstraintsCarrierFightingShipsCB,target->staticinfo);
        }
        dbgAssert(shipsToBuy);
        numShipsToBuy = statsNumShipsNeededToKillTarget(shipsToBuy,target->staticinfo);

        if (numShipsToBuy == 0)
        {
            // we don't know what ships to buy, so just arbitrarily pick some.
            switch (race)
            {
                case R1:
                case R2:
                    shipsToBuy = GetShipStaticInfo(StandardFrigate,race);
                    break;

                case P1:
                    shipsToBuy = GetShipStaticInfo(P1MissileCorvette,race);
                    break;
                case P2:
                    shipsToBuy = GetShipStaticInfo(P2AdvanceSwarmer,race);
                    break;

                default:
                    dbgAssert(FALSE);
            }
            numShipsToBuy = 1;
            aiplayerLog((aiIndex,"Taking out unknown target %d.  Guessing on ship to use",target->shiptype));
        }

        aiplayerLog((aiIndex,"Taking out with %i of shiptype %i", numShipsToBuy, shipsToBuy->shiptype));
        aimCreateGetShips(team, shipsToBuy->shiptype, (sbyte)numShipsToBuy, 0, TRUE, FALSE);
    }

    if (useTheseShips != NULL)
    {
        memFree(useTheseShips);
    }

    aimCreateVarDec(team, aiCurrentAIPlayer->attackVarLabel, TRUE, FALSE);
//    aimCreateVarWait(team, aiCurrentAIPlayer->attackVarLabel, -1, TRUE, FALSE);
    aimCreateTempGuard(team, AIO_TOUT_TARG_TGUARD_FORMATION, AIO_TOUT_TARG_TGUARD_TACTICS, TRUE, FALSE);

    selectone = memAlloc(sizeofSelectCommand(1),"takeoutsel",0);
    selectone->numShips = 1;
    selectone->ShipPtr[0] = target;
    attackmove = aimCreateAttack(team, selectone, BROAD_FORMATION, TRUE, FALSE);
    aieHandlerSetGettingRocked(attackmove, TRUE, aihGenericGettingRockedHandler);
    aieHandlerSetFuelLow(attackmove, 15, TRUE, TRUE, aihGenericFuelLowHandler);
    aimCreateMoveDone(team, FALSE, FALSE);
}