//
//  return true iff there are no enemy ships within a certain radius of any of
//  the given team's ships.
//
sdword aieCheckEnemyNotNearby(AITeam *team)
{
//    blob *myblob;
    SelectCommand *ships = NULL;

    if (team->shipList.selection->numShips)
    {
        // must use less efficient, but guaranteed, enemy nearby
        ships = aiuFindNearbyEnemyShips(team->shipList.selection->ShipPtr[0],team->curMove->events.enemyNearby.watchRadius);

        // for efficiency, we assume all ships in the team and all
        // potential enemies are in the same blob -- an enhancement
        // later could be to select the most "central" ship instead
        // of the first one
//        myblob = aiuWrapGetCollBlob(team->shipList.selection);
//        if (!myblob) goto end;
//
//        ships.numShips = 0;
//        selSelectionCopy((MaxAnySelection *)&ships, (MaxAnySelection *)myblob->blobShips);
//        MakeTargetsOnlyEnemyShips((SelectAnyCommand *)&ships, aiCurrentAIPlayer->player);
//        MakeTargetsOnlyBeWithinRangeAndNotIncludeMe((SelectAnyCommand *)&ships, (SpaceObjRotImpTarg *)team->shipList.selection->ShipPtr[0], team->curMove->events.enemyNotNearby.watchRadius);
        if (ships->numShips)
        {
            aiumemFree(ships);
            return FALSE;
        }
    }

//  end:
    aiumemFree(ships);
    return TRUE;
}
//
//  return true iff there are enemy ships within a certain radius of any of
//  the given team's ships.
//  NOTE: this will allocate memory for ships iff true.
//
sdword aieCheckEnemyNearby(AITeam *team, SelectCommand **ships)
{
//    blob *myblob;

    if (team->shipList.selection->numShips)
    {
        // must use less efficient, but guaranteed, enemy nearby
        *ships = aiuFindNearbyEnemyShips(team->shipList.selection->ShipPtr[0],team->curMove->events.enemyNearby.watchRadius);

        // for efficiency, we assume all ships in the team and all
        // potential enemies are in the same blob -- an enhancement
        // later could be to select the most "central" ship instead
        // of the first one
            // NOTE: this method didn't work because blobs were too small.
//        myblob = aiuWrapGetCollBlob(team->shipList.selection);
//        if (!myblob) goto end;
//
//        *ships = selectDupSelection(myblob->blobShips);
//        aiuMakeShipsOnlyPrimaryEnemyShips((*ships));
//        MakeTargetsOnlyBeWithinRangeAndNotIncludeMe((SelectAnyCommand *)(*ships), (SpaceObjRotImpTarg *)(*ships)->ShipPtr[0], team->curMove->events.enemyNearby.watchRadius);
        if ((*ships)->numShips)
        {
            if (((*ships)->numShips <= 2) &&
                ((*ships)->ShipPtr[0]->shiptype == LightInterceptor))
            {
                goto end;
            }
            return TRUE;
        }
    }

  end:
    aiumemFree(*ships);
    return FALSE;
}
Exemple #3
0
//special move
sdword aimProcessSpecial(AITeam *team)
{
    AITeamMove *thisMove = team->curMove;
    SelectCommand *selection = team->shipList.selection;

    if (team->shipList.selection->numShips == 0)
    {
        aiplayerLog((aiIndex,"Special Move, Zero Sized Team"));
        return TRUE;
    }

    if (!thisMove->processing)
    {
        if ((selection->numShips > 0) &&
            ((thisMove->params.attack.ships == NULL) ||
             (thisMove->params.attack.ships->numShips > 0)))
        {
            aiuWrapSpecial(team->shipList.selection, thisMove->params.attack.ships);
            thisMove->processing = TRUE;
        }
        else
        {
            aiplayerLog((aiIndex,"Warning: no ships to special stuff with"));
            thisMove->processing = TRUE;
        }

        return FALSE;
    }
    else
    {
        if ((selection->numShips == 0) ||
            (!aitTeamIsDoingSpecialOp(team)))
        {
            // we're done
            aiumemFree(thisMove->params.attack.ships);

            return TRUE;
        }
        else
        {
            return (!thisMove->wait);
        }
    }
}
Exemple #4
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);
}
Exemple #5
0
void aimSpecialClose(AITeam *team,AITeamMove *move)
{
    aiumemFree(move->params.attack.ships);
}