void CprobeIGC::Terminate(void) { AddRef(); DataProbeTypeIGC* dataProbeType = (DataProbeTypeIGC*)(m_probeType->GetData()); if (dataProbeType->dtRipcord >= 0.0f) { GetMyMission()->GetIgcSite()->DestroyTeleportProbe(this); } if (m_projectileType) { m_projectileType->Release(); m_projectileType = NULL; } m_launcher = NULL; m_target = NULL; GetCluster()->GetClusterSite()->AddExplosion(GetPosition(), GetRadius(), c_etProbe); GetMyMission()->DeleteProbe(this); TmodelIGC<IprobeIGC>::Terminate(); if (m_probeType) { m_probeType->Release(); m_probeType = NULL; } Release(); }
void CbuoyIGC::Terminate(void) { AddRef(); GetMyMission()->DeleteBuoy(this); TmodelIGC<IbuoyIGC>::Terminate(); Release(); }
void CmineIGC::Terminate(void) { AddRef(); GetMyMission()->DeleteMine(this); TmodelIGC<ImineIGC>::Terminate(); if (m_launcher) { m_launcher->Release(); m_launcher = NULL; } if (m_mineType) { m_mineType->Release(); m_mineType = NULL; } Release(); }
void CprobeIGC::Update(Time now) { if (now >= m_timeExpire) GetMyMission()->GetIgcSite()->KillProbeEvent(this); else { { float dt = m_probeType->GetRipcordDelay(); if (dt >= 0.0f) { Time timeActivate = m_time0 + dt; if ((GetMyLastUpdate() < timeActivate) && (now >= timeActivate)) { GetMyMission()->GetIgcSite()->ActivateTeleportProbe(this); } } } if (m_projectileType) { if (m_nextFire < now) { IclusterIGC* pcluster = GetCluster(); assert (pcluster); //We'll be able to take a shot float lifespan = GetProjectileLifespan(); IsideIGC* pside = GetSide(); const Vector& myPosition = GetPosition(); float speed = m_projectileType->GetSpeed(); if (m_ammo != 0) speed *= GetSide()->GetGlobalAttributeSet().GetAttribute(c_gaSpeedAmmo); float accuracy = GetAccuracy(); float dtimeBurst = GetDtBurst(); float dispersion = m_probeType->GetDispersion(); Time lastUpdate = GetMyLastUpdate(); if (m_nextFire < lastUpdate) m_nextFire = lastUpdate; assert (m_nextFire <= now); TmodelIGC<IprobeIGC>::Update(now); float dtUpdate = m_nextFire - lastUpdate; //If we have a target ... find the closest enemy ship who is a valid target ExpendableAbilityBitMask eabm = m_probeType->GetCapabilities(); float distance2Min = speed * lifespan / 1.2f; distance2Min *= distance2Min; Vector directionMin; ImodelIGC* pmodelTarget = NULL; if (eabm & c_eabmShootOnlyTarget) { if (m_target && (m_target->GetCluster() == pcluster)) { ObjectType type = m_target->GetObjectType(); ValidTarget((type == OT_ship) ? ((IshipIGC*)(ImodelIGC*)m_target)->GetSourceShip() : m_target, pside, myPosition, dtUpdate, accuracy, speed, lifespan, type, &pmodelTarget, &distance2Min, &directionMin); } } else { if (eabm & c_eabmShootShips) { //Threats to stations get highest priority GetTarget((const ModelListIGC*)(pcluster->GetShips()), pside, myPosition, dtUpdate, accuracy, speed, lifespan, OT_ship, &pmodelTarget, &distance2Min, &directionMin); } if (eabm & c_eabmShootMissiles) { GetTarget((const ModelListIGC*)(pcluster->GetMissiles()), pside, myPosition, dtUpdate, accuracy, speed, lifespan, OT_missile, &pmodelTarget, &distance2Min, &directionMin); } if (eabm & c_eabmShootStations) { GetTarget((const ModelListIGC*)(pcluster->GetStations()), pside, myPosition, dtUpdate, accuracy, speed, lifespan, OT_station, &pmodelTarget, &distance2Min, &directionMin); } } if (pmodelTarget) { if (m_launcher && (m_launcher->GetMission() != GetMyMission())) m_launcher = NULL; //It is going to shoot ... make it visible to everyone in the sector if (!m_bSeenByAll) { m_bSeenByAll = true; for (SideLinkIGC* psl = m_pMission->GetSides()->first(); (psl != NULL); psl = psl->next()) { IsideIGC* psideOther = psl->data(); if (!SeenBySide(psideOther)) { //Does this side have any scanners in the sector? ClusterSite* pcs = pcluster->GetClusterSite(); const ScannerListIGC* psl = pcs->GetScanners(psideOther->GetObjectID()); if ((psl->n() != 0) || (m_pMission->GetMissionParams()->bAllowAlliedViz && psideOther->AlliedSides(psideOther,pside))) //ALLY 7/3/09 VISIBILITY 7/11/09 imago SetSideVisibility(psideOther, true); else m_bSeenByAll = false; } } } //We have a target ... fire along directionMin (modulo dispersion) Orientation o = GetOrientation(); o.TurnTo(directionMin); SetOrientation(o); Vector position = myPosition + m_probeType->GetEmissionPt() * o; DataProjectileIGC dataProjectile; dataProjectile.projectileTypeID = m_projectileType->GetObjectID(); short nShots = 0; do { //Permute the "forward" direction slightly by a random amount dataProjectile.forward = directionMin; if (dispersion != 0.0f) { float r = random(0.0f, dispersion); float a = random(0.0f, 2.0f * pi); dataProjectile.forward += (r * cos(a)) * o.GetRight(); dataProjectile.forward += (r * sin(a)) * o.GetUp(); dataProjectile.forward.SetNormalize(); } //We never move, so skip all the velocity calculations dataProjectile.velocity = speed * dataProjectile.forward; dataProjectile.lifespan = lifespan; IprojectileIGC* p = (IprojectileIGC*)(m_pMission->CreateObject(m_nextFire, OT_projectile, &dataProjectile, sizeof(dataProjectile))); assert (p); { p->SetLauncher(m_launcher ? ((ImodelIGC*)m_launcher) : ((ImodelIGC*)this)); p->SetPosition(position); p->SetCluster(pcluster); p->Release(); } nShots++; m_nextFire += dtimeBurst; } while (m_nextFire < now); if (m_ammo > 0) { m_ammo -= nShots; if (m_ammo <= 0) { m_ammo = 0; GetMyMission()->GetIgcSite()->KillProbeEvent(this); } } } else { //No shots this cycle m_nextFire = now; } } } TmodelIGC<IprobeIGC>::Update(now); } }