BrigadeClass::BrigadeClass(VU_BYTE **stream) : GroundUnitClass(stream) { if (load_log) { fprintf (load_log, "%08x BrigadeClass ", *stream - start_load_stream); fflush (load_log); } memset (element,0,sizeof(VU_ID)*MAX_UNIT_CHILDREN); memcpy(&elements, *stream, sizeof(uchar)); *stream += sizeof(uchar); memcpy(element, *stream, sizeof(VU_ID)*elements); *stream += sizeof(VU_ID)*elements; #ifdef DEBUG for (int i=0; i<elements; i++) element[i].num_ &= 0x0000ffff; #endif c_element = 0; fullstrength = 0; #ifdef DEBUG char buffer[256]; sprintf(buffer,"campaign\\save\\dump\\%d.BRI",GetCampID()); unlink(buffer); #endif }
int BrigadeClass::ChooseTactic (void) { int priority=0,tid; haveWeaps = -1; tid = GTACTIC_BRIG_SECURE; while (tid < FirstGroundTactic + GroundTactics && !priority) { priority = CheckTactic(tid); if (!priority) tid++; } // Make Adjustments due to tactic if (tid == GTACTIC_BRIG_WITHDRAW) { Objective o; o = GetUnitObjective(); if (!o || !o->IsSecondary()) { // Find a retreat path o = FindRetreatPath(this,3,FIND_SECONDARYONLY); if (o) SetUnitOrders(GORD_RESERVE,o->Id()); // KCK: This will cause the whole brigade to surrender if the first element get's // cutoff and we're withdrawing. So I'm axing it. Instead, we'll just wait until // the element surrenders. // else // CheckForSurrender(); SetOrdered(1); } } if (GetUnitTactic() != tid) SetOrdered(1); SetUnitTactic(tid); #ifdef ROBIN_GDEBUG if (TrackingOn[GetCampID()]) MonoPrint("Brigade %d (%s) chose tactic %s.\n",GetCampID(),OrderStr[GetUnitOrders()],TacticsTable[tid].name); #endif return tid; }
//CampID const _CAMP_DATA *Obj_Character::GetCampData(VOID) { const _CAMP_DATA *pCampData = GetBaseCampData(); if ( pCampData != NULL ) { m_CampDataRefix = *pCampData; m_CampDataRefix.m_nCampID = GetCampID(); return &m_CampDataRefix; } else { return NULL; } }
// This calculates the maximum speed we can travel as a whole unit int BrigadeClass::GetUnitSpeed (void) { int speed = 9999; Battalion e; e = (Battalion)GetFirstUnitElement(); if (!e) return GetCruiseSpeed(); while (e) { if (speed > e->GetCruiseSpeed()) speed = e->GetCruiseSpeed(); e = (Battalion)GetNextUnitElement(); } if (speed > 9000) MonoPrint("Warning: Unit %d exceeding maximum warp!\n",GetCampID()); return speed; }
int SquadronClass::MoveUnit (CampaignTime time) { GridIndex x,y,nx,ny; VuGridIterator* myit = NULL; Objective o,bo=NULL; float fd; int range,score,i,want_alert=0,bs=-999; CampEntity ab; /* Don't recall squadrons - per Gilman if (GetTotalVehicles() < GetFullstrengthVehicles() / 4) { if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_RECALLED,0,0); KillUnit(); } */ //TJL 11/02/03 Enable Scramble missions if (g_bScramble) { // Set up an alert bird for this squadron if (rating[ARO_CA] > 4) { // KCK: Check if we have available aircraft // NOTE: We might want to make sure we always ask for at least one // alert flight. for (i=0; i<VEHICLES_PER_UNIT/2; i++) { if (!schedule[i]) want_alert = 1; } if (want_alert) { //#ifdef DEBUG MonoPrint("Requesting alert bird for squadron #%d.\n",GetCampID()); //#endif MissionRequestClass mis; // JB 010728 Make the wait time configurable // MN 020102 This is not the relocation timer - check above // mis.tot = Camp_GetCurrentTime() + g_nRelocationWait * CampaignHours; // hang around for a few hours mis.tot = Camp_GetCurrentTime() + 3 * CampaignHours; mis.requesterID = Id(); mis.who = GetTeam(); mis.vs = GetEnemyTeam(mis.who); mis.tot_type = TYPE_NE; GetLocation(&mis.tx,&mis.ty); mis.targetID = FalconNullId; mis.mission = AMIS_ALERT; mis.roe_check = ROE_AIR_ENGAGE; mis.flags = REQF_ONETRY | REQF_USE_REQ_SQUAD | REQF_USERESERVES; mis.priority = 255; // High priority mis.RequestMission(); } } } else { } //TJL 11/02/03 End Scramble // OW AB Relocation fix if(g_bEnableABRelocation) { if(SimLibElapsedTime < 32450000.0f) return 0; //me123 dont relocate before the campaign has begun } ab = FindEntity(airbase_id); // A.S. begin CampEntity ab_old; // A.S. new variable if (g_bHelosReloc) { ab_old = ab; } // A.S. end ShiAssert (!ab || ab->IsObjective() || ab->IsTaskForce() || (ab == this && DontPlan())); if (!ab || ab->IsObjective() || ab == this) { // Don't plan flag used to mean don't rebase for squadrons if (DontPlan()) { // 2001-08-06 MODIFIED BY S.G. FRIENDLY BASE WILL DO THE JOB ALL RIGHT. NO NEED TO LIMIT IT TO OUR TEAM. // if (ab->GetTeam() != GetTeam()) if (!ab || !GetRoE(ab->GetTeam(), GetTeam(), ROE_AIR_USE_BASES)) { if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_RECALLED,0,0); KillUnit(); } return 0; } // If airbase is non-functional, force a rebase // 2001-08-03 MODIFIED BY S.G. ONLY IF CAPTURED SHOULD IT RELOCATE. DESTROYED AIRBASE STILL OWN BY US WILL REPAIR EVENTUALLY. // if (ab && ab->IsObjective() && ((Objective)ab)->GetAdjustedDataRate() < 1) if (ab && ab->IsObjective() && !GetRoE(ab->GetTeam(), GetTeam(), ROE_AIR_USE_BASES)) ab = NULL; // Added by A.S. 1.1.2002. Helos will be reallocated if armybase is destoyed. if (g_bHelosReloc) { if (ab && ab->IsObjective() && IsHelicopter() && ((Objective)ab)->GetAdjustedDataRate() < 1) { ab = NULL; // FILE *deb; // deb = fopen("c:\\temp\\realloc.txt", "a"); // fprintf(deb, "ArmyBase ID = %d team = %x type = %x TIME = %d\n", ab_old, ab_old->GetTeam, ab_old->GetType, TheCampaign.CurrentTime/(3600*1000)); // fclose(deb); } } // A.S. end // Check airbase location - if to near or far from front, relocate GetLocation(&x,&y); fd = DistanceToFront(x,y); range = GetUnitRange(); // 2001-07-05 MODIFIED BY S.G. DON'T RELOCATE IF TOO FAR FROM FLOT IF GLOBALLY SET TO ACT THAT WAY // if (fd < 999.0F && (fd < range/30 || fd > range/3 || !ab)) // We're to close or to far from the front or don't have an airbase if (fd < 999.0F && (fd < range/30 || (!(g_nAirbaseReloc & AirBaseRelocNoFar) && fd > range/3) || !ab)) // We're to close or to far from the front or don't have an airbase { // Find a better base for us UnitClassDataType *uc = GetUnitClassData(); ATMAirbaseClass *atmbase; Team us = GetTeam(); CAMPREGLIST_ITERATOR myit(AllObjList); o = (Objective) myit.GetFirst(); while (o) { // 2001-07-05 MODIFIED BY S.G. ONLY USE YOUR OWN AIRBASE IF GLOBALLY SET TO ACT THAT WAY // if ((o->GetType() == TYPE_AIRBASE && !IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES)) || // (o->GetType() == TYPE_ARMYBASE && IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES))) int enter = FALSE; if (g_nAirbaseReloc & AirBaseRelocTeamOnly) { if ((o->GetType() == TYPE_AIRBASE && !IsHelicopter() && o->GetTeam() == us) || (o->GetType() == TYPE_ARMYBASE && IsHelicopter() && o->GetTeam() == us)) enter = TRUE; } else { if ((o->GetType() == TYPE_AIRBASE && !IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES)) || (o->GetType() == TYPE_ARMYBASE && IsHelicopter() && GetRoE(o->GetTeam(),us,ROE_AIR_USE_BASES))) enter = TRUE; } if (enter) // END OF MODIFIED SECTION { o->GetLocation(&nx,&ny); fd = DistanceToFront(nx,ny); if (fd > range/15 && o->GetAdjustedDataRate() > 0) { score = o->GetObjectiveStatus()*5 - FloatToInt32(fd); // Adjust by number of squadrons already based here. atmbase = TeamInfo[us]->atm->FindATMAirbase (o->Id()); if (atmbase && atmbase->usage) // JB 010328 from Mad__Max //score /= atmbase->usage; { if (o != ab) score /= (atmbase->usage+1); if (o == ab) score /= atmbase->usage; } // JB 010328 from Mad__Max if (score > bs) { bo = o; bs = score; } } } o = (Objective) myit.GetNext(); } if (bo) { if (bo != ab) { bo->GetLocation(&nx,&ny); SetLocation(nx,ny); SetUnitAirbase(bo->Id()); TeamInfo[us]->atm->AddToAirbaseList(bo); if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_REBASED,0,0); // 2001-07-05 MODIFIED BY S.G. RETASK IN ONE DAY ONLY // 020102 M.N. Variable relocate time squadronRetaskAt = Camp_GetCurrentTime() + CampaignHours * g_nRelocationWait; // A.S. begin: retask time for Helos only 1 hour if (g_bHelosReloc) { if (ab_old && ab_old->IsObjective() && ((Objective)ab_old)->GetAdjustedDataRate() < 1) { if ( IsHelicopter() ) { squadronRetaskAt = Camp_GetCurrentTime() + CampaignHours * 1; // FILE *deb; // deb = fopen("c:\\temp\\realloc.txt", "a"); // fprintf(deb, "====> squadronRetaskAt ID = %d ID_neu %d team = %x type = %x TIME = %d\n\n", ab_old, bo, ab_old->GetTeam, ab_old->GetType, TheCampaign.CurrentTime/(3600*1000)); // fclose(deb); } } } // A.S. end +++++++++++++++++ } } else { // We're lost if (this == FalconLocalSession->GetPlayerSquadron()) PostMessage(FalconDisplay.appWin,FM_SQUADRON_RECALLED,0,0); KillUnit(); return 0; } } } // Set up an alert bird for this squadron //TJL 10/31/03 Move This /* if (rating[ARO_CA] > 5) { // KCK: Check if we have available aircraft // NOTE: We might want to make sure we always ask for at least one // alert flight. for (i=0; i<VEHICLES_PER_UNIT/2; i++) { if (!schedule[i]) want_alert = 1; } if (want_alert) { #ifdef DEBUG // MonoPrint("Requesting alert bird for squadron #%d.\n",GetCampID()); #endif MissionRequestClass mis; // JB 010728 Make the wait time configurable // MN 020102 This is not the relocation timer - check above // mis.tot = Camp_GetCurrentTime() + g_nRelocationWait * CampaignHours; // hang around for a few hours mis.tot = Camp_GetCurrentTime() + 3 * CampaignHours; mis.requesterID = Id(); mis.who = GetTeam(); mis.vs = GetEnemyTeam(mis.who); mis.tot_type = TYPE_NE; GetLocation(&mis.tx,&mis.ty); mis.targetID = FalconNullId; mis.mission = AMIS_ALERT; mis.roe_check = ROE_AIR_ENGAGE; mis.flags = REQF_ONETRY | REQF_USE_REQ_SQUAD | REQF_USERESERVES; mis.priority = 255; // High priority mis.RequestMission(); } } */ return 0; }
// Order elements will find the best _final_ positions for this brigades elements and order them to go there. // It's up to the elements to determine the method of getting there. int BrigadeClass::OrderElement(Unit e, F4PFList nearlist) { Objective o,bo; int neworders = GetUnitOrders(); int role; // Check to see if there's something more important to do o = GetUnitObjective(); role = GetNewRole(e,this); // Determine orders by role neworders = GetGroundOrders(role); switch (role) { case GRO_ATTACK: case GRO_ASSAULT: case GRO_AIRBORNE: case GRO_RECON: // Assign to best offensive objective bo = FindBestPosition(e, this, GRO_ATTACK, nearlist); break; case GRO_DEFENSE: case GRO_ENGINEER: case GRO_AIRDEFENSE: case GRO_FIRESUPPORT: case GRO_RESERVE: bo = FindBestPosition(e, this, role, nearlist); break; default: // Assign to an objective out of the way bo = FindBestPosition(e, this, GRO_RESERVE, nearlist); break; } // If we didn't find a location, then look for a reserve location if (!bo) { neworders = GORD_RESERVE; bo = FindBestPosition(e, this, GRO_RESERVE, nearlist); } if (bo) o = bo; ShiAssert (o); e->SetUnitOrders(neworders,o->Id()); e->SetAssigned(1); // ReorganizeUnit(e); // This needs to only reposition element e ReorganizeUnit(); #ifdef ROBIN_GDEBUG if (TrackingOn[GetCampID()]) { GridIndex x,y; o->GetLocation(&x,&y); MonoPrint("Battalion %d ordered to %s obj %d at %d,%d.\n",e->GetCampID(),OrderStr[neworders],o->GetCampID(),x,y); } #endif return 1; }
void BrigadeClass::SetUnitOrders (int neworders, VU_ID oid) { Objective o,so; GridIndex x,y,dx,dy; Unit e; SetOrdered(1); SetUnitTactic(0); o = FindObjective(oid); #ifdef DEBUG if (gDumping) { FILE *fp; int id1; char buffer[256]; char name1[80],name2[80],timestr[80]; sprintf(buffer,"campaign\\save\\dump\\%d.BRI",GetCampID()); fp = fopen(buffer,"a"); if (fp) { if (o) { o->GetName(name1,79,FALSE); id1 = o->GetCampID(); } else { sprintf(name1,"NONE"); id1 = 0; } GetName(name2,79,FALSE); GetTimeString(TheCampaign.CurrentTime,timestr); sprintf(buffer,"%s (%d) ordered to %s %s (%d) @ %s.\n",name2,GetCampID(),OrderStr[neworders],name1,id1,timestr); fprintf(fp,buffer); fclose(fp); } else gDumping = 0; } #endif if (!o) return; o->GetLocation(&dx,&dy); GetLocation(&x,&y); if ((x != dx || y != dy) && GetMovementType() != NoMove) { SetMoving(1); SetUnitDestination(dx,dy); } SetTempDest(0); if (neworders == GetOrders() && oid == GetUnitObjectiveID()) return; DisposeWayPoints(); SetUnitObjective(oid); GroundUnitClass::SetUnitOrders(neworders); // Reset component ordered state e = GetFirstUnitElement(); while (e) { e->SetAssigned(0); e = GetNextUnitElement(); } // If this is near the front, send a low priority request for an enemy recon patrol if (o->IsNearfront()) { MissionRequestClass mis; mis.tot = Camp_GetCurrentTime() + (rand()%MIN_TASK_GROUND + 30) * CampaignMinutes; mis.vs = GetTeam(); mis.tot_type = TYPE_NE; o->GetLocation(&mis.tx,&mis.ty); mis.targetID = Id(); mis.mission = AMIS_RECONPATROL; mis.roe_check = ROE_AIR_OVERFLY; mis.RequestEnemyMission(); } // Let's make sure our objective tree jives with our assignment if (o->IsSecondary()) { so = o->GetObjectiveParent(); if (so) SetUnitPrimaryObj(so->Id()); SetUnitSecondaryObj(o->Id()); } else if (o->IsPrimary()) { SetUnitPrimaryObj(o->Id()); SetUnitSecondaryObj(o->Id()); } else { so = o->GetObjectiveParent(); if (so) { SetUnitSecondaryObj(so->Id()); o = so->GetObjectiveParent(); if (o) SetUnitPrimaryObj(o->Id()); } } }