The UnitClass

Superclasses

VuEntity

FalconEntity

Other Subclasses: CampManagerClass , SimBaseClass,TeamClass

CampBaseClass

Subclasses: ObjectiveClass


UnitClass

Subclasses: AirUnitClass, GroundUnitClass, TaskForceClass
Def:
Implementation:

        private:
              CampaignTime            last_check;             // Last time we checked this unit
                fourbyte                        roster;                 // 4 byte bitwise roster
                fourbyte                        unit_flags;             // Various user flags
              GridIndex                       dest_x;                 // Destination
              GridIndex                       dest_y;
              VU_ID                           cargo_id;               // id of our cargo, or our carrier unit
              VU_ID                           target_id;              // Target we're engaged with (there can be only one! (c))
                uchar                           moved;          // Moves since check
                uchar                           losses;                 // How many vehicles we've lost
                uchar                           tactic;                 // Current Unit tactic
                ushort                          current_wp;             // Which WP we're heading to
                short                           name_id;                // Element number, used only for naming
                short                           reinforcement;  // What reinforcement level this unit becomes active at
                short                           odds;                   // How much shit is coming our way
                int                                     dirty_unit;

        public:
                UnitClassDataType       *class_data;
              DrawablePoint           *draw_pointer;  // inserted into draw list when unit aggregated
              WayPoint                        wp_list;

        public:
                // access functions
                CampaignTime GetLastCheck (void)        { return last_check; }
                fourbyte GetRoster (void)                       { return roster; }
                fourbyte GetUnitFlags (void)            { return unit_flags; }
                GridIndex GetDestX (void)                       { return dest_x; }
                GridIndex GetDestY (void)                       { return dest_y; }
                VU_ID GetCargoId (void)                         { return cargo_id; }
                VU_ID GetTargetId (void)                        { return target_id; }
                uchar GetMoved (void)                           { return moved; }
                uchar GetLosses (void)                          { return losses; }
                uchar GetTactic (void)                          { return tactic; }
                ushort GetCurrentWaypoint (void)        { return current_wp; }
                short GetNameId (void)                          { return name_id; }
                short GetReinforcement (void)           { return reinforcement; }
                short GetOdds (void)                            { return odds; }
                UnitClassDataType *GetClassData (void) { return class_data; }

                void SetLastCheck (CampaignTime);
                void SetRoster (fourbyte);
                void SetUnitFlags (fourbyte);
                void SetDestX (GridIndex);
                void SetDestY (GridIndex);
                void SetCargoId (VU_ID);
                void SetTargetId (VU_ID);
                void SetMoved (uchar);
                void SetLosses (uchar);
                void SetTactic (uchar);
                void SetCurrentWaypoint (ushort);
                void SetNameId (short);
                void SetReinforcement (short);
                void SetOdds (short);
                void MakeWaypointsDirty (void);

                // Dirty Functions
                void MakeUnitDirty (Dirty_Unit bits, Dirtyness score);
                void WriteDirty (unsigned char **stream);
                void ReadDirty (unsigned char **stream);

                // constructors and serial functions
                UnitClass(int type);
                UnitClass(VU_BYTE **stream);
                virtual ~UnitClass();
                virtual int SaveSize (void);
                virtual int Save (VU_BYTE **stream);

                // event Handlers
                virtual VU_ERRCODE Handle(VuFullUpdateEvent *event);

                // Required pure virtuals handled by UnitClass
                virtual void SendDeaggregateData (VuTargetEntity *);
                virtual int RecordCurrentState (FalconSessionEntity*, int);
                virtual int Deaggregate (FalconSessionEntity* session);
                virtual int Reaggregate (FalconSessionEntity* session);
                virtual int TransferOwnership (FalconSessionEntity* session);
                virtual int Wake (void);
                virtual int Sleep (void);
                virtual void InsertInSimLists (float cameraX, float cameraY);
                virtual void RemoveFromSimLists (void);
                virtual void DeaggregateFromData (int size, uchar* data);
                virtual void ReaggregateFromData (int size, uchar* data);
                virtual void TransferOwnershipFromData (int size, uchar* data);
                virtual int ResetPlayerStatus (void);
                virtual int ApplyDamage (FalconCampWeaponsFire *cwfm, uchar);
                virtual int ApplyDamage (DamType d, int *str, int where, short flags);
                virtual int DecodeDamageData (uchar *data, Unit shooter, FalconDeathMessage *dtm);
                virtual int CollectWeapons(uchar* dam, MoveType m, uchar w[], uchar wc[], int dist);
                virtual uchar* GetDamageModifiers (void);
                virtual _TCHAR* GetName (_TCHAR* buffer, int size, int object);
                virtual _TCHAR* GetFullName (_TCHAR* buffer, int size, int object);
                virtual _TCHAR* GetDivisionName (_TCHAR* buffer, int size, int object);
                virtual int GetHitChance (int mt, int range);
                virtual int GetAproxHitChance (int mt, int range);
                virtual int GetCombatStrength (int mt, int range);
                virtual int GetAproxCombatStrength (int mt, int range);
                virtual int GetWeaponRange (int mt);
                virtual int GetAproxWeaponRange (int mt);
                virtual int GetDetectionRange (int mt);                                         // Takes into account emitter status
                virtual int GetElectronicDetectionRange (int mt);                       // Max Electronic detection range, even if turned off
                virtual int CanDetect (FalconEntity* ent);                                              // Nonzero if this entity can see ent
                virtual void GetComponentLocation (GridIndex* x, GridIndex* y, int component);
                virtual int GetComponentAltitude (int component);
                virtual float GetRCSFactor (void);
                virtual float GetIRFactor (void);

                // These are only really relevant for sam/airdefense/radar entities
                virtual int GetNumberOfArcs (void);
                virtual float GetArcRatio (int anum);
                virtual float GetArcRange (int anum);
                virtual void GetArcAngle (int anum, float* a1, float *a2);
                virtual int GetRadarType (void);

                // Addition Virtual functions required by all derived classes
                virtual int CanShootWeapon (int)                                                      { return TRUE; };
                virtual int GetDeaggregationPoint (int, CampEntity*)    { return 0; }
                virtual UnitDeaggregationData* GetUnitDeaggregationData (void)  { return NULL; }
                virtual int     ShouldDeaggregate(void)                                                         {return TRUE;}
                virtual void ClearDeaggregationData (void)                                            {}
                virtual int Reaction (CampEntity, int, float)   { return 0; }
                virtual int MoveUnit (CampaignTime)                                             { return 0; }
                virtual int DoCombat (void)                                                                           { return 0; }
                virtual int ChooseTactic (void)                                                                 { return 0; }
                virtual int CheckTactic (int)                                                           { return 1; }
                virtual int Father (void)                                                                             { return 0; }
                virtual int Real (void)                                                                               { return 0; }
                virtual float AdjustForSupply(void)                                                             { return 1.0F; }
                virtual int GetUnitSpeed (void)                                                               { return GetMaxSpeed(); }
                virtual int DetectOnMove (void)                                                                 { return -1; }
                virtual int ChooseTarget (void)                                                                 { return -1; }
                virtual CampaignTime UpdateTime (void)                                                  { return CampaignDay; }
                virtual CampaignTime CombatTime (void)                                                { return CampaignDay; }
                virtual int GetUnitSupplyNeed (int)                                           { return 0; }
                virtual int GetUnitFuelNeed (int)                                                     { return 0; }
                virtual void SupplyUnit (int, int)                                      {}
                virtual int GetVehicleDeagData (SimInitDataClass*, int) { ShiWarning("Shouldn't be here"); return 0; }

                // Core functions
                void Setup(uchar stype, uchar sptype, Control who, Unit Parent);
                void SendUnitMessage (VU_ID id, short msg, short d1, short d2, short d3);
                void BroadcastUnitMessage (VU_ID id, short msg, short d1, short d2, short d3);
                int     ChangeUnitLocation (CampaignHeading h);
                int MoraleCheck (int shot, int lost);
                virtual int IsUnit (void)                                                                               { return TRUE; }

                // Unit flags
                void SetDead (int p);
                void SetAssigned (int p);
                void SetOrdered (int p);
                void SetDontPlan (int p);
                void SetParent (int p);
                void SetEngaged (int p);
                void SetScripted (int p);
                void SetCommando (int c);
                void SetMoving (int p);
                void SetRefused (int r);
                void SetHasECM (int e);
                void SetCargo (int c);
                void SetCombat (int p);
                void SetBroken (int p);
                void SetAborted (int p);
                void SetLosses (int p);
                void SetInactive (int i);
                void SetFragment (int f);
                void SetTargeted (int p);
                void SetRetreating (int p);
                void SetDetached (int p);
                void SetSupported (int s);
                void SetTempDest (int t);
                void SetFinal (int p);
                void SetPilots (int f);
                void SetDiverted (int d);
                void SetFired (int f);
                void SetLocked (int l);
                void SetIAKill (int f);
                void SetNoAbort (int f);
                virtual int IsDead (void)                                             { return (int)unit_flags & U_DEAD; }
                int Dead (void)                                                                 { return IsDead(); }
                int Assigned (void)                                                             { return (int)unit_flags & U_ASSIGNED; }
                int Ordered (void)                                                              { return (int)unit_flags & U_ORDERED; }
                int DontPlan (void)                                                             { return (int)unit_flags & U_NO_PLANNING; }
                int Parent (void)                                                               { return (int)unit_flags & U_PARENT; }
                int Engaged (void)                                                              { return (int)unit_flags & U_ENGAGED; }
                int Scripted (void)                                                             { return (int)unit_flags & U_SCRIPTED; }
                int Commando (void)                                                             { return (int)unit_flags & U_COMMANDO; }
                int Moving (void)                                                               { return (int)unit_flags & U_MOVING; }
                int Refused (void)                                                              { return (int)unit_flags & U_REFUSED; }
                int Cargo (void)                                                                { return (int)unit_flags & U_CARGO; }
                int Combat (void)                                                               { return (int)unit_flags & U_COMBAT; }
                int Broken (void)                                                               { return (int)unit_flags & U_BROKEN; }
                int Aborted (void)                                                              { return (int)unit_flags & U_BROKEN; }
                int Losses (void)                                                               { return (int)unit_flags & U_LOSSES; }
                int Inactive (void)                                                             { return (int)unit_flags & U_INACTIVE; }
                int Fragment (void)                                                             { return (int)unit_flags & U_FRAGMENTED; }
                int Targeted (void)                                                             { return (int)unit_flags & U_TARGETED; }
                int Retreating (void)                                                   { return (int)unit_flags & U_RETREATING; }
                int Detached (void)                                                             { return (int)unit_flags & U_DETACHED; }
                int Supported (void)                                                    { return (int)unit_flags & U_SUPPORTED; }
                int TempDest (void)                                                             { return (int)unit_flags & U_TEMP_DEST; }
                int Final (void)                                                                { return (int)unit_flags & U_FINAL; }
                int HasPilots (void)                                                    { return (int)unit_flags & U_HAS_PILOTS; }
                int Diverted (void)                                                             { return (int)unit_flags & U_DIVERTED; }
                int Fired (void)                                                                { return (int)unit_flags & U_FIRED; }
                int Locked (void)                                                               { return (int)unit_flags & U_LOCKED; }
                int IAKill (void)                                                               { return (int)unit_flags & U_IA_KILL; }
                int NoAbort (void)                                                              { return (int)unit_flags & U_NO_ABORT; }

                // Entity information
                UnitClassDataType* GetUnitClassData     (void);
                char* GetUnitClassName (void);
                void SetUnitAltitude (int alt)                                  { SetPosition(XPos(),YPos(),-1.0F * (float)alt); MakeCampBaseDirty (DIRTY_ALTITUDE, SEND_SOON); }
                int GetUnitAltitude (void)                                              { return FloatToInt32(ZPos()*-1.0F); }
              virtual void SimSetLocation (float x, float y, float z) { SetPosition(x,y,z); MakeCampBaseDirty (DIRTY_POSITION, SEND_SOON); MakeCampBaseDirty (DIRTY_ALTITUDE, SEND_SOON); }
              virtual void SimSetOrientation (float, float, float) {}
                virtual void GetRealPosition (float*, float*, float*) {}
                virtual int GetBestVehicleWeapon (int,uchar*,MoveType,int,int*);
                virtual int GetVehicleHitChance (int slot, MoveType mt, int range, int hitflags);
                virtual int GetVehicleCombatStrength (int slot, MoveType mt, int range);
                virtual int GetVehicleRange (int slot, int mt);
                virtual int GetUnitWeaponId (int hp, int slot);
                virtual int GetUnitWeaponCount (int hp, int slot);

                // Unit_data information
                void SetUnitDestination (GridIndex x, GridIndex y)      {       dest_x = (GridIndex)(x+1); dest_y = (GridIndex)(y+1); }
