void CclusterIGC::DeleteModel(ImodelIGC* modelOld) { assert (modelOld); { //Add the model to the collision set HitTest* ht = modelOld->GetHitTest(); ModelAttributes mt = modelOld->GetAttributes(); if ((mt & c_mtNotPickable) == 0) { DeleteIbaseIGC((BaseListIGC*)&m_modelsPickable, modelOld); } if (mt & c_mtCastRay) { DeleteIbaseIGC((BaseListIGC*)&m_modelsCastRay, modelOld); } if (mt & c_mtHitable) { ((mt & c_mtStatic) ? m_kdrStatic : m_kdrMoving).deleteHitTest(ht); } else ht->SetDeadF(true); ZRetailAssert(ht->GetDeadF()); } m_pClusterSite->DeleteThingSite(modelOld->GetThingSite()); DeleteIbaseIGC((BaseListIGC*)&m_models, modelOld); }
///////////////////////////////////////////////////////////////////////////// // CsideIGC HRESULT CsideIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize) { m_pMission = pMission; ZRetailAssert (data && (dataSize >= sizeof(DataSideIGC))); m_data = *((DataSideIGC*)data); m_pCivilization = pMission->GetCivilization(m_data.civilizationID); assert (m_pCivilization); m_pCivilization->AddRef(); m_ttbmBuildingTechs.ClearAll(); //Will automatically adjust for starting buildings m_lastUpdate = now; pMission->AddSide(this); m_pMission->GetIgcSite()->CreateSideEvent(static_cast<IsideIGC*>(this)); //#ALLY m_data.allies = NA; bRandomCivilization = false; //Xynth #170 8/10 Initialize new bool return S_OK; }
HRESULT CchaffIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize) { TmodelIGC<IchaffIGC>::Initialize(pMission, now, data, dataSize); ZRetailAssert (data && (dataSize == sizeof(DataChaffIGC))); DataChaffIGC* dataChaff = (DataChaffIGC*)data; m_pChaffTypeData = (DataChaffTypeIGC*)(dataChaff->pchafftype->GetData()); LoadDecal(m_pChaffTypeData->textureName, NULL, Color(1.0f, 1.0f, 1.0f, 1.0f), false, 1.0f, c_mtNotPickable | c_mtPredictable); Time time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataChaff->time0); SetRadius(1.0f); SetPosition(dataChaff->p0 + Seconds(now - time0).count() * dataChaff->v0); SetVelocity(dataChaff->v0); { Rotation r(Vector(0.0f, 0.0f, 1.0f), 2.75f); SetRotation(r); } SetMass(0.0f); m_timeExpire = time0 + Seconds(m_pChaffTypeData->lifespan); SetCluster(dataChaff->pcluster); return S_OK; }
HRESULT CweaponIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert(pMission); m_pMission = pMission; ZRetailAssert(data && (dataSize == sizeof(DataPartIGC))); { m_partType = ((DataPartIGC*)data)->partType; assert(m_partType); m_partType->AddRef(); m_typeData = (const DataWeaponTypeIGC*)m_partType->GetData(); m_projectileType = m_pMission->GetProjectileType(m_typeData->projectileTypeID); ZRetailAssert(m_projectileType); m_projectileType->AddRef(); } return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CmineTypeIGC HRESULT CmineTypeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataMineTypeIGC))); { m_data = *((DataMineTypeIGC*)data); pMission->AddExpendableType(this); } return S_OK; }
HRESULT CafterburnerIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize) { m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataPartIGC))); { m_partType = ((DataPartIGC*)data)->partType; assert (m_partType); m_partType->AddRef(); m_typeData = (const DataAfterburnerTypeIGC*)m_partType->GetData(); } return S_OK; }
HRESULT CpackIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataPartIGC))); { m_partType = ((DataPartIGC*)data)->partType; assert (m_partType); m_partType->AddRef(); m_typeData = (const DataPackTypeIGC*)m_partType->GetData(); m_amount = m_typeData->amount; } return S_OK; }
HRESULT CbuoyIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize) { TmodelIGC<IbuoyIGC>::Initialize(pMission, now, data, dataSize); ZRetailAssert (data && (dataSize == sizeof(DataBuoyIGC))); DataBuoyIGC* dataBuoy = (DataBuoyIGC*)data; LoadDecal("buoy", "buoyicon", Color(1.0f, 1.0f, 1.0f, 1.0f), false, 1.0f, c_mtStatic | c_mtPredictable); SetRadius(20.0f); SetPosition(dataBuoy->position); { Rotation r(Vector(0.0f, 0.0f, 1.0f), 0.5f); SetRotation(r); } m_type = dataBuoy->type; m_buoyID = (dataBuoy->buoyID == NA) ? pMission->GenerateNewBuoyID() : dataBuoy->buoyID; IclusterIGC* pcluster = pMission->GetCluster(dataBuoy->clusterID); if (dataBuoy->type == c_buoyCluster) SetSecondaryName(pcluster->GetName()); else SetSecondaryName("waypoint"); SetMass(0.0f); pMission->AddBuoy(this); SetCluster(pcluster); return S_OK; }
void CclusterIGC::AddModel(ImodelIGC* modelNew) { assert (modelNew); ZVerify(m_models.first(modelNew)); modelNew->AddRef(); m_pClusterSite->AddThingSite(modelNew->GetThingSite()); { //Add the model to the collision set HitTest* ht = modelNew->GetHitTest(); ModelAttributes mt = modelNew->GetAttributes(); if ((mt & c_mtNotPickable) == 0) { ZVerify(m_modelsPickable.last(modelNew)); modelNew->AddRef(); } if (mt & c_mtCastRay) { ZVerify(m_modelsCastRay.last(modelNew)); modelNew->AddRef(); } if (mt & c_mtHitable) { ((mt & c_mtStatic) ? m_kdrStatic : m_kdrMoving).addHitTest(ht); } else ht->SetDeadF(false); ZRetailAssert(!ht->GetDeadF()); } }
HRESULT CdispenserIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataPartIGC))); { m_partType = (IlauncherTypeIGC*)(((DataPartIGC*)data)->partType); assert (m_partType); m_partType->AddRef(); m_expendableType = (IexpendableTypeIGC*)(m_partType->GetExpendableType()); assert (m_expendableType); assert ((m_expendableType->GetObjectType() == OT_mineType) || (m_expendableType->GetObjectType() == OT_probeType) || (m_expendableType->GetObjectType() == OT_chaffType)); m_expendableType->AddRef(); m_amount = 0; } return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CclusterIGC HRESULT CclusterIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(m_data))); m_data = *((DataClusterIGC*)data); m_nPass = m_data.clusterID; m_lastUpdate = now; pMission->AddCluster(this); m_pClusterSite = pMission->GetIgcSite()->CreateClusterSite(this); if (m_data.posterName[0] != '\0') m_pClusterSite->SetEnvironmentGeo(m_data.posterName); if (m_data.planetName[0] != '\0') { Vector position; double sinLatitude = double(m_data.planetSinLatitude - 0.5); double cosLatitude = sqrt(1.0 - sinLatitude * sinLatitude); double longitude = double(m_data.planetLongitude * (2.0f * pi)); position.x = float(cos(longitude) * cosLatitude); position.y = float(sin(longitude) * cosLatitude); position.z = float(sinLatitude); m_pClusterSite->AddPoster(m_data.planetName, position, float(m_data.planetRadius)); } m_highlight = false; //Xynth #208 return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CprobeTypeIGC HRESULT CprobeTypeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataProbeTypeIGC))); { m_data = *((DataProbeTypeIGC*)data); assert (iswalpha(m_data.modelName[0])); pMission->GetIgcSite()->Preload(m_data.modelName, iswalpha(m_data.textureName[0]) ? m_data.textureName : NULL); MultiHullBase* pmhb = HitTest::Load(m_data.modelName); if (m_data.projectileTypeID != NA) { m_projectileType = pMission->GetProjectileType(m_data.projectileTypeID); assert (m_projectileType); m_projectileType->AddRef(); if (pmhb) { float scale = (m_data.radius / pmhb->GetOriginalRadius()); m_emissionPt = pmhb->GetFrameOffset("wepemt") * scale; } else { m_emissionPt = Vector::GetZero(); } } pMission->AddExpendableType(this); } return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CmissileTypeIGC HRESULT CmissileTypeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataMissileTypeIGC))); { m_data = *((DataMissileTypeIGC*)data); if (iswalpha(m_data.modelName[0])) { pMission->GetIgcSite()->Preload(m_data.modelName, iswalpha(m_data.textureName[0]) ? m_data.textureName : NULL); HitTest::Load(m_data.modelName); } else pMission->GetIgcSite()->Preload(NULL, m_data.textureName); pMission->AddExpendableType(this); } return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CdroneTypeIGC HRESULT CdroneTypeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, unsigned int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataDroneTypeIGC))); memcpy(&m_data, data, dataSize); #ifdef WIN m_petLaid = (m_data.etidLaid == NA) ? NULL : pMission->GetExpendableType(m_data.etidLaid); #else m_petLaid.reset( (m_data.etidLaid == NA) ? nullptr : pMission->GetExpendableType(m_data.etidLaid) ); #endif // KGJV - fix for debug mode - to remove later //assert ((m_petLaid != NULL) == (m_data.pilotType == c_ptLayer)); pMission->AddDroneType(this); return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CcivilizationIGC HRESULT CcivilizationIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataCivilizationIGC))); m_data = *((DataCivilizationIGC*)data); pMission->AddCivilization(this); m_pstInitial = pMission->GetStationType(m_data.initialStationTypeID); assert (m_pstInitial); m_pstInitial->AddRef(); assert (m_pstInitial->HasCapability(c_sabmRestart)); m_phtLifepod = pMission->GetHullType(m_data.lifepod); assert (m_phtLifepod); m_phtLifepod->AddRef(); return S_OK; }
HRESULT CprojectileIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { TmodelIGC<IprojectileIGC>::Initialize(pMission, now, data, dataSize); ZRetailAssert (data && (dataSize == sizeof(DataProjectileIGC))); { DataProjectileIGC* dataProjectile = (DataProjectileIGC*)data; m_projectileType = pMission->GetProjectileType(dataProjectile->projectileTypeID); if (m_projectileType) { m_projectileType->AddRef(); DataProjectileTypeIGC* dataProjectileType = (DataProjectileTypeIGC*)m_projectileType->GetData(); assert (dataProjectileType); //Load the model for the projectile if (iswalpha(dataProjectileType->modelName[0])) { HRESULT hr = Load(0, dataProjectileType->modelName, dataProjectileType->textureName, NULL, c_mtCastRay | c_mtNotPickable); assert (SUCCEEDED(hr)); SetRadius(dataProjectileType->radius); } else { HRESULT hr = LoadDecal(dataProjectileType->textureName, NULL, Color((float)dataProjectileType->color.r, (float)dataProjectileType->color.g, (float)dataProjectileType->color.b, (float)dataProjectileType->color.a), dataProjectileType->bDirectional, dataProjectileType->width, c_mtCastRay | c_mtNotPickable); assert (SUCCEEDED(hr)); GetHitTest()->SetRadius(0.0f); GetThingSite()->SetRadius(dataProjectileType->radius); } //position set after being initialized SetVelocity(dataProjectile->velocity); { Orientation o(dataProjectile->forward); SetOrientation(o); } { Rotation r(dataProjectile->forward, dataProjectileType->rotation); SetRotation(r); } { HitTest* ht = GetHitTest(); //lifespan == 0 => immortal projectile that can hit until it gets terminated on the next update; this is bad assert (dataProjectile->lifespan > 0.0f); ht->SetTimeStart(now); ht->SetTimeStop(m_timeExpire = now + dataProjectile->lifespan); //intentional assignment assert (m_timeExpire != now); } SetMass(0.0f); } } return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CwarpIGC HRESULT CwarpIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { TmodelIGC<IwarpIGC>::Initialize(pMission, now, data, dataSize); ZRetailAssert (data && (dataSize == sizeof(DataWarpIGC))); { DataWarpIGC* dataWarp = (DataWarpIGC*)data; m_warpDef = dataWarp->warpDef; IclusterIGC* cluster = pMission->GetCluster(dataWarp->clusterID); ZRetailAssert (cluster); { // , use the real texture name HRESULT rc = LoadWarp(dataWarp->warpDef.textureName, dataWarp->warpDef.iconName, c_mtStatic | c_mtHitable | c_mtSeenBySide | c_mtPredictable); assert (SUCCEEDED(rc)); { SetRadius((float)m_warpDef.radius); SetPosition(dataWarp->position); SetVelocity(Vector::GetZero()); { Orientation o(dataWarp->forward); SetOrientation(o); } SetRotation(dataWarp->rotation); SetCluster(cluster); SetMass(0.0f); // KG- hack for unmovable alephs (to avoid a IGC file format change) // aleph name with a leading '*' denotes a fixed position aleph // so remove the '*' from the name and set m_bFixedPosition to true // Andon: Added mass limits to alephs. It checks for a leading '+' // and if found it searches for a ':' - It then takes everything after // this and turns it into a number. After that, it replaces the ':' with // a '(' and adds a ')' to the end. if (dataWarp->name[0] == '*') { m_bFixedPosition = true; if (dataWarp->name[1] == '+')//Andon: Added for if the aleph is both unmoved and mass limited { ZString name = dataWarp->name; int MassFind = name.Find(':',0); char* mass = &(dataWarp->name[MassFind+2]); m_MassLimit = atoi(mass); name.ReplaceAll(":" ,'('); //Replaces the : with a ( const char* alephname = &(name[2]); //Removes the leading '*+' char* newAlephName = new char[25]; const char* nameSuffix = ")"; //Adds a ) to the end strncpy(newAlephName, alephname, strlen(alephname)+1); strncat(newAlephName, nameSuffix, strlen(nameSuffix)+1); SetName(newAlephName); } else { SetName(&(dataWarp->name[1])); // skip the leading '*' m_MassLimit = -1; } } else if (dataWarp->name[0] == '+') { ZString name = dataWarp->name; int MassFind = name.Find(':',0); char* mass = &(dataWarp->name[MassFind+1]); m_MassLimit = atoi(mass); name.ReplaceAll(":" ,'('); //Replaces the : with a ( const char* alephname = &(name[1]);//Skip the leading '+' char* newAlephName = new char[25]; const char* nameSuffix = ")"; //Adds a ) to the end strncpy(newAlephName, alephname, strlen(alephname)+1); strncat(newAlephName, nameSuffix, strlen(nameSuffix)+1); SetName(newAlephName); } else { SetName(dataWarp->name); m_MassLimit = -1; } SetSignature(dataWarp->signature); pMission->AddWarp(this); } } } return S_OK; }
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; }
///////////////////////////////////////////////////////////////////////////// // CasteroidIGC HRESULT CasteroidIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { ZeroMemory(&m_builderseensides, sizeof(bool) * c_cSidesMax); //Imago 8/10 TmodelIGC<IasteroidIGC>::Initialize(pMission, now, data, dataSize); ZRetailAssert (data && (dataSize == sizeof(DataAsteroidIGC))); { DataAsteroidIGC* dataAsteroid = (DataAsteroidIGC*)data; m_asteroidDef = dataAsteroid->asteroidDef; IclusterIGC* cluster = pMission->GetCluster(dataAsteroid->clusterID); ZRetailAssert (cluster); { HRESULT rc = Load(0, m_asteroidDef.modelName, m_asteroidDef.textureName, m_asteroidDef.iconName, c_mtStatic | c_mtHitable | c_mtDamagable | c_mtSeenBySide | c_mtPredictable); assert (SUCCEEDED(rc)); SetRadius((float)m_asteroidDef.radius); SetPosition(dataAsteroid->position); { Orientation o(dataAsteroid->forward, dataAsteroid->up); SetOrientation(o); } // Turkey 01/2014 AME is bugged, rotation axis should be a normalized vector Rotation r = dataAsteroid->rotation; Vector axis = r.axis().Normalize(); r.axis(axis); SetRotation(r); SetSignature(dataAsteroid->signature); m_fraction = dataAsteroid->fraction; if (m_fraction > 1.0f) m_fraction = 1.0f; // Turkey 01/2014 AME is bugged, gives rocks 100.4% hitpoints (241/240) if (dataAsteroid->name[0] != '\0') SetName(dataAsteroid->name); else SetSecondaryName(dataAsteroid->name + 1); SetCluster(cluster); //Xynth #100 7/2010 Need to initialize oreseenbyside for all sides for (SideLinkIGC* psl = this->GetMission()->GetSides()->first(); psl != NULL; psl = psl->next()) { IsideIGC* pside = psl->data(); oreSeenBySide.Set(pside, 0.0); } m_lastUpdateOre = 0.0; //Xynth #132 7/2010 Should update first time this is mined m_inhibitUpdate = false; //Xynth #225 9/10 m_inhibitCounter = -1; #ifdef DEBUG { //Verify that there is no pre-existing asteroid with the same ID for (AsteroidLinkIGC* pal = pMission->GetAsteroids()->first(); (pal != NULL); pal = pal->next()) { assert (pal->data()->GetObjectID() != m_asteroidDef.asteroidID); } } #endif pMission->AddAsteroid(this); } } return S_OK; }
HRESULT CmineIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { ZRetailAssert (data && (dataSize > sizeof(DataMineBase))); { DataMineBase* dataMineBase = (DataMineBase*)data; if ((dataMineBase->exportF) && ((DataMineExport*)dataMineBase)->createNow) { m_time0 = now; } else { m_time0 = pMission->GetIgcSite()->ClientTimeFromServerTime(dataMineBase->time0); } TmodelIGC<ImineIGC>::Initialize(pMission, now, data, dataSize); IshipIGC* pshipLauncher; IclusterIGC* pcluster; DataMineTypeIGC* dataMineType; if (dataMineBase->exportF) { assert (dataSize >= sizeof(DataMineExport)); DataMineExport* dataMineExport = (DataMineExport*)dataMineBase; m_mineType = (ImineTypeIGC*)(pMission->GetExpendableType(dataMineExport->minetypeID)); assert (m_mineType); assert (m_mineType->GetObjectType() == OT_mineType); pcluster = pMission->GetCluster(dataMineExport->clusterID); assert (m_mineType); dataMineType = (DataMineTypeIGC*)(m_mineType->GetData()); pshipLauncher = pMission->GetShip(dataMineExport->launcherID); SetSide(pMission->GetSide(dataMineExport->sideID)); m_fraction = dataMineExport->fraction; } else { assert (dataSize == sizeof(DataMineIGC)); DataMineIGC* dataMine = (DataMineIGC*)dataMineBase; m_mineType = dataMine->pminetype; pcluster = dataMine->pcluster; assert (m_mineType); assert (m_mineType->GetObjectType() == OT_mineType); dataMineType = (DataMineTypeIGC*)(m_mineType->GetData()); pshipLauncher = dataMine->pshipLauncher; SetSide(dataMine->psideLauncher); m_fraction = 1.0f; } if (pshipLauncher && (dataMineType->launcherDef.price == 0)) { m_launcher = pshipLauncher; m_launcher->AddRef(); } assert (GetSide()); assert (pcluster); m_mineType->AddRef(); //Load the model for the mine LoadMine(dataMineType->textureName, 1.0f, dataMineType->radius, dataMineType->iconName, c_mtSeenBySide | c_mtPredictable | c_mtHitable | c_mtStatic); SetRadius(dataMineType->radius); SetSignature(dataMineType->signature); SetSecondaryName(dataMineType->launcherDef.name); { //lifespan == 0 => immortal mine that can hit until it gets terminated on the next update; this is bad assert (dataMineType->lifespan > 0.0f); m_timeExpire = m_time0 + dataMineType->lifespan; assert (m_timeExpire != m_time0); } SetMass(0.0f); m_mineID = dataMineBase->mineID; SetPosition(dataMineBase->p0); SetCluster(pcluster); pMission->AddMine(this); } return S_OK; }
///////////////////////////////////////////////////////////////////////////// // ChullTypeIGC HRESULT ChullTypeIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize >= sizeof(DataHullTypeIGC))); //Note ... we need to allocate & copy the DataHullTypeIGC + the variable length fields m_data = (DataHullTypeIGC*)(new char [dataSize]); assert (m_data); memcpy(m_data, data, dataSize); { for (int i = 0; ((i < c_cMaxPreferredPartTypes) && (m_data->preferredPartsTypes[i] != NA)); i++) { IpartTypeIGC* ppt = pMission->GetPartType(m_data->preferredPartsTypes[i]); assert (ppt); ppt->AddRef(); m_preferredPartTypes.last(ppt); } } IIgcSite* pigc = pMission->GetIgcSite(); pigc->Preload(m_data->modelName, iswalpha(m_data->textureName[0]) ? m_data->textureName : NULL); m_poIcon = pigc->LoadRadarIcon(m_data->iconName); { static const Vector z(0.0f, 0.0f, 1.0f); MultiHullBase* pmhb = HitTest::Load(m_data->modelName); assert (pmhb); { { float r = pmhb->GetOriginalRadius(); m_scale = (0.5f * m_data->length / r); #if 0 { const Vector& ellipseEquation = pmhb->GetEllipseEquation(); debugf("%s/%d %f %f %f\n", m_data->name, m_data->hullID, ellipseEquation.x * m_scale, ellipseEquation.y * m_scale, ellipseEquation.z * m_scale); double v = ellipseEquation.x * ellipseEquation.y * ellipseEquation.z; debugf("%s/%d\t(%s)\n\tOld length = %f\n\tNew Length = %f\n\tFrontal area = %f\n\tVolume = %f\n", m_data->name, m_data->hullID, m_data->modelName, float(m_data->length), float(m_data->length) * r * float(pow(v, -1.0/3.0)), pmhb->GetEllipseEquation().x * pmhb->GetEllipseEquation().y * m_scale * m_scale, pmhb->GetEllipseEquation().x * pmhb->GetEllipseEquation().y * pmhb->GetEllipseEquation().z * m_scale * m_scale * m_scale); debugf("\tDensity %f\n", m_data->mass / (0.2f * (pmhb->GetEllipseEquation().x * pmhb->GetEllipseEquation().y * pmhb->GetEllipseEquation().z * m_scale * m_scale * m_scale))); } #endif } { const FrameDataUTL* pfd = pmhb->GetFrame("cockpt"); m_cockpit = pfd ? (pfd->position * m_scale) : z; } { // TurkeyXIII 11/09 #94 const FrameDataUTL* pfd = pmhb->GetFrame("chaff"); m_chaff = pfd ? (pfd->position * m_scale) : Vector::GetZero(); } for (Mount i = m_data->maxWeapons - 1; (i >= 0); i--) { const HardpointData& hd = GetHardpointData(i); const FrameDataUTL* pfd = pmhb->GetFrame(hd.frameName); // KGJV: temp fix assert (pfd); //Note: still need to handle pfd == NULL semi-gracefully in retail // mmf added debugf to log what would have been the above assert that KGJV commented out // this seems to happen a lot at core load, no sense logging it // if (pfd==NULL) debugf("mmf hullTypeIGC.cpp ln 96 pfd == NULL would have called assert\n"); if (hd.bFixed) { assert (i < m_data->maxFixedWeapons); m_positionWeapons[i] = pfd ? (pfd->position * m_scale) : Vector::GetZero(); } else { // mmf debug build failing on this assert with newer cores like plus14b or rps55 // dn 4.05 and zone core work // this has been logged sufficiently to provide core authors enough info // if they wanted to try and resolve the 'errors' they seem not to be problematic // if (i < m_data->maxFixedWeapons) { // debugf("mmf hullTypeIGC.cpp would have called assert\n"); // debugf("mmf i=%d, maxFixedWeapons=%d, hullID = %d\n",i,m_data->maxFixedWeapons,m_data->hullID); // } // end mmf // mmf comment out this assert so debug build will work // assert (i >= m_data->maxFixedWeapons); if (pfd) { m_positionWeapons[i] = pfd->position * m_scale; static const Vector up(0.0f, 1.0f, 0.0f); if (fabs(pfd->forward * up) < 0.9f) m_orientationWeapons[i].Set(pfd->forward, up); else { m_orientationWeapons[i].Set(pfd->forward, z); } } else { m_positionWeapons[i] = Vector::GetZero(); m_orientationWeapons[i].Set(z); } } } #if 0 if (m_data->maxFixedWeapons > 1) { debugf("\n%s/%d\t%s\t%f\n", GetName(), GetObjectID(), m_data->modelName, m_data->length); for (Mount i = 0; (i < m_data->maxFixedWeapons); i++) { for (Mount j = i+1; (j < m_data->maxFixedWeapons); j++) { debugf("%d <-> %d\t%f %s %s\n", i, j, (m_positionWeapons[i] - m_positionWeapons[j]).Length(), GetHardpointData(i).frameName, GetHardpointData(j).frameName); } } } #endif m_nLandSlots = 0; m_nLaunchSlots = 0; { //Get the stations launch slots static char bfrLaunch[] = "launchX"; while (true) { //Do we have a launch slot? bfrLaunch[6] = '1' + m_nLaunchSlots; const FrameDataUTL* pfd = pmhb->GetFrame(bfrLaunch); if (pfd) { assert (m_nLaunchSlots < c_maxShipLaunchSlots); m_positionLaunches[m_nLaunchSlots] = pfd->position * m_scale; m_directionLaunches[m_nLaunchSlots++] = pfd->forward; } else break; } } { //debugf("Station %s/%s\n", GetName(), m_data.modelName); //Refigure the stations launch slots static char bfrLand[] = "garageXA"; while (true) { //Do we have a launch slot? bfrLand[6] = '1' + m_nLandSlots; bfrLand[7] = 'A'; const FrameDataUTL* pfd = pmhb->GetFrame(bfrLand); if (pfd) { assert (m_nLandSlots < c_maxShipLandSlots); int i = 0; do { assert (i < c_maxLandPlanes); m_positionLandPlanes[m_nLandSlots][i] = pfd->position * m_scale; m_directionLandPlanes[m_nLandSlots][i] = pfd->forward; //debugf("\t%s %f %f %f\n", bfrLand, m_positionLandPlanes[m_nLandSlots][i].x, m_positionLandPlanes[m_nLandSlots][i].y, m_positionLandPlanes[m_nLandSlots][i].z); bfrLand[7] = 'A' + ++i; pfd = pmhb->GetFrame(bfrLand); } while (pfd); m_nLandPlanes[m_nLandSlots++] = i; } else break; } } } } if (m_data->successorHullID != NA) { m_phtSuccessor = pMission->GetHullType(m_data->successorHullID); // mmf this assert causing plus15b2 core to exit // comment out for now so this core can be tested with debug build // assert (m_phtSuccessor); // add debugf // this has been logged enough if core devs want to resolve it // does not seem to be problem // debugf("mmf hullTypeIGC.cpp m_phtSuccessor == NULL would have called assert\n"); // debugf("mmf m_data->successorHullID = %d, hullID = %d\n",m_data->successorHullID,m_data->hullID); } pMission->AddHullType(this); /* if (this->GetRechargeRate() > 0.0f) { float eTotal = 0.0f; for (Mount i = 0; (i < this->GetMaxWeapons()); i++) { const HardpointData& hd = this->GetHardpointData(i); float eMax = 0.0f; for (PartTypeLinkIGC* ppl = pMission->GetPartTypes()->first(); (ppl != NULL); ppl = ppl->next()) { IpartTypeIGC* pt = ppl->data(); if ((pt->GetEquipmentType() == ET_Weapon) && ((pt->GetPartMask() & ~hd.partMask) == 0)) { DataWeaponTypeIGC* dwt = (DataWeaponTypeIGC*)(pt->GetData()); float e = dwt->energyPerShot / dwt->dtimeBurst; if (e > eMax) eMax = e; } } eTotal += eMax; } if (this->GetPartMask(ET_Cloak, 0) != 0) { debugf("\n%s (%d)\n\t%8.3f%8.0f%8.0f\n\t%8.3f (120)\n\t%8.3f (180)\n\t%8.3f (200)\n\t%8.3f (%8.3f) %8.3f\n", GetName(), GetObjectID(), this->GetMaxEnergy() / this->GetRechargeRate(), this->GetMaxEnergy(), this->GetRechargeRate(), this->GetMaxEnergy() / (120.0f - this->GetRechargeRate()), this->GetMaxEnergy() / (180.0f - this->GetRechargeRate()), this->GetMaxEnergy() / (200.0f - this->GetRechargeRate()), (eTotal > this->GetRechargeRate()) ? this->GetMaxEnergy() / (eTotal - this->GetRechargeRate()) : -1.0f, eTotal, eTotal/this->GetRechargeRate()); } else { debugf("\n%s (%d)\n\t%8.3f%8.0f%8.0f\n\t%8.3f (%8.3f) %8.3f\n", GetName(), GetObjectID(), this->GetMaxEnergy() / this->GetRechargeRate(), this->GetMaxEnergy(), this->GetRechargeRate(), (eTotal > this->GetRechargeRate()) ? this->GetMaxEnergy() / (eTotal - this->GetRechargeRate()) : -1.0f, eTotal, eTotal/this->GetRechargeRate()); } } */ return S_OK; }
///////////////////////////////////////////////////////////////////////////// // CbucketIGC HRESULT CbucketIGC::Initialize(ImissionIGC* pMission, Time now, const void* data, int dataSize) { assert (pMission); m_pMission = pMission; ZRetailAssert (data && (dataSize == sizeof(DataBucketIGC))); m_data = *((DataBucketIGC*)data); assert (m_data.side); m_data.side->AddRef(); m_price = m_data.buyable->GetPrice(); m_timeToBuild = m_data.buyable->GetTimeToBuild(); //See if there is a predecessor bucket if (m_data.buyable->GetObjectType() == OT_development) { IdevelopmentIGC* pdevelopment = (IdevelopmentIGC*)(m_data.buyable); if ((!pdevelopment->GetTechOnly()) && pdevelopment->GetEffectTechs().GetAllZero()) { //A tech that affects only a side's global attributes. //Check for other buckets which do exactly the same thing Money price = pdevelopment->GetPrice(); const GlobalAttributeSet& gas = pdevelopment->GetGlobalAttributeSet(); //Go backwards to get the last possible development for (BucketLinkIGC* pbl = m_data.side->GetBuckets()->last(); (pbl != NULL); pbl = pbl->txen()) { IbucketIGC* pbucket = pbl->data(); IbuyableIGC* pbuyable = pbucket->GetBuyable(); if (pbuyable->GetObjectType() == OT_development) { IdevelopmentIGC* pd = (IdevelopmentIGC*)pbuyable; if ((!pd->GetTechOnly()) && (pd->GetPrice() <= price) && pd->GetEffectTechs().GetAllZero()) { //Look at that ... a equally or less expensive development that affects only global attributes //do they affect the same global attributes the same way? if (pd->GetGlobalAttributeSet() == gas) { pbucket->AddRef(); m_pbucketPredecessor = pbucket; break; } } } } } if (pdevelopment->GetObjectID() != c_didTeamMoney) { m_price = (Money)(m_price * m_data.side->GetGlobalAttributeSet().GetAttribute(c_gaDevelopmentCost)); m_timeToBuild = (DWORD)(m_timeToBuild * m_data.side->GetGlobalAttributeSet().GetAttribute(c_gaDevelopmentTime)); } } m_data.side->AddBucket(this); assert (m_data.buyable); m_data.buyable->AddRef(); m_lastUpdate = now; return S_OK; }