void Obstacle::Write(std::ostream& os)const { os << std::endl; os << EntityType() << ",";//z 写入了实体类型,位置和半径 os << Pos() << ","; os << BRadius(); }
void Trigger_WeaponGiver::Try(Raven_Bot* pBot) { if (this->isActive() && this->isTouchingTrigger(pBot->Pos(), pBot->BRadius())) { pBot->GetWeaponSys()->AddWeapon(EntityType()); Deactivate(); } }
/** * \brief Returns the entity type with the given name. * * This is the name used in data files and return by the Lua function * entity:get_type(). * * \param entity_type_name The name of an entity type. It must exist. * \return The corresponding type. */ EntityType get_entity_type_by_name(const std::string& entity_type_name) { for (const auto& kvp: entity_type_names) { if (kvp.second == entity_type_name) { return kvp.first; } } Debug::die(std::string("Unknown entity type: ") + entity_type_name); return EntityType(); }
PairIterRelation Entity::relations( EntityType et , unsigned kind ) const { const EntityType et_next = EntityType( et + 1 ); const relation_attr_type lo_attr = relation_attr( et , 0 , kind ), hi_attr = relation_attr( et_next , 0 , kind ); std::vector<Relation>::const_iterator i = m_relation.begin(); std::vector<Relation>::const_iterator e = m_relation.end(); i = std::lower_bound( i , e , lo_attr , LessRelation() ); e = std::lower_bound( i , e , hi_attr , LessRelation() ); return PairIterRelation( i , e ); }
/** * @brief Creates a movement of type CircleMovement that will be accessible from the script. * * - Argument 1 (integer): type of the center entity * (must match the enumeration EntityType) * - Argument 2 (string): name of the center entity * - Argument 3 (int): the radius of the circle in pixels * - Return value (movement): a handle to the movement created * * @param l the Lua context that is calling this function */ int Script::main_api_circle_movement_create(lua_State *l) { Script *script; called_by_script(l, 3, &script); int center_type = luaL_checkinteger(l, 1); const std::string& center_name = luaL_checkstring(l, 2); int radius = luaL_checkinteger(l, 3); MapEntity* center_entity = script->get_map().get_entities(). get_entity(EntityType(center_type), center_name); CircleMovement *movement = new CircleMovement(); movement->set_center(center_entity); movement->set_radius(radius); int movement_handle = script->create_movement_handle(*movement); lua_pushinteger(l, movement_handle); return 1; }
void FullID::parse( String const& fullidstring ) { // empty FullID string is invalid if( fullidstring == "" ) { THROW_EXCEPTION( BadID, "empty FullID string" ); } String aString( fullidstring ); eraseWhiteSpaces( aString ); // ignore leading white spaces String::size_type aFieldStart( 0 ); String::size_type aFieldEnd( aString.find_first_of( DELIMITER, aFieldStart ) ); if( aFieldEnd == String::npos ) { THROW_EXCEPTION( BadID, "no ':' in the FullID string [" + aString + "]" ); } String aTypeString( aString.substr( aFieldStart, aFieldEnd - aFieldStart ) ); theEntityType = EntityType( aTypeString ); aFieldStart = aFieldEnd + 1; aFieldEnd = aString.find_first_of( DELIMITER, aFieldStart ); if( aFieldEnd == String::npos ) { THROW_EXCEPTION( BadID, "only one ':' in the FullID string [" + aString + "]" ); } theSystemPath = SystemPath( aString.substr( aFieldStart, aFieldEnd - aFieldStart ) ); aFieldStart = aFieldEnd + 1; // drop trailing string after extra ':'(if this is FullPN), // or go to the end aFieldEnd = aString.find_first_of( DELIMITER, aFieldStart ); theID = aString.substr( aFieldStart, aFieldEnd - aFieldStart ); }
void BombClass::LauInit(void) { Falcon4EntityClassType* classPtr; WeaponClassDataType* wc; SimWeaponDataType* wpnDefinition; int lauId; lauFireCount = 0; classPtr = (Falcon4EntityClassType*)EntityType(); wc = (WeaponClassDataType*)classPtr->dataPtr; wpnDefinition = &SimWeaponDataTable[classPtr->vehicleDataIndex]; lauId = (short)(((int)Falcon4ClassTable[wc->Index].dataPtr - (int)WeaponDataTable) / sizeof(WeaponClassDataType)); if(wpnDefinition->weaponClass == wcRocketWpn) { if(auxData && auxData->lauWeaponId) { lauRounds = lauMaxRounds = auxData->lauRounds; lauWeaponId = auxData->lauWeaponId; lauSalvoSize = auxData->lauSalvoSize; } else { int j; int entryfound = 0; // read the rack dat file for (j=0; j<NumRocketTypes; j++) { if (lauId == RocketDataTable[j].weaponId) { if (RocketDataTable[j].nweaponId) // 0 = don't change weapon ID lauWeaponId = RocketDataTable[j].nweaponId; lauMaxRounds = RocketDataTable[j].weaponCount; lauRounds = lauMaxRounds; lauSalvoSize = lauRounds; /* WeaponClass weapClass = (WeaponClass)SimWeaponDataTable[Falcon4ClassTable[WeaponDataTable[lauWeaponId].Index].vehicleDataIndex].weaponClass; // MLR 1/28/2004 - hardPoint[i]->GetWeaponClass() is not correct if(weapClass==wcGunWpn) { hardPoint[i]->weaponPointer = InitAGun (newOwnship, hardPoint[i]->weaponId, hardPoint[i]->weaponCount); } else { hardPoint[i]->weaponPointer = InitWeaponList (newOwnship, hardPoint[i]->weaponId, hardPoint[i]->GetWeaponClass(), hardPoint[i]->weaponCount, InitAMissile); } */ entryfound = 1; break; } } /* if (!entryfound) // use generic 2.75mm rocket { lauWeaponId = gRocketId; lauMaxRounds = 19; lauRounds = lauMaxRounds; lauSalvoSize = lauRounds; }*/ } } else { lauWeaponId=0; } }
void Engine::createEntityType(const std::string &name, const std::string &script) { entityTypes[name] = EntityType(name, script); }
void Trigger_WeaponGiver::Render() { if (isActive()) { switch (EntityType()) { case type_rail_gun: { gdi->BluePen(); gdi->BlueBrush(); gdi->Circle(Pos(), 3); gdi->ThickBluePen(); gdi->Line(Pos(), Vector2D(Pos().x, Pos().y-9)); } break; case type_shotgun: { gdi->BlackBrush(); gdi->BrownPen(); const double sz = 3.0; gdi->Circle(Pos().x-sz,Pos().y, sz); gdi->Circle(Pos().x+sz,Pos().y, sz); } break; case type_smg: { gdi->RedBrush(); gdi->YellowPen(); const double sz = 3.0; gdi->Circle(Pos().x - sz, Pos().y, sz); gdi->Circle(Pos().x + sz, Pos().y, sz); } break; case type_revolver: { gdi->BlackBrush(); gdi->BlackPen(); const double sz = 2.0; gdi->Circle(Pos().x - sz, Pos().y, sz); gdi->Circle(Pos().x + sz, Pos().y, sz); gdi->Circle(Pos().x - sz / 2.0, Pos().y + sz / 2.0, sz); gdi->Circle(Pos().x + sz / 2.0, Pos().y + sz / 2.0, sz); gdi->Circle(Pos().x - sz / 2.0, Pos().y - sz / 2.0, sz); gdi->Circle(Pos().x + sz / 2.0, Pos().y - sz / 2.0, sz); } break; case type_minigun: { gdi->RedPen(); gdi->RedBrush(); gdi->Circle(Pos(), 2); gdi->ThickRedPen(); gdi->Line(Pos(), Vector2D(Pos().x, Pos().y - 9)); } break; case type_rocket_launcher: { Vector2D facing(-1,0); m_vecRLVBTrans = WorldTransform(m_vecRLVB, Pos(), facing, facing.Perp(), Vector2D(2.5,2.5)); gdi->RedPen(); gdi->ClosedShape(m_vecRLVBTrans); } break; }//end switch } }
void HelicopterClass::InitDamageStation (void) { #if 0 // KCK Removed on 6/23 - This stuff isn't really necessary and breaks a unification assumption Falcon4EntityClassType* classPtr; VuEntityType* eclassPtr = NULL; int i, debrisvis; Tpoint simView = {0.0F, 0.0F, 0.0F}; Trotation viewRotation = IMatrix; // current parts are: // fuselage // 2 wings // tail numBodyParts = 4; damageStation = new WeaponStation; damageStation->onRail = new SimBaseClass*[numBodyParts]; damageStation->SetupPoints(numBodyParts); // get the aircraft's class info // for each aircraft, visType[1] should indicate the specific type for // the aircraft's damaged version eclassPtr = EntityType(); F4Assert (eclassPtr); classPtr = &(Falcon4ClassTable[ GetClassID( eclassPtr->classInfo_[VU_DOMAIN], eclassPtr->classInfo_[VU_CLASS], eclassPtr->classInfo_[VU_TYPE], eclassPtr->classInfo_[VU_STYPE], eclassPtr->classInfo_[VU_SPTYPE], VU_ANY, VU_ANY, VU_ANY) ]); /* classPtr = &(Falcon4ClassTable[ GetClassID( eclassPtr->classInfo_[VU_DOMAIN], eclassPtr->classInfo_[VU_CLASS], eclassPtr->classInfo_[VU_TYPE], eclassPtr->classInfo_[VU_STYPE], classPtr->visType[3], VU_ANY, VU_ANY, VU_ANY) ]); */ for (i=0, debrisvis=0; i<numBodyParts; i++) { damageStation->onRail[i] = new SimBaseClass(Type()); CalcTransformMatrix (damageStation->onRail[i]); OTWDriver.CreateVisualObject(damageStation->onRail[i], classPtr->visType[i+2], &simView, &viewRotation, OTWDriver.Scale()); /* if ( i > 0 ) { ((DrawableBSP*)(damageStation->onRail[0]->drawPointer))->GetChildOffset(i, &simView); ((DrawableBSP*)(damageStation->onRail[0]->drawPointer))->AttachChild(((DrawableBSP*)(damageStation->onRail[i]->drawPointer)), i); } damageStation->SetSubPosition(i, simView.x, simView.y, simView.z); damageStation->SetSubRotation(i, 0.0F, 0.0F); */ } // Init smoke trails numSmokeTrails = 4; smokeTrail = new DrawableTrail*[numSmokeTrails]; for (i=0; i<numSmokeTrails; i++) smokeTrail[i] = new DrawableTrail(TRAIL_SMOKE); #endif }
void HelicopterClass::RunExplosion (void) { int i; Tpoint pos; Falcon4EntityClassType *classPtr; SimBaseClass *tmpSimBase; Tpoint tp = Origin; Trotation tr = IMatrix; // F4PlaySound (SFX_DEF[SFX_OWNSHIP_BOOM].handle); //F4SoundFXSetPos( SFX_BOOMA1 + PRANDInt5(), TRUE, XPos(), YPos(), ZPos(), 1.0f ); SoundPos.Sfx( SFX_BOOMA1 + PRANDInt5() ); // MLR 5/16/2004 - // 1st do primary explosion pos.x = XPos(); pos.y = YPos(); pos.z = ZPos(); if ( OnGround( ) ) { pos.z = OTWDriver.GetGroundLevel( pos.x, pos.y ) - 4.0f; SetDelta( XDelta() * 0.1f, YDelta() * 0.1f, -50.0f ); OTWDriver.AddSfxRequest( new SfxClass (SFX_GROUND_EXPLOSION, // type &pos, // world pos 1.2f, // time to live 100.0f ) ); // scale } else { OTWDriver.AddSfxRequest( new SfxClass (SFX_AIR_HANGING_EXPLOSION, // type &pos, // world pos 2.0f, // time to live 200.0f + 200 * PRANDFloatPos() ) ); // scale } classPtr = (Falcon4EntityClassType*)EntityType(); // Add the parts (appairently hardcoded at 4) // Recoded by KCK on 6/23 to remove damage station BS for (i=0; i<4; i++) { tmpSimBase = new SimBaseClass(Type()); CalcTransformMatrix (tmpSimBase); OTWDriver.CreateVisualObject(tmpSimBase, classPtr->visType[i+2], &tp, &tr, OTWDriver.Scale()); tmpSimBase->SetPosition (pos.x, pos.y, pos.z); if (!i) { tmpSimBase->SetDelta (XDelta(), YDelta(), ZDelta()); } if (!OnGround()) { tmpSimBase->SetDelta ( XDelta() + 50.0f * PRANDFloat(), YDelta() + 50.0f * PRANDFloat(), ZDelta() + 50.0f * PRANDFloat() ); } else { tmpSimBase->SetDelta ( XDelta() + 50.0f * PRANDFloat(), YDelta() + 50.0f * PRANDFloat(), ZDelta() - 50.0f * PRANDFloatPos() ); } tmpSimBase->SetYPR (Yaw(), Pitch(), Roll()); if (!i) { // First peice is more steady and is flaming tmpSimBase->SetYPRDelta ( 0.0F, 0.0F, 10.0F + PRANDFloat() * 30.0F * DTR); OTWDriver.AddSfxRequest( new SfxClass (SFX_FLAMING_PART, // type SFX_MOVES | SFX_USES_GRAVITY | SFX_EXPLODE_WHEN_DONE, tmpSimBase, // sim base * 3.0f + PRANDFloatPos() * 4.0F, // time to live 1.0F ) ); // scale } else { // spin piece a random amount tmpSimBase->SetYPRDelta ( PRANDFloat() * 30.0F * DTR, PRANDFloat() * 30.0F * DTR, PRANDFloat() * 30.0F * DTR); OTWDriver.AddSfxRequest( new SfxClass (SFX_SMOKING_PART, // type SFX_MOVES | SFX_USES_GRAVITY | SFX_BOUNCES | SFX_EXPLODE_WHEN_DONE, tmpSimBase, // sim base * 4.0f * PRANDFloatPos() + (float)((i+1)*(i+1)), // time to live 1.0 ) ); // scale } } }
/* ** GroundClass Exec() function. ** NOTE: returns TRUE if we've processed this frame. FALSE if we're to do ** dead reckoning (in VU) */ int GroundClass::Exec (void) { //RV - I-Hawk - Added a 0 vector for RV new PS calls Tpoint PSvec; PSvec.x = 0; PSvec.y = 0; PSvec.z = 0; Tpoint pos; Tpoint vec; float speedScale; float groundZ; float labelLOD; float drawLOD; RadarClass *radar = NULL; SoundPos.UpdatePos((SimBaseClass *)this); //Cobra pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f; // MLR 5/23/2004 - pos.x = XPos(); pos.y = YPos(); pos.z = OTWDriver.GetApproxGroundLevel( pos.x, pos.y ); // pos.z = -10.0f;//Cobra trying to fix the stupid uninit CTD SetPosition(pos.x, pos.y, pos.z); // dead? -- we do nothing if ( IsDead() ){ return FALSE; } // if damaged if ( pctStrength < 0.5f ){ if (sfxTimer > 1.5f - gai->distLOD * 1.3){ // reset the timer sfxTimer = 0.0f; pos.z -= 10.0f; // VP_changes this shoud be checked why have GetGroundLevel been subtracted by 10.0F // Sometimes the trails seem strange vec.x = PRANDFloat() * 20.0f; vec.y = PRANDFloat() * 20.0f; vec.z = PRANDFloat() * 20.0f; /* OTWDriver.AddSfxRequest( new SfxClass( SFX_TRAILSMOKE, // type SFX_MOVES | SFX_NO_GROUND_CHECK, // flags &pos, // world pos &vec, // vector 3.5f, // time to live 4.5f // scale ) ); */ DrawableParticleSys::PS_AddParticleEx((SFX_TRAILSMOKE + 1), &pos, &vec); } } if (IsExploding()){ // KCK: I've never seen this section of code executed. Maybe it gets hit, but I doubt // it. if (!IsSetFlag( SHOW_EXPLOSION )){ // Show the explosion Tpoint pos, vec; Falcon4EntityClassType *classPtr = (Falcon4EntityClassType *)EntityType(); //DrawableGroundVehicle *destroyedPtr; // FRB //Cobra TJL 11/07/04 CTD point initialize here pos.x = 0.0f; pos.y = 0.0f; pos.z = 0.0f; // MLR 5/23/2004 - uncommented out the x, y pos.x = XPos(); pos.y = YPos(); pos.z = OTWDriver.GetApproxGroundLevel( pos.x, pos.y ) - 10.0f; vec.x = 0.0f; vec.y = 0.0f; vec.z = 0.0f; // create a new drawable for destroyed vehicle // sometimes..... //RV - I-Hawk - Commenting all this if statement... not necessary /* if ( rand() & 1 ){ destroyedPtr = new DrawableGroundVehicle( classPtr->visType[3], &pos, Yaw(), 1.0f ); groundZ = PRANDFloatPos() * 60.0f + 15.0f; /* OTWDriver.AddSfxRequest( new SfxClass ( SFX_BURNING_PART, // type &pos, // world pos &vec, // (DrawableBSP *)destroyedPtr, groundZ, // time to live 1.0f // scale ) ); */ /* DrawableParticleSys::PS_AddParticleEx((SFX_BURNING_PART + 1), &pos, &vec); pos.z += 10.0f; /* OTWDriver.AddSfxRequest( new SfxClass( SFX_FEATURE_EXPLOSION, // type &pos, // world pos groundZ, // time to live 100.0f // scale ) ); */ /* DrawableParticleSys::PS_AddParticleEx((SFX_FEATURE_EXPLOSION + 1), &pos, &PSvec); } */ //RV - I-Hawk - seperating explosion type for ground/sea domains. also //adding a check so soldiers will not explode like ground vehicles... if (GetDomain() == DOMAIN_LAND && GetType() != TYPE_FOOT) { //pos.z -= 20.0f; /* OTWDriver.AddSfxRequest( new SfxClass( SFX_VEHICLE_EXPLOSION, // type &pos, // world pos 1.5f, // time to live 100.0f // scale ) ); */ DrawableParticleSys::PS_AddParticleEx((SFX_VEHICLE_EXPLOSION + 1), &pos, &PSvec); } else if ( GetDomain() == DOMAIN_SEA ) { DrawableParticleSys::PS_AddParticleEx((SFX_WATER_FIREBALL + 1), &pos, &PSvec); } // make sure we don't do it again... SetFlag( SHOW_EXPLOSION ); // we can now kill it immediately SetDead(TRUE); } return FALSE; } // exec any base functionality SimVehicleClass::Exec(); // Sept 30, 2002 // VP_changes: Frequently Z value is not in the correct place. It should follow the terrain. if ( drawPointer ){ drawPointer->GetPosition( &pos ); } else { return FALSE; } //JAM 27Sep03 - Let's try this groundZ = pos.z; // - 0.7f; KCK: WTF is this? //VP_changes Sept 25 groundZ = OTWDriver.GetGroundLevel( pos.x, pos.y ); // Movement/Targeting for local entities if (IsLocal() && SimDriver.MotionOn()) { //I commented this out, because it is done in gai->ProcessTargeting down below DSP 4/30/99 // Refresh our target pointer (if any) //SetTarget( SimCampHandoff( targetPtr, targetList, HANDOFF_RANDOM ) ); // Look for someone to do radar fire control for us FindBattalionFireControl(); // RV - Biker - Switch on lights for ground/naval vehicles int isNight = TimeOfDayGeneral(TheCampaign.CurrentTime) < TOD_DAWNDUSK ? true : false; if (drawPointer && ((DrawableBSP *)drawPointer)->GetNumSwitches() >= AIRDEF_LIGHT_SWITCH) { if (isShip) { isNight = (TimeOfDayGeneral(TheCampaign.CurrentTime) <= TOD_DAWNDUSK || realWeather->weatherCondition == INCLEMENT) ? true : false; if (pctStrength > 0.50f) { ((DrawableBSP *)drawPointer)->SetSwitchMask(0, isNight); ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, isNight); } } else if (GetVt() > 1.0f) { VuListIterator vehicleWalker(SimDriver.combinedList); FalconEntity* object = (FalconEntity*)vehicleWalker.GetFirst(); bool hasThreat = false; float range = 999.9f * NM_TO_FT; // Consider each potential target in our environment while (object && !hasThreat) { // Skip sleeping sim objects if (object->IsSim()) { if (!((SimBaseClass*)object)->IsAwake()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } } // Fow now we skip missles -- might want to display them eventually... if (object->IsMissile() || object->IsBomb()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } if (object->GetTeam() == GetTeam()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } float dx = object->XPos() - XPos(); float dy = object->YPos() - YPos(); float dz = object->ZPos() - ZPos(); range = (float)sqrt(dx*dx + dy*dy + dz*dz); if (range < 5.0f * NM_TO_FT) hasThreat = true; object = (FalconEntity*)vehicleWalker.GetNext(); } // If no enemy nearby and not heavy damaged switch on lights if (!hasThreat && pctStrength > 0.75f) { ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, isNight); } else { ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } else { ((DrawableBSP *)drawPointer)->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } // RV - Biker - Do also switch on lights for tractor vehicles if (truckDrawable && truckDrawable->GetNumSwitches() >= AIRDEF_LIGHT_SWITCH) { if (GetVt() > 1.0f) { VuListIterator vehicleWalker(SimDriver.combinedList); FalconEntity* object = (FalconEntity*)vehicleWalker.GetFirst(); bool hasThreat = false; float range = 999.9f * NM_TO_FT; // Consider each potential target in our environment while (object && !hasThreat) { // Skip sleeping sim objects if (object->IsSim()) { if (!((SimBaseClass*)object)->IsAwake()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } } // Fow now we skip missles -- might want to display them eventually... if (object->IsMissile() || object->IsBomb()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } if (object->GetTeam() == GetTeam()) { object = (FalconEntity*)vehicleWalker.GetNext(); continue; } float dx = object->XPos() - XPos(); float dy = object->YPos() - YPos(); float dz = object->ZPos() - ZPos(); range = (float)sqrt(dx*dx + dy*dy + dz*dz); if (range < 5.0f * NM_TO_FT) hasThreat = true; object = (FalconEntity*)vehicleWalker.GetNext(); } // If no enemy nearby and not heavy damaged switch on lights if (!hasThreat && pctStrength > 0.75f) { truckDrawable->SetSwitchMask(AIRDEF_LIGHT_SWITCH, isNight); } else { truckDrawable->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } else { truckDrawable->SetSwitchMask(AIRDEF_LIGHT_SWITCH, 0); } } // RV - Biker - Shut down ship radar if damaged if (isShip && radarDown == false && pctStrength < 0.9f && rand()%50 > (pctStrength - 0.50f)*100) { isEmitter = false; RadarClass *radar = (RadarClass*)FindSensor(this, SensorClass::Radar); if (radar) { radarDown = true; radar->SetDesiredTarget(NULL); radar->SetEmitting(FALSE); } if (targetPtr) { SelectWeapon(true); } } // 2001-03-26 ADDED BY S.G. NEED TO KNOW IF THE RADAR CALLED SetSpotted // RV - Biker - Rotate radars float deltaDOF; float curDOF = GetDOFValue(5); deltaDOF = 180.0f * DTR * SimLibMajorFrameTime; curDOF += deltaDOF; if ( curDOF > 360.0f * DTR ) curDOF -= 360.0f * DTR; SetDOF(5, curDOF); int spottedSet = FALSE; // END OF ADDED SECTION // 2002-03-21 ADDED BY S.G. // If localData only has zeros, // there is a good chance they are not valid (should not happen here though)... if (targetPtr) { SimObjectLocalData* localData= targetPtr->localData; if ( localData->ataFrom == 0.0f && localData->az == 0.0f && localData->el == 0.0f && localData->range == 0.0f ) { CalcRelAzElRangeAta(this, targetPtr); } } // END OF ADDED SECTION 2002-03-21 // check for sending radar emmisions // 2002-02-26 MODIFIED BY S.G. // Added the nextTargetUpdate check to prevent the radar code to run on every frame! if ( isEmitter && nextTargetUpdate < SimLibElapsedTime){ // 2002-02-26 ADDED BY S.G. Next radar scan is 1 sec for aces, 2 for vets, etc ... nextTargetUpdate = SimLibElapsedTime + (5 - gai->skillLevel) * SEC_TO_MSEC; radar = (RadarClass*)FindSensor( this, SensorClass::Radar ); ShiAssert( radar ); if (radar){ radar->Exec( targetList ); } // 2001-03-26 ADDED BY S.G. // IF WE CAN SEE THE RADAR'S TARGET AND WE ARE A AIR DEFENSE THINGY // NOT IN A BKOGEN MORAL STATE, MARK IT AS SPOTTED IF WE'RE BRIGHT ENOUGH if ( radar && radar->CurrentTarget() && gai->skillLevel >= 3 && ((UnitClass *)GetCampaignObject())->GetSType() == STYPE_UNIT_AIR_DEFENSE && !((UnitClass *)GetCampaignObject())->Broken() ){ CampBaseClass *campBaseObj; if (radar->CurrentTarget()->BaseData()->IsSim()){ campBaseObj = ((SimBaseClass *)radar->CurrentTarget()->BaseData())->GetCampaignObject(); } else{ campBaseObj = (CampBaseClass *)radar->CurrentTarget()->BaseData(); } // JB 011002 If campBaseObj is NULL the target may be chaff if (campBaseObj && !(campBaseObj->GetSpotted(GetTeam())) && campBaseObj->IsFlight()){ RequestIntercept((FlightClass *)campBaseObj, GetTeam()); } spottedSet = TRUE; if (campBaseObj && radar->GetRadarDatFile()){ campBaseObj->SetSpotted( GetTeam(), TheCampaign.CurrentTime, (radar->radarData->flag & RAD_NCTR) != 0 && radar->CurrentTarget()->localData && radar->CurrentTarget()->localData->ataFrom < 45.0f * DTR && radar->CurrentTarget()->localData->range < radar->GetRadarDatFile()->MaxNctrRange / (2.0f * (16.0f - (float)gai->skillLevel) / 16.0f) ); } // 2002-03-05 MODIFIED BY S.G. target's aspect and skill used in the equation } // END OF ADDED SECTION } // 2001-03-26 ADDED BY S.G. // IF THE BATTALION LEAD HAS LOS // ON IT AND WE ARE A AIR DEFENSE THINGY NOT IN A BKOGEN MORAL STATE, // MARK IT AS SPOTTED IF WE'RE BRIGHT ENOUGH // 2002-02-11 MODIFED BY S.G. // Since I only identify visually, need to perform this even if spotted by radar in case I can ID it. if ( /*!spottedSet && gai->skillLevel >= 3 && */ ((UnitClass *)GetCampaignObject())->GetSType() == STYPE_UNIT_AIR_DEFENSE && gai == gai->battalionCommand && !((UnitClass *)GetCampaignObject())->Broken() && gai->GetAirTargetPtr() && CheckLOS(gai->GetAirTargetPtr()) ){ CampBaseClass *campBaseObj; if (gai->GetAirTargetPtr()->BaseData()->IsSim()) campBaseObj = ((SimBaseClass *)gai->GetAirTargetPtr()->BaseData())->GetCampaignObject(); else campBaseObj = (CampBaseClass *)gai->GetAirTargetPtr()->BaseData(); // JB 011002 If campBaseObj is NULL the target may be chaff if (!spottedSet && campBaseObj && !(campBaseObj->GetSpotted(GetTeam())) && campBaseObj->IsFlight()) RequestIntercept((FlightClass *)campBaseObj, GetTeam()); if (campBaseObj) campBaseObj->SetSpotted(GetTeam(),TheCampaign.CurrentTime, 1); // 2002-02-11 MODIFIED BY S.G. Visual detection means identified as well } // END OF ADDED SECTION // KCK: When should we run a target update cycle? if (SimLibElapsedTime > lastProcess){ gai->ProcessTargeting(); lastProcess = SimLibElapsedTime + processRate; } // KCK: Check if it's ok to think if (SimLibElapsedTime > lastThought ){ // do movement and (possibly) firing.... gai->Process (); lastThought = SimLibElapsedTime + thoughtRate; } // RV - Biker - Only allow SAM fire if radar still does work SimWeaponClass *theWeapon = Sms->GetCurrentWeapon(); // FRB - This version seems to give SAMs a little more activity if(SimLibElapsedTime > nextSamFireTime && !allowSamFire){ allowSamFire = TRUE; } // Biker's version //if(SimLibElapsedTime > nextSamFireTime && !allowSamFire) //{ // if (radarDown == false || (theWeapon && theWeapon->IsMissile() && theWeapon->sensorArray[0]->Type() == SensorClass::IRST)) // allowSamFire = TRUE; //} // Move and update delta; gai->Move_Towards_Dest(); // edg: always insure that our Z position is valid for the entity. // the draw pointer should have this value // KCK NOTE: The Z we have is actually LAST FRAME's Z. Probably not a big deal. SetPosition( XPos() + XDelta() * SimLibMajorFrameTime, YPos() + YDelta() * SimLibMajorFrameTime, groundZ ); // do firing // this also does weapon keep alive if ( Sms ){ gai->Fire(); } } // KCK: I simplified this some. This is now speed squared. speedScale = XDelta()*XDelta() + YDelta()*YDelta(); // set our level of detail if ( gai == gai->battalionCommand ){ gai->SetDistLOD(); } else{ gai->distLOD = gai->battalionCommand->distLOD; } // do some extra LOD stuff: if the unit is not a lead veh amd the // distLOD is less than a certain value, remove it from the draw // list. if (drawPointer && gai->rank != GNDAI_BATTALION_COMMANDER){ // distLOD cutoff by ranking (KCK: This is explicit for testing, could be a formula/table) if (gai->rank & GNDAI_COMPANY_LEADER){ labelLOD = .5F; drawLOD = .25F; } else if (gai->rank & GNDAI_PLATOON_LEADER){ labelLOD = .925F; drawLOD = .5F; } else { labelLOD = 1.1F; drawLOD = .75F; } // RV - Biker - Why do this maybe helpful knowing which vehicle has problems // Determine wether to draw label or not if (gai->distLOD < labelLOD){ if (!IsSetLocalFlag(NOT_LABELED)){ drawPointer->SetLabel ("", 0xff00ff00); // Don't label SetLocalFlag(NOT_LABELED); } } else if (IsSetLocalFlag(NOT_LABELED)){ SetLabel(this); UnSetLocalFlag(NOT_LABELED); } //if (IsSetLocalFlag(NOT_LABELED)) { // SetLabel(this); // UnSetLocalFlag(NOT_LABELED); //} } if (!targetPtr){ //rotate turret to be pointing forward again float maxAz = TURRET_ROTATE_RATE * SimLibMajorFrameTime; float maxEl = TURRET_ELEVATE_RATE * SimLibMajorFrameTime; float newEl; if (isAirDefense){ newEl = 60.0F*DTR; } else { newEl = 0.0F; } float delta = newEl - GetDOFValue(AIRDEF_ELEV); if(delta > 180.0F*DTR){ delta -= 180.0F*DTR; } else if(delta < -180.0F*DTR){ delta += 180.0F*DTR; } // Do elevation adjustments if (delta > maxEl){ SetDOFInc(AIRDEF_ELEV, maxEl); } else if (delta < -maxEl){ SetDOFInc(AIRDEF_ELEV, -maxEl); } else { SetDOF(AIRDEF_ELEV, newEl); } SetDOF(AIRDEF_ELEV, min(85.0F*DTR, max(GetDOFValue(AIRDEF_ELEV), 0.0F))); SetDOF(AIRDEF_ELEV2, GetDOFValue(AIRDEF_ELEV)); delta = 0.0F - GetDOFValue(AIRDEF_AZIMUTH); if(delta > 180.0F*DTR){ delta -= 180.0F*DTR; } else if(delta < -180.0F*DTR){ delta += 180.0F*DTR; } // Now do the azmuth adjustments if (delta > maxAz){ SetDOFInc(AIRDEF_AZIMUTH, maxAz); } else if (delta < -maxAz){ SetDOFInc(AIRDEF_AZIMUTH, -maxAz); } // RV - Biker - Don't do this //else // SetDOF(AIRDEF_AZIMUTH, 0.0F); } // Special shit by ground type if ( isFootSquad ){ if ( speedScale > 0.0f ){ // Couldn't this be done in the drawable class's update function??? ((DrawableGuys*)drawPointer)->SetSquadMoving( TRUE ); } else { // Couldn't this be done in the drawable class's update function??? ((DrawableGuys*)drawPointer)->SetSquadMoving( FALSE ); } // If we're less than 80% of the way from "FAR" toward the viewer, just draw one guy // otherwise, put 5 guys in a squad. if (gai->distLOD < 0.8f) { ((DrawableGuys*)drawPointer)->SetNumInSquad( 1 ); } else { ((DrawableGuys*)drawPointer)->SetNumInSquad( 5 ); } } // We're not a foot squad, so do the vehicle stuff else if ( !IsSetLocalFlag( IS_HIDDEN ) && speedScale > 300.0f ) { // speedScale /= ( 900.0f * KPH_TO_FPS * KPH_TO_FPS); // essentially 1.0F at 30 mph // JPO - for engine noise VehicleClassDataType *vc = GetVehicleClassData(Type() - VU_LAST_ENTITY_TYPE); ShiAssert(FALSE == F4IsBadReadPtr(vc, sizeof *vc)); // (a) Make sound: // everything sounds like a tank right now if ( GetCampaignObject()->IsBattalion() ){ //if (vc) if (vc && vc->EngineSound!=34){ // kludge prevent 34 from playing SoundPos.Sfx( vc->EngineSound, 0, 1.0, 0); // MLR 5/16/2004 - } else{ SoundPos.Sfx( SFX_TANK, 0, 1.0, 0); // MLR 5/16/2004 - } // (b) Make dust // dustTimer += SimLibMajorFrameTime; // if ( dustTimer > max( 0.2f, 4.5f - speedScale - gai->distLOD * 3.3f ) ) if ( ((rand() & 7) == 7) && gSfxCount[ SFX_GROUND_DUSTCLOUD ] < gSfxLODCutoff && gTotSfx < gSfxLODTotCutoff ){ // reset the timer // dustTimer = 0.0f; pos.x += PRANDFloat() * 5.0f; pos.y += PRANDFloat() * 5.0f; pos.z = groundZ; // RV - Biker - Move that smoke more behind the vehicle mlTrig trig; mlSinCos (&trig, Yaw()); pos.x -= 15.0f*trig.cos; pos.y -= 15.0f*trig.sin; vec.x = PRANDFloat() * 5.0f; vec.y = PRANDFloat() * 5.0f; vec.z = -20.0f; //JAM 24Oct03 - No dust trails when it's raining. if(realWeather->weatherCondition < INCLEMENT){ /* OTWDriver.AddSfxRequest( new SfxClass (SFX_VEHICLE_DUST, // type //JAM 03Oct03 // new SfxClass (SFX_GROUND_DUSTCLOUD, // type SFX_USES_GRAVITY | SFX_NO_DOWN_VECTOR | SFX_MOVES | SFX_NO_GROUND_CHECK, &pos, // world pos &vec, 1.0f, // time to live 1.f)); //JAM 03Oct03 8.5f )); // scale */ DrawableParticleSys::PS_AddParticleEx((SFX_VEHICLE_DUST + 1), &pos, &vec); } } // (c) Make sure we're using our 'Moving' model (i.e. Trucked artillery, APC, etc) if (truckDrawable){ // Keep truck 20 feet behind us (HACK HACK) Tpoint truckPos; mlTrig trig; mlSinCos (&trig, Yaw()); truckPos.x = XPos()-20.0F*trig.cos; truckPos.y = YPos()-20.0F*trig.sin; truckPos.z = ZPos(); truckDrawable->Update(&truckPos, Yaw()+PI); } if (isTowed || hasCrew){ SetSwitch(0,0x2); } } else // itsa task force { if (vc){ SoundPos.Sfx( vc->EngineSound, 0, 1.0, 0); } else { SoundPos.Sfx( SFX_SHIP, 0, 1.0, 0); } //RV - I-Hawk - Do wakes only at some cases if ( (rand() & 7) == 7 ) { //I-Hawk - not using all this anymore // // reset the timer // dustTimer = 0.0f; //float ttl; //static float trailspd = 5.0f; //static float bowfx = 0.92f; //static float sternfx = 0.75f; //float spdratio = GetVt() / ((UnitClass*)GetCampaignObject())->GetMaxSpeed(); float radius; if ( drawPointer ){ radius = drawPointer->Radius(); // JPO from 0.15 - now done inline } else{ radius = 90.0f; } //I-Hawk - Fixed position for ships wakes, effect "delay" in position is //handled by PS now. No more the "V shape" of water wakes. pos.x = XPos() + XDelta() * SimLibMajorFrameTime; pos.y = YPos() + YDelta() * SimLibMajorFrameTime; pos.z = groundZ; //// JPO - think this is sideways on. ///* //vec.x = dmx[1][0] * spdratio * PRANDFloat() * trailspd; //vec.y = dmx[1][1] * spdratio * PRANDFloat() * trailspd; //vec.z = 0.5f; // from -20 JPO //*/ //I-Hawk - More correct vector for wakes vec.x = XDelta(); vec.y = YDelta(); vec.z = 0.0f; //I-Hawk - Separate wake effect for different ships size int theSFX; if ( radius < 200.0f ) { theSFX = SFX_WATER_WAKE_SMALL; } else if ( radius >= 200.0f && radius < 400.0f ) { theSFX = SFX_WATER_WAKE_MEDIUM; } else if ( radius >= 400.0f ) { theSFX = SFX_WATER_WAKE_LARGE; } //I-Hawk - The PS DrawableParticleSys::PS_AddParticleEx((theSFX + 1), &pos, &vec); } } } // Otherwise, we're not moving or are hidden. Do some stuff else { // (b) Make sure we're using our 'Holding' model (i.e. Unlimbered artillery, troops prone, etc) if (truckDrawable){ // Once we stop, our truck doesn't move at all - but sits further away than when moving Tpoint truckPos; truckPos.x = XPos() + 40.0F; truckPos.y = YPos(); truckPos.z = 0.0F; truckDrawable->Update(&truckPos, Yaw()); } if (isTowed || hasCrew){ SetSwitch(0,0x1); } } // ACMI Output if (gACMIRec.IsRecording() && (SimLibFrameCount & 0x0f ) == 0){ ACMIGenPositionRecord genPos; genPos.hdr.time = SimLibElapsedTime * MSEC_TO_SEC + OTWDriver.todOffset; genPos.data.type = Type(); genPos.data.uniqueID = ACMIIDTable->Add(Id(),NULL,TeamInfo[GetTeam()]->GetColor());//.num_; genPos.data.x = XPos(); genPos.data.y = YPos(); genPos.data.z = ZPos(); genPos.data.roll = Roll(); genPos.data.pitch = Pitch(); genPos.data.yaw = Yaw(); // Remove genPos.data.teamColor = TeamInfo[GetTeam()]->GetColor(); gACMIRec.GenPositionRecord( &genPos ); } return IsLocal(); }
virtual EntityType getEntityType() const { return EntityType( EntityType::SYSTEM ); }