std::ostream& SyncVar::operator<<(std::ostream& o) const{ if(!IsAggregate()) return o << Id(); o << "["; for(int i=0; i<u.aggregate->NumVars(); i++){ o << u.aggregate->Var(i) << ' '; } return o << "]"; }
/* 2002-02-11 COMMENTED OUT BY S.G. TOO MANY CHANGES TO TRACK THEM ALL (LIKE FOR OTHER UNIT TYPES) int TaskForceClass::DetectVs (CampEntity e, float *d, int *combat, int *spot) { int react,det; det = Detected(this,e,d); if (!(det & REACTION_MASK)) return 0; react = Reaction(e,det,*d); if (det & ENEMY_DETECTED) e->SetSpotted(GetTeam(),TheCampaign.CurrentTime); if (det & ENEMY_IN_RANGE && react) *combat = 1; if (det & FRIENDLY_DETECTED) { SetSpotted(e->GetTeam(),TheCampaign.CurrentTime); *spot = 1; } return react; } */ int TaskForceClass::DetectVs (CampEntity e, float *d, int *combat, int *spot) { int react,det; det = Detected(this,e,d); int detTmp = det; // Check type of entity before GCI is used if (CheckValidType(this, e)) detTmp |= e->GetSpotted(GetTeam()) ? ENEMY_DETECTED : 0; // Check type of entity before GCI is used if (CheckValidType(e, this)) detTmp |= GetSpotted(e->GetTeam()) ? FRIENDLY_DETECTED : 0; if (!(detTmp & REACTION_MASK)) return 0; react = Reaction(e,detTmp,*d); // We'll spot our enemy if we're not broken if (det & ENEMY_DETECTED) { if (IsAggregate() && CheckValidType(this, e)) e->SetSpotted(GetTeam(),TheCampaign.CurrentTime, (CanItIdentify(this, e, *d, e->GetMovementType()))); // 2002-02-11 MODIFIED BY S.G. Say 'identified if it has the hability to identify } if (det & ENEMY_IN_RANGE && react) *combat = 1; if (det & FRIENDLY_DETECTED) { // Spotting will be set only if our enemy is aggregated or if he's an AWAC. SensorFusion or GroundClass::Exec will hanlde deaggregated vehicles. if ((e->IsAggregate() && CheckValidType(e, this)) || (e->IsFlight() && e->GetSType() == STYPE_UNIT_AWACS)) { SetSpotted(e->GetTeam(),TheCampaign.CurrentTime, 1); // 2002-02-11 Modified by S.G. Ground units are always identified (doesn't change a thing) *spot = 1; } } return react; }
int TaskForceClass::StepRadar(int t, int d, float range)//me123 modifyed to take tracking/detection parameter { int radMode = GetRadarMode(); if (IsAggregate()) { // Check if we still have any radar vehicles if (class_data->RadarVehicle == 255 || !GetNumVehicles(class_data->RadarVehicle)) return FEC_RADAR_OFF; // Check if we're already in our fire state if (radMode == FEC_RADAR_GUIDE || radMode == FEC_RADAR_SEARCH_100) return radMode; // Check for switch over to guide if (radMode == FEC_RADAR_AQUIRE) { SetRadarMode(FEC_RADAR_GUIDE); return FEC_RADAR_GUIDE; } else { SetRadarMode(FEC_RADAR_AQUIRE); // KCK: Good operators could shoot before going to guide mode. Check skill and return TRUE if (GetRadarMode() == FEC_RADAR_AQUIRE && rand()%100 < TeamInfo[GetOwner()]->airDefenseExperience - MINIMUM_EXP_TO_FIRE_PREGUIDE) SetRadarMode(FEC_RADAR_GUIDE); return GetRadarMode(); } } assert (range); /* FEC_RADAR_OFF 0x00 // Radar always off FEC_RADAR_SEARCH_100 0x01 // Search Radar - 100 % of the time (always on) FEC_RADAR_SEARCH_1 0x02 // Search Sequence #1 FEC_RADAR_SEARCH_2 0x03 // Search Sequence #2 FEC_RADAR_SEARCH_3 0x04 // Search Sequence #3 FEC_RADAR_AQUIRE 0x05 // Aquire Mode (looking for a target) FEC_RADAR_GUIDE 0x06 // Missile in flight. Death is imminent*/ // Check if we still have any radar vehicles if (class_data->RadarVehicle == 255 || !GetNumVehicles(class_data->RadarVehicle )) return FEC_RADAR_OFF; assert(radarDatFileTable != NULL); RadarDataSet* radarData = &radarDatFileTable[((VehicleClassDataType *)Falcon4ClassTable[class_data->VehicleType[class_data->RadarVehicle]].dataPtr)->RadarType]; // Check if we're already in our fire state if (radMode == FEC_RADAR_SEARCH_100) return radMode; // Check for switch over to guide float skill = TeamInfo[GetOwner()]->airDefenseExperience/30.0f*1000; // from 1 - 3 skill *= (float)radarData->Timeskillfactor; skill /=100.0f; float timetosearch ; float timetoaquire ; if (!d && !t) SetRadarMode(search_mode); if (GetRadarMode() == FEC_RADAR_CHANGEMODE && search_mode >= FEC_RADAR_SEARCH_1 ) SetRadarMode(search_mode);// we are changing mode.. realy not off switch (GetRadarMode()) { case FEC_RADAR_OFF: timetosearch = radarData->Timetosearch1 - skill; if (range <= radarData->Rangetosearch1 && !SEARCHtimer) SEARCHtimer = SimLibElapsedTime; else if (range >= radarData->Rangetosearch1 || SimLibElapsedTime - SEARCHtimer > timetosearch+6000.0f)SEARCHtimer = 0; if (range <= radarData->Rangetosearch1 && SEARCHtimer && SimLibElapsedTime - SEARCHtimer > timetosearch ) { SEARCHtimer = SimLibElapsedTime; search_mode = FEC_RADAR_SEARCH_1 ; SetRadarMode(FEC_RADAR_SEARCH_1); } break; case FEC_RADAR_SEARCH_1: AQUIREtimer = SimLibElapsedTime; if (!SEARCHtimer) SEARCHtimer = SimLibElapsedTime; timetosearch = radarData->Timetosearch1 - skill; if (d && range <= radarData->Rangetosearch2 && SimLibElapsedTime - SEARCHtimer >= timetosearch) { SetRadarMode(FEC_RADAR_CHANGEMODE); search_mode = FEC_RADAR_SEARCH_2; SEARCHtimer = SimLibElapsedTime; } break; case FEC_RADAR_SEARCH_2: AQUIREtimer = SimLibElapsedTime; timetosearch = radarData->Timetosearch2 - skill; if (!SEARCHtimer) SEARCHtimer = SimLibElapsedTime; if (d && range <= radarData->Rangetosearch3 && SimLibElapsedTime - SEARCHtimer >= timetosearch) { search_mode =FEC_RADAR_SEARCH_3; SetRadarMode(FEC_RADAR_CHANGEMODE); SEARCHtimer = SimLibElapsedTime; } else if (!d)// no detection step search down { SetRadarMode(FEC_RADAR_CHANGEMODE); search_mode = FEC_RADAR_SEARCH_1 ; SEARCHtimer = SimLibElapsedTime; } break; case FEC_RADAR_SEARCH_3: AQUIREtimer = SimLibElapsedTime; timetosearch = radarData->Timetosearch3 - skill; if (!SEARCHtimer) SEARCHtimer = SimLibElapsedTime; // goto aquire ? if (d && range <= radarData->Rangetoacuire && SimLibElapsedTime - SEARCHtimer >= timetosearch ) { search_mode =FEC_RADAR_AQUIRE; SetRadarMode(FEC_RADAR_CHANGEMODE); AQUIREtimer = SimLibElapsedTime; } else if(!d)// no detection step search down { SetRadarMode(FEC_RADAR_CHANGEMODE); search_mode = FEC_RADAR_SEARCH_2 ; SEARCHtimer = SimLibElapsedTime; } break; case FEC_RADAR_AQUIRE: SEARCHtimer = 0; timetoaquire = radarData->Timetoacuire - skill; // only allow to be in aquire for the coast amount of time if (!t && !d && SimLibElapsedTime - AQUIREtimer >= (unsigned)radarData->Timetocoast) { SetRadarMode(FEC_RADAR_CHANGEMODE); search_mode = FEC_RADAR_SEARCH_3 ; } else if (t && range <= radarData->Rangetoguide && SimLibElapsedTime - AQUIREtimer >= timetoaquire) { search_mode =FEC_RADAR_GUIDE; SetRadarMode(FEC_RADAR_CHANGEMODE); return FEC_RADAR_GUIDE; } break; case FEC_RADAR_GUIDE: AQUIREtimer = SimLibElapsedTime; search_mode = FEC_RADAR_AQUIRE; if (!t) SetRadarMode(FEC_RADAR_CHANGEMODE); break; } /* else if (SimLibElapsedTime - AQUIREtimer > timetoaquire) { // KCK: Good operators could shoot before going to guide mode. Check skill and return TRUE if (GetRadarMode() == FEC_RADAR_AQUIRE && rand()%100 < TeamInfo[GetOwner()]->airDefenseExperience - MINIMUM_EXP_TO_FIRE_PREGUIDE) { search_mode = FEC_RADAR_AQUIRE ; SetRadarMode(FEC_RADAR_GUIDE); } } */ int out = GetRadarMode(); if (out == FEC_RADAR_OFF) out = search_mode; return out; }
int TaskForceClass::DoCombat (void) { int combat; SetCombatTime(TheCampaign.CurrentTime); #if 0 // JPO mthis stuff now done in Choose Target - like Battalion // KCK: Super simple targetting (c) Team who = GetTeam(); CampEntity e; FalconEntity *react_against=NULL,*air_react_against=NULL; int react,spot,best_reaction=1,best_air_react=1; int search_dist; float react_distance,air_react_distance,d; react_distance = air_react_distance = 9999.0F; SetEngaged(0); SetCombat(0); SetChecked(); search_dist = GetDetectionRange(Air); #ifdef VU_GRID_TREE_Y_MAJOR VuGridIterator detit(RealUnitProxList,YPos(),XPos(),(BIG_SCALAR)GridToSim(search_dist)); #else VuGridIterator detit(RealUnitProxList,XPos(),YPos(),(BIG_SCALAR)GridToSim(search_dist)); #endif e = (CampEntity)detit.GetFirst(); while (e) { if (GetRoE(who,e->GetTeam(),ROE_GROUND_FIRE) == ROE_ALLOWED) { combat = 0; react = DetectVs(e,&d,&combat,&spot); if (!e->IsFlight() && react >= best_reaction && d < react_distance) { // React vs a ground/Naval target best_reaction = react; react_distance = d; react_against = e; SetEngaged(1); SetCombat(combat); } else if (e->IsFlight() && react >= best_air_react && d < air_react_distance) { // React vs an air target - best_air_react = react; air_react_distance = d; air_react_against = e; if (!e->IsAggregate()) { // Pick a specific aircraft in the flight if it's deaggregated CampEnterCriticalSection(); if (e->GetComponents()) { VuListIterator cit(e->GetComponents()); FalconEntity *fe; float rsq,brsq=FLT_MAX; fe = (FalconEntity *)cit.GetFirst(); while (fe) { rsq = DistSqu(XPos(),YPos(),fe->XPos(),fe->YPos()); if (rsq < brsq) { air_react_against = fe; air_react_distance = (float)sqrt(rsq); brsq = rsq; } fe = (FalconEntity *)cit.GetNext(); } } CampLeaveCriticalSection(); } SetEngaged(1); SetCombat(combat); } } e = (CampEntity)detit.GetNext(); } if (air_react_against) SetAirTarget(air_react_against); if (react_against) SetTarget(react_against); #endif if (Engaged()) { FalconEntity *e = GetTarget(); FalconEntity *a = GetAirTarget(); // Check vs our Ground Target if (!e) SetTarget(NULL); else { if (Combat() && IsAggregate()) { combat = ::DoCombat(this,e); if (combat <= 0 || Targeted()) SetTargeted(0); } } // Check vs our Air Target if (!a) SetAirTarget(NULL); else if (Combat() && IsAggregate()) { combat = ::DoCombat(this,a); if (combat < 0) SetAirTarget(NULL); // Clear targeting data so we can look for another } } return 0; }