HRESULT CprobeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize > sizeof(DataProbeBase))); { DataProbeBase* dataProbeBase = (DataProbeBase*)data; if ((dataProbeBase->exportF) && ((DataProbeExport*)dataProbeBase)->createNow) { m_time0 = now; } else { m_time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataProbeBase->time0); } TmodelIGC<IprobeIGC>::Initialize(pMission, now, data, dataSize); IshipIGC* pshipLauncher; IsideIGC* pside; IclusterIGC* pcluster; if (dataProbeBase->exportF) { assert (dataSize == sizeof(DataProbeExport)); DataProbeExport* dataProbeExport = (DataProbeExport*)dataProbeBase; m_probeType = (IprobeTypeIGC*)(pMission->GetExpendableType(dataProbeExport->probetypeID)); pside = pMission->GetSide(dataProbeExport->sideID); pcluster = pMission->GetCluster(dataProbeExport->clusterID); pshipLauncher = pside->GetShip(dataProbeExport->shipID); if (m_probeType->HasCapability(c_eabmShootOnlyTarget)) m_target = pMission->GetModel(dataProbeExport->otTarget, dataProbeExport->oidTarget); } else { assert (dataSize == sizeof(DataProbeIGC)); DataProbeIGC* dataProbe = (DataProbeIGC*)dataProbeBase; m_probeType = dataProbe->pprobetype; pside = dataProbe->pside; pcluster = dataProbe->pcluster; pshipLauncher = dataProbe->pship; if (m_probeType->HasCapability(c_eabmShootOnlyTarget)) m_target = dataProbe->pmodelTarget; } assert (m_probeType); assert (m_probeType->GetObjectType() == OT_probeType); m_probeType->AddRef(); m_ammo = m_probeType->GetAmmo(); DataProbeTypeIGC* dataProbeType = (DataProbeTypeIGC*)(m_probeType->GetData()); m_projectileType = m_probeType->GetProjectileType(); if (m_projectileType) { m_projectileType->AddRef(); m_bSeenByAll = false; if (pshipLauncher && (dataProbeType->launcherDef.price == 0)) m_launcher = pshipLauncher; } assert (pcluster); //Load the model for the probe assert (iswalpha(dataProbeType->modelName[0])); HRESULT hr = Load(0, dataProbeType->modelName, dataProbeType->textureName, dataProbeType->iconName, c_mtDamagable | c_mtHitable | c_mtStatic | c_mtSeenBySide | c_mtPredictable | c_mtScanner); assert (SUCCEEDED(hr)); SetRadius(dataProbeType->radius); SetSignature(dataProbeType->signature); SetSide(pside); SetSecondaryName(dataProbeType->launcherDef.name); { //Parts get a random orientation Vector v = Vector::RandomDirection(); Orientation o(v); SetOrientation(o); } //lifespan == 0 => immortal probe that can hit until it gets terminated on the next update; this is bad assert (dataProbeType->lifespan > 0.0f); m_timeExpire = m_time0 + dataProbeType->lifespan; assert (m_timeExpire != m_time0); m_nextFire = m_time0 + (m_probeType->HasCapability(c_eabmQuickReady) ? 5.0f //5 second delay : 30.0f); //30 second delay before we start to shoot assert (GetSide()); SetMass(0.0f); m_probeID = dataProbeBase->probeID; SetPosition(dataProbeBase->p0); SetCluster(pcluster); pMission->AddProbe(this); if ((dataProbeType->dtRipcord >= 0.0f) && ((GetMyLastUpdate() - m_time0) >= dataProbeType->dtRipcord)) { pMission->GetIgcSite()->ActivateTeleportProbe(this); } // mmf 04/08 destroy any probe near aleph (warp) tip as this is viewed as an exploit as the enemy // often cannot delete it // // if (experimental game type) mmf const MissionParams* pmp = pMission->GetMissionParams(); if (pmp->bExperimental) { Vector dV, probeV, warpV, tipdistV; Vector bV, tipV; float warp_rad, distance; Orientation warp_orient; Rotation warp_rot; // loop through list of warps for (WarpLinkIGC* pwl = pcluster->GetWarps()->first(); (pwl != NULL); pwl = pwl->next()) { IwarpIGC* pwarp = pwl->data(); warp_rad = pwarp->GetRadius(); warp_orient = pwarp->GetOrientation(); warpV = pwarp->GetPosition(); probeV = this->GetPosition(); dV= warpV-probeV; distance = dV.Length(); warp_rot = pwarp->GetRotation(); // if rotating (i.e. rotation is other than 0 0 1 0) abort check if (!((warp_rot.x()==0) && (warp_rot.y()==0) && (warp_rot.z()==1) && (warp_rot.angle()==0))) break; if (distance < (warp_rad * 2) ) { // only check if close to tip if reasonably close to warp center bV = warp_orient.GetBackward(); tipV = warpV + (bV*warp_rad); tipdistV = tipV-probeV; distance = tipdistV.Length(); if (distance < 30) { debugf("Destroying probe as it was dropped too close (within 30) of aleph(warp) tip. dist = $f\n",distance); return S_FALSE; // this will destroy the probe } } } } // mmf end // mmf added code to detect tp drop near asteroid and if too close destroy it // leave ActivateTeleProbe code above so enemy is alerted to the drop even though it may be destroyed if (dataProbeType->dtRipcord >= 0.0f) // check to see if this is a teleprobe { Vector dV; float asteroid_rad, distance; // loop through list of asteroids for (AsteroidLinkIGC* pal = pcluster->GetAsteroids()->first(); (pal != NULL); pal = pal->next()) { asteroid_rad = (pal->data()->GetRadius()); dV=this->GetPosition() - pal->data()->GetPosition(); distance = dV.Length(); if (distance < (asteroid_rad-5)) { debugf("Teleprobe dropped too close to asteroid (within -5) destroying probe. dist = %f, asteroid rad = %f\n", distance,asteroid_rad); // this->Terminate(); should be terminated when missionigc processes S_FALSE return S_FALSE; } } } // mmf end } return S_OK; }
//------------------------------------------------------------------------------ Goal* Mission5::CreateGoal03 (void) { GoalList* pGoalList = new GoalList; // tm_5_12 // Attention, Cadet, new contact: an enemy scout. In some // cases, utility craft like miners will run home for // protection, but you can tell them to hide by giving them // orders to go to a base. You left-click the miners, then // left-click the Go To command, and then right-click ÿ the // base. { Goal* pGoal = CreatePlaySoundGoal (tm_5_12Sound); IwarpIGC* pAlephMars = trekClient.GetCore ()->GetWarp (1052); Orientation alephMarsOrientation = pAlephMars->GetOrientation (); // create the enemy scout Vector pos = pAlephMars->GetPosition () + (alephMarsOrientation.GetForward () * random (800.0f, 1200.0f)) + (alephMarsOrientation.GetRight () * random(-100.0f, 200.0f)); CreateDroneAction* pCreateDroneAction = new CreateDroneAction ("Enemy Scout", m_enemyScoutID, 310, 1, c_ptWingman); pCreateDroneAction->SetCreatedLocation (GetStartSectorID () + 1, pos); pGoal->AddStartAction (pCreateDroneAction); // tell the enemy scout of these guys to do nothing pGoal->AddStartAction (new SetCommandAction (m_enemyScoutID, c_cmdAccepted, NULL, c_cidDoNothing)); pGoal->AddStartAction (new SetCommandAction (m_enemyScoutID, c_cmdCurrent, NULL, c_cidDoNothing)); // set its signature to infinity pGoal->AddStartAction (new SetSignatureAction (OT_ship, m_enemyScoutID, 1.0e6f)); pGoalList->AddGoal (pGoal); } // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); // tm_5_13 // Most enemy ships can be considered a threat to your miners // unless you have plenty of defending pilots ? which you // don?t. So let's get those miners to shelter ? send all // three of them to the base. pGoalList->AddGoal (CreatePlaySoundGoal (tm_5_13Sound)); // tm_5_13r // Send all three of your miners to base for safety. { Condition* pAndConditionA = new AndCondition (new GetCommandCondition (m_miner2ID, c_cidGoto), new GetCommandCondition (m_miner3ID, c_cidGoto)); Condition* pConditionB = new GetCommandCondition (m_miner4ID, c_cidGoto); Goal* pGoal = new Goal (new AndCondition (pAndConditionA, pConditionB)); pGoal->AddStartAction (new MessageAction ("Order all three miners back to base for safety.")); pGoal->AddConstraintCondition (CreateTooLongCondition (30.0f, tm_5_13rSound)); pGoalList->AddGoal (pGoal); } // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); // tm_5_14 // Good! Utility ships like miners and constructors are // drones. They will always accept your orders. pGoalList->AddGoal (CreatePlaySoundGoal (tm_5_14Sound)); // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); return new Goal (pGoalList); }
//------------------------------------------------------------------------------ Goal* Mission4::CreateGoal03 (void) { GoalList* pGoalList = new GoalList; ImissionIGC* pMission = trekClient.GetCore (); BuoyID buoyID = pMission->GenerateNewBuoyID (); IshipIGC* pShip = trekClient.GetShip (); // tm_4_07 // The last means of communication is to receive an order from // your commander. I'm giving you a command to go to a // waypoint. pGoalList->AddGoal (CreatePlaySoundGoal (tm_4_07Sound)); // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); // tm_4_08 // This red text denotes an objective from the commander. { Goal* pGoal = CreatePlaySoundGoal (tm_4_08Sound); IwarpIGC* pAleph = pMission->GetWarp (1030); Vector delta = pAleph->GetPosition () - pShip->GetPosition (); Vector position = pShip->GetPosition () + (delta * 0.25f) + (pAleph->GetOrientation ().GetUp () * (delta.Length () * 0.1f)); pGoal->AddStartAction (new CreateWaypointAction (buoyID, position, 1030)); pGoal->AddStartAction (new SetCommandAction (pShip, c_cmdQueued, OT_buoy, buoyID, c_cidGoto)); //pGoal->AddStartAction (new SetHUDOverlayAction (CommandTrainingOverlay)); pGoalList->AddGoal (pGoal); } // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); // tm_4_08r // Press the INSERT key to accept this objective. { Goal* pGoal = new Goal (new GetCommandCondition (trekClient.GetShip (), c_cidGoto)); pGoal->AddStartAction (new MessageAction ("Press the INSERT key to accept the command.")); pGoal->AddStartAction (new PlaySoundAction (tm_4_08rSound)); pGoal->AddConstraintCondition (CreateTooLongCondition (30.0f, tm_4_08rSound)); pGoalList->AddGoal (pGoal); } // wait a few seconds pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (1.5f))); // tm_4_09 // Good. Notice that autopilot is activated when you accept an // objective to fly you to your goal. { Goal* pGoal = CreatePlaySoundGoal (tm_4_09Sound); //pGoal->AddStartAction (new SetHUDOverlayAction (NoTrainingOverlay)); pGoalList->AddGoal (pGoal); } // (Wait for ship to get near waypoint) { Goal* pGoal = new Goal (new ObjectWithinRadiusCondition (static_cast<ImodelIGC*> (pShip), OT_buoy, buoyID, 100.0f)); pGoal->AddConstraintCondition (new ConditionalAction (new TrueCondition, new SetAutopilotAction (trekClient.GetShip (), true))); pGoalList->AddGoal (pGoal); } return new Goal (pGoalList); }
//------------------------------------------------------------------------------ Goal* Mission4::CreateGoal08 (void) { GoalList* pGoalList = new GoalList; // tm_4_31 // Excellent work, Cadet! It looks like the other enemy miners // are running now. I'm ordering a constructor into this // sector to build a station here. { Goal* pGoal = CreatePlaySoundGoal (tm_4_31Sound); // create the friendly builder IwarpIGC* pAleph = trekClient.GetCore ()->GetWarp (1030); Vector pos = pAleph->GetPosition () + (pAleph->GetOrientation ().GetForward () * 100.0f); CreateDroneAction* pCreateDroneAction = new CreateDroneAction ("Constructor", m_builderID, 419, 0, c_ptBuilder); pCreateDroneAction->SetCreatedLocation (1030, pos); pCreateDroneAction->SetStationType (112); pGoal->AddStartAction (pCreateDroneAction); // command the builder to go to the asteroid on which it will build pGoal->AddStartAction (new SetCommandAction (m_builderID, c_cmdCurrent, OT_asteroid, static_cast<ObjectID>(10332), c_cidBuild)); pGoal->AddStartAction (new SetCommandAction (m_builderID, c_cmdAccepted, OT_asteroid, static_cast<ObjectID>(10332), c_cidBuild)); // create a waypoint for all of the miners to run to, and send them all there BuoyID buoyID = trekClient.GetCore ()->GenerateNewBuoyID (); pGoal->AddStartAction (new CreateWaypointAction (buoyID, Vector (1000.0f, 1000.0f, 1000.0f), 1032)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner1ID, c_cmdCurrent, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner1ID, c_cmdAccepted, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner2ID, c_cmdCurrent, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner2ID, c_cmdAccepted, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner3ID, c_cmdCurrent, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner3ID, c_cmdAccepted, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner4ID, c_cmdCurrent, OT_buoy, buoyID, c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (m_enemyMiner4ID, c_cmdAccepted, OT_buoy, buoyID, c_cidGoto)); // clear the player command set pGoal->AddStartAction (new SetCommandAction (trekClient.GetShip (), c_cmdCurrent, NA, NA, c_cidDoNothing)); pGoal->AddStartAction (new SetCommandAction (trekClient.GetShip (), c_cmdAccepted, NA, NA, c_cidDoNothing)); pGoalList->AddGoal (pGoal); } // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); // tm_4_32 // I'm moving your ship around to protect the constructor. // Stay near it in case an enemy fighter comes in. // Constructors are very expensive, and we don't want to lose // it. { Goal* pGoal = new Goal (new GetCommandCondition (trekClient.GetShip (), c_cidGoto)); pGoal->AddStartAction (new SetCommandAction (trekClient.GetShip (), c_cmdQueued, OT_ship, m_builderID, c_cidGoto)); pGoal->AddStartAction (new MessageAction ("Press the INSERT key to accept the command.")); pGoal->AddStartAction (new PlaySoundAction (tm_4_32Sound)); pGoal->AddConstraintCondition (CreateTooLongCondition (30.0f, tm_4_08rSound)); pGoalList->AddGoal (pGoal); } // (Wait for enemy scout to get within range) { Goal* pGoal = new Goal (new ObjectWithinRadiusCondition (trekClient.GetShip (), OT_ship, m_enemyScoutID, 1500.0f)); Vector pos (random(-300.0f, 300.0f), random(-300.0f, 300.0f), random(-300.0f, 300.0f)); CreateDroneAction* pCreateDroneAction = new CreateDroneAction ("Enemy Scout", m_enemyScoutID, 310, 1, c_ptWingman); pCreateDroneAction->SetCreatedLocation (1031, pos); pGoal->AddStartAction (pCreateDroneAction); pGoal->AddStartAction (new SetCommandAction (m_enemyScoutID, c_cmdCurrent, trekClient.GetShip (), c_cidAttack)); pGoal->AddStartAction (new SetCommandAction (m_enemyScoutID, c_cmdAccepted, trekClient.GetShip (), c_cidAttack)); pGoalList->AddGoal (pGoal); } // tm_4_33 // Enemy scout detected! Intercept it! { Goal* pGoal = new Goal (new GetCommandCondition (trekClient.GetShip (), c_cidAttack)); pGoal->AddStartAction (new SetCommandAction (m_builderID, c_cmdCurrent, NA, NA, c_cidDoNothing)); pGoal->AddStartAction (new SetCommandAction (m_builderID, c_cmdAccepted, NA, NA, c_cidDoNothing)); pGoal->AddStartAction (new SetCommandAction (trekClient.GetShip (), c_cmdQueued, OT_ship, m_enemyScoutID, c_cidAttack)); pGoal->AddStartAction (new MessageAction ("Press the INSERT key to accept the command.")); pGoal->AddStartAction (new PlaySoundAction (tm_4_33Sound)); pGoal->AddConstraintCondition (CreateTooLongCondition (30.0f, tm_4_33Sound)); pGoalList->AddGoal (pGoal); } // wait half second pGoalList->AddGoal (new Goal (new ElapsedTimeCondition (0.5f))); // tm_4_33r // Stop the scout from destroying the builder. { Goal* pGoal = new Goal (new GetCommandCondition (m_enemyScoutID, c_cidGoto)); pGoal->AddStartAction (new PlaySoundAction (tm_4_33rSound)); pGoal->AddConstraintCondition (CreateTooLongCondition (45.0f, tm_4_33rSound)); pGoalList->AddGoal (pGoal); } // wait half second { Goal* pGoal = new Goal (new ElapsedTimeCondition (0.5f)); // clear the player command set pGoal->AddStartAction (new SetCommandAction (trekClient.GetShip (), c_cmdCurrent, NA, NA, c_cidDoNothing)); pGoal->AddStartAction (new SetCommandAction (trekClient.GetShip (), c_cmdAccepted, NA, NA, c_cidDoNothing)); pGoalList->AddGoal (pGoal); } { Goal* pGoal = new Goal (pGoalList); // show the eyeball if it is appropriate ObjectID shipID = trekClient.GetShip ()->GetObjectID (); Condition* pOrConditionA = new OrCondition (new ShipSeesObjectCondition (m_enemyMiner1ID, OT_ship, shipID), new ShipSeesObjectCondition (m_enemyMiner2ID, OT_ship, shipID)); Condition* pOrConditionB = new OrCondition (new ShipSeesObjectCondition (m_enemyMiner3ID, OT_ship, shipID), new ShipSeesObjectCondition (m_enemyMiner4ID, OT_ship, shipID)); Condition* pSeesCondition = new OrCondition (new OrCondition (pOrConditionA, pOrConditionB), new ShipSeesObjectCondition (m_enemyScoutID, OT_ship, shipID)); pGoal->AddConstraintCondition (new ConditionalAction (pSeesCondition, new ShowEyeballAction (true))); pGoal->AddConstraintCondition (new ConditionalAction (new NotCondition (new ProxyCondition (pSeesCondition)), new ShowEyeballAction (false))); return pGoal; } }
void CFSShip::HitWarp(IwarpIGC * pwarp) { //Ignore jumps that happen too closely together if (m_warpState == warpReady) { // Andon - Added check for aleph mass limits if (m_pShip->GetMass() <= pwarp->MassLimit() || !IsPlayer() && pwarp->MassLimit() > 0 || pwarp->MassLimit() < 0) { if (IsPlayer()) { m_warpState = warpNoUpdate; } IwarpIGC * pwarpDest = pwarp->GetDestination(); assert (pwarpDest); IclusterIGC * pclusterDest = pwarpDest->GetCluster(); ShipStatusWarped(pwarp); Orientation alephOrientation = pwarpDest->GetOrientation(); const Vector& v = m_pShip->GetVelocity(); float speed2 = v.LengthSquared(); float speed = float(sqrt(speed2)); if (speed2 > 0) { float error; { //How close is the ship coming to the center of the warp? Vector dp = pwarp->GetPosition() - m_pShip->GetPosition(); float t = (dp * v) / speed2; float d = (dp - t * v).LengthSquared(); float r = pwarp->GetRadius(); error = (d / (r*r)) + 0.125f; //Error ranges from 0.125 to 1.125 // yp: to prevent 'spin of death' in massive ships. // This works and is explained in that the more massive the ship the less effect going through the aleph should have // on its rotational velocity. The massive amount of inertia should decrease changes in rotational velocity. if(m_pShip->GetMass() > 300.0f) { error = error * (300.0f / m_pShip->GetMass()); // the greater the mass is above 750 the less error will be applied. } // yp end } alephOrientation.Pitch(random(-error, error)); alephOrientation.Yaw(random(-error, error)); m_pShip->SetCurrentTurnRate(c_axisRoll, m_pShip->GetCurrentTurnRate(c_axisRoll) + random(pi * 0.5f * error, pi * 1.5f * error)); //Must be less than 2.0 * pi } m_pShip->SetOrientation(alephOrientation); const Vector& backward = alephOrientation.GetBackward(); speed = -(speed + pwarp->GetMission()->GetFloatConstant(c_fcidExitWarpSpeed)); m_pShip->SetVelocity(backward * speed); m_pShip->SetPosition(pwarpDest->GetPosition() + (alephOrientation.GetUp() * random(2.0f, 5.0f)) + (alephOrientation.GetRight() * random(2.0f, 5.0f)) - (m_pShip->GetRadius() + 5.0f) * backward); GetIGCShip()->SetCluster(pclusterDest); } } }