예제 #1
0
void DefaultShipFire(Ship *ship,SpaceObjRotImpTarg *target)
{
    GunInfo *guninfo = ship->gunInfo;
    sdword numGuns;
    sdword i;
    Gun *gun;

    if (guninfo == NULL)
    {
        return;
    }

    numGuns = guninfo->numGuns;

    for (i=0;i<numGuns;i++)
    {
        gun = &guninfo->guns[i];
        if (gunCanShoot(ship, gun))
        {
            switch (gun->gunstatic->guntype)
            {
                case GUN_MissileLauncher:
                case GUN_MineLauncher:
                    if (gunHasMissiles(gun))
                    {
                        missileShoot(ship,gun,target);
                    }
                    break;

                case GUN_NewGimble:
                case GUN_Gimble:
                case GUN_Fixed:
                    gunShoot(ship,gun,target);
                    break;

                default:
                    dbgAssert(FALSE);

            }
        }
    }
}
예제 #2
0
bool P1MissileCorvetteSpecialTarget(Ship *ship,void *custom)
{
    SelectAnyCommand *targets;
    sdword i;
    sdword numShipsToTarget;
    sdword numGuns;
    Gun *gun;
    GunStatic *gunstatic;
    SpaceObjRotImpTarg *target;
    ShipStaticInfo *shipstaticinfo;
    P1MissileCorvetteSpec *spec;
    P1MissileCorvetteStatics *mcorvettestat;
    bool firedSomeMissiles;

    spec = (P1MissileCorvetteSpec *)ship->ShipSpecifics;
    shipstaticinfo = (ShipStaticInfo *)ship->staticinfo;
    mcorvettestat = (P1MissileCorvetteStatics *)shipstaticinfo->custstatinfo;

    spec->lasttimeDidSpecialTargeting = universe.totaltimeelapsed;

    if ((universe.totaltimeelapsed - spec->lasttimeFiredVolley) > mcorvettestat->missileVolleyTime)
    {
        spec->lasttimeFiredVolley = universe.totaltimeelapsed;
    }
    else
    {
        return FALSE;
    }

    targets = (SelectAnyCommand *)custom;
    numShipsToTarget = targets->numTargets;

    if (numShipsToTarget == 0)
    {
        // have destroyed targets, so we are done
        spec->curTargetIndex = 0;
        return TRUE;
    }

    if (spec->curTargetIndex >= numShipsToTarget)
    {
        spec->curTargetIndex = 0;
    }

    numGuns = ship->gunInfo->numGuns;
    firedSomeMissiles = FALSE;
    for (i=0; i<numGuns; i++)
    {
        gunstatic = &shipstaticinfo->gunStaticInfo->gunstatics[i];
        if (gunstatic->guntype == GUN_MissileLauncher)
        {
            gun = &ship->gunInfo->guns[i];
            if (gunHasMissiles(gun))
            {
                firedSomeMissiles = TRUE;

                target = targets->TargetPtr[spec->curTargetIndex];

                missileShoot(ship,gun,target);

                spec->curTargetIndex++;
                if (spec->curTargetIndex >= numShipsToTarget)
                {
                    spec->curTargetIndex = 0;
                }
            }
        }
    }

    if (firedSomeMissiles)
    {
        return FALSE;
    }
    else
    {
        // all empty of missiles, so we are done
        spec->curTargetIndex = 0;
        return TRUE;
    }
}