//              void SetUnitRoster (fourbyte r)                                 { roster = r; }
                void SetNumVehicles (int v, int n)                              { SetRoster ((roster & ~(3<<(v*2))) | (n << (v*2))); }
                void SetTarget (FalconEntity *e)                                { target_id = (e)? e->Id() : FalconNullId; }
                void SetUnitMoved (uchar m)                                             { moved = m; }
                void SetUnitTactic (uchar t)                                    { tactic = t; }
                void SetUnitReinforcementLevel (short r)                { reinforcement = r; }
                void GetUnitDestination (GridIndex* x, GridIndex* y);
//              fourbyte GetUnitRoster (void)                                   { return roster; }
                int GetNumVehicles (int v)                                              { return (int)((roster >> (v*2)) & 0x03); }
                FalconEntity* GetTarget (void)                                  { return (FalconEntity*) vuDatabase->Find(target_id); }
                VU_ID GetTargetID (void)                                                { return target_id; }
                SimBaseClass* GetSimTarget (void);
                CampBaseClass* GetCampTarget (void);
                CampEntity GetCargo (void);
                CampEntity GetTransport (void);
                VU_ID GetCargoID (void);
                VU_ID GetTransportID (void);
                int GetUnitMoved (void)                                                 { return moved; }
                int GetUnitTactic (void)                                                { return tactic; }
                int GetUnitReinforcementLevel (void)                    { return reinforcement; }
                void AssignUnit (VU_ID mgr, VU_ID po, VU_ID so, VU_ID ao, int orders);
                void SetUnitNameID (short id)                                   { name_id = id; }
                int SetUnitSType (char t);
                int SetUnitSPType (char t);
                int GetUnitNameID (void)                                                { return name_id; }

                // Attribute data
                VehicleID GetVehicleID (int v);
                int GetTotalVehicles (void);
                int GetFullstrengthVehicles (void);
                int GetFullstrengthVehicles (int slot);
                int GetMaxSpeed (void);
                int GetCruiseSpeed (void);
                int GetCombatSpeed (void);
                int GetUnitEndurance (void);
                int GetUnitRange (void);
                int GetRClass (void);

                // Support routines
                CampaignTime GetUnitReassesTime (void);
                int CountUnitElements (void);
                Unit GetRandomElement (void);
                void ResetMoves(void);
                void ResetLocations (GridIndex x, GridIndex y);
                void ResetDestinations (GridIndex x, GridIndex y);
                void ResetFlags (void);
                void SortElementsByDistance(GridIndex x, GridIndex y);
                int FirstSP (void);
                Unit FindPrevUnit (short *type);
                void SaveUnits (int FHandle, int flags);
                void BuildElements(void);
                int ChangeVehicles (int a);
                int GetFormationCruiseSpeed (void);
                void KillUnit (void);
                int NoMission(void);
                int AtDestination (void);
                int GetUnitFormation (void);
                int GetUnitRoleScore (int role, int calcType, int use_to_calc);
                float GetUnitMovementCost(GridIndex x, GridIndex y, CampaignHeading h);
                int GetUnitObjectivePath (Path p, Objective o, Objective t);
                int GetUnitGridPath (Path p, GridIndex x, GridIndex y, GridIndex xx, GridIndex yy);
                void LoadUnit (Unit cargo);
                void UnloadUnit (void);
                CampaignTime GetUnitSupplyTime (void);

                // Waypoint routines
                WayPoint AddUnitWP (GridIndex x, GridIndex y, int alt, int speed, CampaignTime arr, int station, uchar mission);
                WayPoint AddWPAfter (WayPoint pw, GridIndex x, GridIndex y, int alt, int speed, CampaignTime arr, int station, uchar mission);
                void DeleteUnitWP (WayPoint w);
                int EncodeWaypoints (uchar **stream);
                void DecodeWaypoints (uchar **stream);
                WayPoint GetFirstUnitWP (void)                          { return wp_list; }
                WayPoint GetCurrentUnitWP (void);
                WayPoint GetUnitMissionWP (void);
                void FinishUnitWP (void);
                void DisposeWayPoints (void);
                void CheckBroken (void);
                void SetCurrentUnitWP (WayPoint w);
                void AdjustWayPoints (void);

                // Virtual Functions (These are empty except for those derived classes they belong to)
                // AirUnit virtuals
                // None

                // Flight virtuals
                virtual void SetUnitLastMove (CampaignTime)                             {}
                virtual void SetCombatTime (CampaignTime)                                       {}
                virtual void SetBurntFuel (long)                                                {}
                virtual void SetUnitMission (uchar)                                             {}
                virtual void SetUnitRole (uchar)                                                        {}
                virtual void SetUnitPriority (int)                                              {}
                virtual void SetUnitMissionID (int)                                             {}
                virtual void SetUnitMissionTarget (int)                                 {}
                virtual void SetUnitTOT (CampaignTime)                                  {}
                virtual void SetUnitSquadron (VU_ID)                                            {}
                virtual void SetUnitAirbase (VU_ID)                                             {}
                virtual void SetLoadout (LoadoutStruct*, int)   { ShiWarning("Shouldn't be here"); }
                virtual int GetNumberOfLoadouts (void)                                          { return 0; }
               virtual CampaignTime GetMoveTime (void)                                         { return TheCampaign.CurrentTime - last_check; }
                virtual CampaignTime GetCombatTime (void)                                       { return 0; }
                virtual VU_ID GetAirTargetID (void)                                                     { return FalconNullId; }
                virtual FalconEntity* GetAirTarget (void)                                       { return NULL; }
                virtual int GetBurntFuel (void)                                                         { return 0; }
                virtual MissionTypeEnum GetUnitMission (void)                                                   { return (MissionTypeEnum)0; }
                virtual int GetUnitNormalRole (void)                                            { return 0; }
                virtual int GetUnitCurrentRole (void)                                           { return 0; }
                virtual int GetUnitPriority (void)                                                      { return 0; }
                virtual CampEntity GetUnitMissionTarget (void)                          { return NULL; }
                virtual VU_ID GetUnitMissionTargetID (void)                                     { return FalconNullId; }
                virtual int GetUnitMissionID (void)                                                     { return 0; }
                virtual CampaignTime GetUnitTOT (void)                                          { return 0; }
                virtual Unit GetUnitSquadron (void)                                                     { return NULL; }
                virtual VU_ID GetUnitSquadronID (void)                                          { return FalconNullId; }
                virtual CampEntity GetUnitAirbase (void)                                        { return NULL; }
                virtual VU_ID GetUnitAirbaseID (void)                                           { return FalconNullId; }
                virtual int LoadWeapons (void*, uchar*, MoveType, int, int, int)        { return 0; }
                virtual int DumpWeapons (void)                                                          { return 0; }
                virtual CampaignTime ETA (void)                                                         { return 0; }
                virtual F4PFList GetKnownEmitters (void)                                        { return NULL; }
                virtual int BuildMission(MissionRequestClass*)                  { return 0; }
                virtual void IncrementTime (CampaignTime)                               {}
                virtual void UseFuel (long)                                                     {}

                // Squadron virtuals
                virtual void SetUnitSpecialty (int)                                             {}
                virtual void SetUnitSupply (int)                                                        {}
                virtual void SetUnitMorale (int)                                                        {}
                virtual void SetSquadronFuel (long)                                             {}
                virtual void SetUnitStores (int, uchar)                                 {}
                virtual void SetLastResupply (int)                                              {}
                virtual void SetLastResupplyTime (CampaignTime)                 {}
                virtual int GetUnitSpecialty (void)                                                     { return 0; }
                virtual int GetUnitSupply (void)                                                        { return 0; }
                virtual int GetUnitMorale (void)                                                        { return 0; }
                virtual long GetSquadronFuel (void)                                                     { return 0; }
                virtual uchar GetUnitStores (int)                                                       { return 0; }
                virtual CampaignTime GetLastResupplyTime (void)                         { return TheCampaign.CurrentTime; }
                virtual int GetLastResupply (void)                                                      { return 0; }

                // Package virtuals
                virtual int BuildPackage(MissionRequest, F4PFList)      { return 0; }
                virtual void HandleRequestReceipt(int, int, VU_ID)                      {}
                virtual void SetUnitAssemblyPoint (int, GridIndex, GridIndex)           {}
                virtual void GetUnitAssemblyPoint (int, GridIndex*, GridIndex*) {}

                // Ground Unit virtuals
                virtual void SetUnitPrimaryObj (VU_ID)                                  {}
                virtual void SetUnitSecondaryObj (VU_ID)                                        {}
                virtual void SetUnitObjective (VU_ID)                                   {}
                virtual void SetUnitOrders (int)                                                        {}
                virtual void SetUnitOrders (int, VU_ID)                         {}
                virtual void SetUnitFatigue (int)                                               {}
