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); } } } }
void MinelayerCorvetteFire(Ship *ship,SpaceObjRotImpTarg *target) { GunInfo *guninfo = ship->gunInfo; Gun *gun0,*gun1; if (guninfo == NULL) { dbgAssert(FALSE); //should have gun info...something is teribly wrong... } gun0 = ((Gun *) &(ship->gunInfo->guns[0])); if(ship->gunInfo->numGuns > 1) { //ship has 2 guns (race 1) gun1 = ((Gun *) &(ship->gunInfo->guns[1])); if(gun0->lasttimefired <= gun1->lasttimefired) { //Gun 0's turn to fire if (gun0->numMissiles >0) { //if there is ammo if (gunCanShoot(ship, gun0)) { missileShoot(ship,gun0, target); } } else { if(gun1->numMissiles >0) { if (gunCanShoot(ship, gun1)) { missileShoot(ship,gun1, target); } } } } else { if (gun1->numMissiles >0) { //if there is ammo if (gunCanShoot(ship, gun1)) { missileShoot(ship,gun1, target); } } else { if(gun0->numMissiles >0) { if (gunCanShoot(ship, gun0)) { missileShoot(ship,gun0, target); } } } } } else { //ship is race 2 wiht 1 gun only if (gun0->numMissiles >0) { //if there is ammo if (gunCanShoot(ship, gun0)) { missileShoot(ship,gun0, target); } } } }
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; } }