//              virtual void SetUnitElement (int e)                                                     {}
                virtual void SetUnitMode (int)                                                  {}
                virtual void SetUnitPosition (int)                                              {}
                virtual void SetUnitDivision (int)                                              {}
                virtual void SetUnitHeading (int)                                                       {}
                virtual Objective GetUnitPrimaryObj (void)                                      { return NULL; }
                virtual Objective GetUnitSecondaryObj (void)                            { return NULL; }
                virtual Objective GetUnitObjective (void)                                       { return NULL; }
                virtual VU_ID GetUnitPrimaryObjID (void)                                        { return FalconNullId; }
                virtual VU_ID GetUnitSecondaryObjID (void)                                      { return FalconNullId; }
                virtual VU_ID GetUnitObjectiveID (void)                                         { return FalconNullId; }
                virtual int GetUnitOrders (void)                                                        { return 0; }
                virtual int GetUnitFatigue (void)                                                       { return 0; }
                virtual int GetUnitElement (void)                                                       { return 0; }
                virtual int GetUnitMode (void)                                                          { return 0; }
                virtual int GetUnitPosition (void)                                                      { return 0; }
                virtual int GetUnitDivision (void)                                                      { return 0; }
                virtual int GetUnitHeading (void)                                                       { return Here; }
                virtual void SetUnitNextMove (void)                                                     {}
                virtual void ClearUnitPath (void)                                                       {}
                virtual int GetNextMoveDirection (void)                                         { return Here; }
                virtual void SetUnitCurrentDestination(GridIndex, GridIndex)    {}
                virtual void GetUnitCurrentDestination(GridIndex*, GridIndex*)  {}
                virtual MoveType GetObjMovementType (Objective, int)    { return CampBaseClass::GetMovementType(); }
                virtual int CheckForSurrender (void)                                            { return 1; }
                virtual int BuildMission (void)                                                         { return 0; }
                virtual int RallyUnit (int)                                                     { return 0; }

                // Battalion virtuals
                virtual Unit GetUnitParent (void)                                                       { return NULL; }
                virtual VU_ID GetUnitParentID (void)                                            { return FalconNullId; }
                virtual void SetUnitParent (Unit)                                                       {}
#ifdef USE_FLANKS
                virtual void GetLeftFlank (GridIndex *x, GridIndex *y)          { GetLocation(x,y); }
                virtual void GetRightFlank (GridIndex *x, GridIndex *y)         { GetLocation(x,y); }
#endif

                // Brigade virtuals
                virtual Unit GetFirstUnitElement (void)                                         { return NULL; }
                virtual Unit GetNextUnitElement (void)                                          { return NULL; }
                virtual Unit GetUnitElement (int)                                                       { return NULL; }
                virtual Unit GetUnitElementByID (int)                                   { return NULL; }
                virtual Unit GetPrevUnitElement (Unit)                                  { return NULL; }
                virtual void AddUnitChild (Unit)                                                        {}
                virtual void DisposeChildren (void)                                                     {}
                virtual void RemoveChild (VU_ID)                                                {}
                virtual void ReorganizeUnit (void)                                                      {}
                virtual int UpdateParentStatistics (void)                                       { return 0; }

                // Naval Unit virtuals
                // None