fsship.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544
  1. /*-------------------------------------------------------------------------
  2. * FSShip.h
  3. *
  4. * Declaration of FedSrv ships class (CFSShip) and derivatives for players and drones
  5. *
  6. * Owner:
  7. *
  8. * Copyright 1986-1998 Microsoft Corporation, All Rights Reserved
  9. *-----------------------------------------------------------------------*/
  10. #ifndef _FSSHIP_H_
  11. #define _FSSHIP_H_
  12. #define GETFSSHIP(pship) ((CFSShip *) (pship)->GetPrivateData())
  13. #define ISPLAYER(pship) (GETFSSHIP(pship)->IsPlayer())
  14. typedef TLargeBitMask<c_cPlayersMax + c_cDronesMax> ShipDirtyMask;
  15. class CFSMission;
  16. class CFSPlayer;
  17. class CFSDrone;
  18. class CAdminUser;
  19. const short c_chatBudgetMax = 100;
  20. const short c_chatBudgetCost = 20;
  21. //Never more than 20 parts (actually 19 plus room to grow)
  22. // 4 guns
  23. // 4 turrets
  24. // missile, shield, booster, chaff, dispenser, cloak
  25. // 5 cargo
  26. const int c_cbLoadout = sizeof(ShipLoadout) + 20 * sizeof(ExpandedPartData);
  27. /* CFSShip
  28. This is the common object for players and drones
  29. Inherited classes must call Init during construction
  30. */
  31. class CFSShip // abstract base class
  32. {
  33. public:
  34. Money GetMoney() {return m_money;} // move this to Iship
  35. void SetMoney(Money money) {assert(money >= 0); m_money = money;}
  36. void AddKill()
  37. {
  38. m_pShip->AddKill();
  39. m_plrscore.AddKill();
  40. }
  41. void AddDeath()
  42. {
  43. m_pShip->AddDeath();
  44. m_plrscore.AddDeath();
  45. }
  46. void AddEjection()
  47. {
  48. m_pShip->AddEjection();
  49. m_plrscore.AddEjection();
  50. }
  51. bool GetHasUpdate(void) const { return m_bHasUpdate; }
  52. void SetHasUpdate(void) { m_bHasUpdate = true; }
  53. void ClearHasUpdate(void) { m_bHasUpdate = false; }
  54. float GetDeviation(void) const { return m_deviation; }
  55. void SetDeviation(float f) { m_deviation = f; }
  56. bool IsPlayer() {return m_fIsPlayer;}
  57. CFSPlayer * GetPlayer()
  58. {
  59. assert(IsPlayer());
  60. return (CFSPlayer *) this;
  61. }
  62. CFSDrone * GetDrone()
  63. {
  64. assert(!IsPlayer());
  65. return (CFSDrone *) this;
  66. }
  67. IshipIGC * GetIGCShip() const {return m_pShip;}
  68. ShipID GetShipID() {return m_pShip->GetObjectID();}
  69. // These are also on the IGC ship, but I'm not sure whether we'll be
  70. // able to guarantee that we always have an IGC ship.
  71. // This is the cluster the USER is in, not their IGC ship.
  72. IclusterIGC * GetCluster()
  73. {
  74. IstationIGC * pstation = m_pShip->GetStation();
  75. return pstation ? pstation->GetCluster() : m_pShip->GetCluster();
  76. }
  77. IsideIGC* GetSide() {return m_pShip->GetSide();}
  78. virtual void SetSide(CFSMission * pfsMission, IsideIGC * pside);
  79. IstationIGC * GetStation() {return m_pShip->GetStation();}
  80. const char * GetName() {return m_pShip->GetName();}
  81. static CFSShip * GetShipFromID(ShipID shipID)
  82. {
  83. assert (shipID < c_cShipsMax && shipID >= 0);
  84. return m_rgpfsShip[shipID];
  85. }
  86. void AnnounceExit(IclusterIGC* pclusterOld, ShipDeleteReason sdr);
  87. void ShipStatusSpotted(IsideIGC* pside);
  88. void ShipStatusExit(void);
  89. void ShipStatusHidden(IsideIGC* pside);
  90. void ShipStatusHullChange(IhullTypeIGC* pht);
  91. void ShipStatusDocked(IstationIGC* pstation);
  92. void ShipStatusLaunched(void);
  93. void ShipStatusStart(IstationIGC* pstation);
  94. void ShipStatusRestart(IstationIGC* pstation);
  95. void ShipStatusWarped(IwarpIGC* pwarp);
  96. void ShipStatusRecalculate(void);
  97. ShipStatus* GetShipStatus(SideID sid)
  98. {
  99. assert (sid >= 0);
  100. assert (sid < c_cSidesMax);
  101. return &(m_rgShipStatus[sid]);
  102. }
  103. ShipStatus* GetOldShipStatus(SideID sid)
  104. {
  105. assert (sid >= 0);
  106. assert (sid < c_cSidesMax);
  107. return &(m_rgOldShipStatus[sid]);
  108. }
  109. //void ShipLoadoutChange(LoadoutChange lc);
  110. void QueueLoadoutChange(bool bForce = false);
  111. virtual void Launch(IstationIGC* pstation);
  112. /*
  113. virtual bool UpdateIsValid() = 0;
  114. virtual void GetHeavyShipUpdate(HeavyShipUpdate * phsu) = 0;
  115. virtual void GetLightShipUpdate(LightShipUpdate * plsu) = 0;
  116. */
  117. virtual void Dock(IstationIGC * pstation) = 0;
  118. CFSMission * GetMission() {return m_pfsMission;}
  119. void HitWarp(IwarpIGC * pwarp);
  120. void CaptureStation(IstationIGC * pstation);
  121. virtual void Reset(bool bFull);
  122. void SetTreasureData(ObjectID oid, short amount)
  123. {
  124. assert (m_oidTreasure == NA);
  125. m_oidTreasure = oid;
  126. m_amountTreasure = amount;
  127. }
  128. void SetTreasureObjectID(TreasureID oid)
  129. {
  130. m_oidTreasure = oid;
  131. }
  132. ObjectID GetTreasureObjectID(void) const
  133. {
  134. return m_oidTreasure;
  135. }
  136. short GetTreasureAmount(void) const
  137. {
  138. return m_amountTreasure;
  139. }
  140. virtual void SetCluster(IclusterIGC * pcluster, bool bViewOnly = false);
  141. PlayerScoreObject* GetPlayerScoreObject(void)
  142. {
  143. return &m_plrscore;
  144. }
  145. void SetPlayerScoreObject(PlayerScoreObject* pplrscore)
  146. {
  147. if (pplrscore)
  148. m_plrscore = *pplrscore;
  149. else
  150. m_plrscore.Reset(true);
  151. }
  152. bool OkToWarp(void) const
  153. {
  154. return m_warpState == warpReady;
  155. }
  156. void SetWarpState(void)
  157. {
  158. m_warpState = warpNoUpdate;
  159. }
  160. void ResetWarpState(void)
  161. {
  162. m_warpState = warpReady;
  163. }
  164. protected:
  165. // can't instantiate this class. Must use inherited classes
  166. CFSShip(TRef<IshipIGC> pShip, bool fIsPlayer);
  167. ~CFSShip();
  168. enum WarpState
  169. { warpNoUpdate,
  170. warpWaiting,
  171. warpReady
  172. } m_warpState;
  173. Time m_timeNextWarp;
  174. private:
  175. PlayerScoreObject m_plrscore;
  176. ShipStatus m_rgShipStatus[c_cSidesMax];
  177. ShipStatus m_rgOldShipStatus[c_cSidesMax];
  178. CFSMission * m_pfsMission;
  179. TRef<IshipIGC> m_pShip; // must NOT be null;
  180. Money m_money;
  181. bool m_fIsPlayer; // T => CFSPlayer, F => CFSDrone
  182. static ShipID m_shipidNext; // next ship id to use
  183. static int m_cShips;
  184. static CFSShip* m_rgpfsShip[c_cShipsMax]; // indexed for O(1) lookup by ShipID
  185. ObjectID m_oidTreasure;
  186. short m_amountTreasure;
  187. bool m_bHasUpdate;
  188. float m_deviation;
  189. friend void FedSrvSiteBase::ChangeCluster(IshipIGC* pship,
  190. IclusterIGC* pclusterOld,
  191. IclusterIGC* pclusterNew);
  192. friend HRESULT FedSrvSiteBase::OnAppMessage(FedMessaging * pthis, CFMConnection & cnxn, FEDMESSAGE * pfm);
  193. };
  194. const unsigned char c_ucNone = 0;
  195. const unsigned char c_ucShipUpdate = 1;
  196. const unsigned char c_ucActiveTurretUpdate = 2;
  197. const unsigned char c_ucInactiveTurretUpdate = 3;
  198. class CFSPlayer :
  199. public CFSShip,
  200. public CAdminSponsor<CAdminUser>
  201. {
  202. public:
  203. CFSPlayer(CFMConnection * pcnxn, int characterId, const char * szCDKey,
  204. TRef<IshipIGC> pShip, bool fCanCheat);
  205. virtual ~CFSPlayer();
  206. CFMGroup * GetGroup() {return m_pgrp;}
  207. virtual void Launch(IstationIGC* pstation);
  208. virtual void Dock(IstationIGC * pstation);
  209. // these are for ship updates only
  210. static DWORD GetMaxLatency() {return m_latencyMax;}
  211. static DWORD GetAverageLatency() {return m_cUpdates ? m_latencyTotal / m_cUpdates : 0;}
  212. static void ResetLatency()
  213. {
  214. m_cUpdates = 0;
  215. m_latencyMax = 0;
  216. m_latencyTotal = 0;
  217. }
  218. unsigned char GetLastUpdate(void) const
  219. {
  220. return m_ucLastUpdate;
  221. }
  222. void ResetLastUpdate(void)
  223. {
  224. m_ucLastUpdate = c_ucNone;
  225. }
  226. void SetShipUpdate(const ClientShipUpdate& su);
  227. const ClientShipUpdate& GetShipUpdate(void) const { return m_su; }
  228. void SetActiveTurretUpdate(const ClientActiveTurretUpdate& atu);
  229. const ClientActiveTurretUpdate& GetActiveTurretUpdate(void) const { return m_atu; }
  230. void SetInactiveTurretUpdate(void);
  231. bool GetReady()
  232. {
  233. return m_fReady;
  234. }
  235. void SetReady(bool fReady);
  236. void UnreadyNoSide(void)
  237. {
  238. assert(GetSide() == NULL);
  239. m_fReady = false;
  240. }
  241. bool IsMissionOwner();
  242. Cookie GetCookie()
  243. {
  244. return m_cookie;
  245. }
  246. Cookie NewCookie()
  247. {
  248. ResetLastUpdate();
  249. return ++m_cookie;
  250. }
  251. int GetCharacterID()
  252. {
  253. return m_characterId;
  254. }
  255. const char* GetCDKey()
  256. {
  257. return m_strCDKey;
  258. }
  259. virtual void SetSide(CFSMission * pmission, IsideIGC * pside);
  260. bool CanCheat()
  261. {
  262. return m_fCanCheat;
  263. }
  264. CFSPlayer* GetAutoDonate(void) const
  265. {
  266. IshipIGC* pship = GetIGCShip()->GetAutoDonate();
  267. return pship ? ((CFSShip*)(pship->GetPrivateData()))->GetPlayer()
  268. : NULL;
  269. }
  270. void SetAutoDonate(CFSPlayer* pplayer, Money amount, bool bSend = true);
  271. CFMConnection * GetConnection()
  272. {
  273. return m_pcnxn;
  274. }
  275. static CFSPlayer * GetPlayerFromConnection(CFMConnection & cnxn)
  276. {
  277. return (CFSPlayer *)cnxn.GetPrivateData();
  278. }
  279. void SetDPGroup(CFSCluster* pfsCluster, bool bFlying);
  280. virtual void SetCluster(IclusterIGC * pcluster, bool bViewOnly = false);
  281. PersistPlayerScoreObjectList * GetPersistPlayerScoreObjectList()
  282. {
  283. return &m_perplrscoreList;
  284. }
  285. PersistPlayerScoreObject * GetPersistPlayerScore(CivID civID)
  286. {
  287. PersistPlayerScoreObjectLink * pl;
  288. for (pl = m_perplrscoreList.first(); pl; pl = pl->next())
  289. if (pl->data()->GetCivID() == civID)
  290. return pl->data();
  291. // Somebody's asking for a civ we don't have, so let's add it.
  292. PersistPlayerScoreObject * pperplrsco = new PersistPlayerScoreObject;
  293. pperplrsco->SetCivID(civID);
  294. m_perplrscoreList.last(pperplrsco);
  295. return pperplrsco;
  296. }
  297. SquadMembershipList * GetSquadMembershipList()
  298. {
  299. return &m_pSquadMembershipList;
  300. }
  301. bool GetIsMemberOfSquad(SquadID squadID);
  302. bool GetCanLeadSquad(SquadID squadID);
  303. SquadID GetPreferredSquadToLead();
  304. void SetLifepod(IclusterIGC* pcluster, const Vector& position)
  305. {
  306. m_pclusterLifepod = pcluster;
  307. m_positionLifepod = position;
  308. }
  309. IclusterIGC* GetLifepodCluster(void) const
  310. {
  311. return m_pclusterLifepod;
  312. }
  313. const Vector& GetLifepodPosition(void) const
  314. {
  315. return m_positionLifepod;
  316. }
  317. unsigned char GetBannedSideMask(void) const
  318. {
  319. return m_bannedSideMask;
  320. }
  321. void SetBannedSideMask(unsigned char bsm)
  322. {
  323. m_bannedSideMask = bsm;
  324. }
  325. void OrBannedSideMask(unsigned char bsm)
  326. {
  327. m_bannedSideMask |= bsm;
  328. }
  329. virtual void Reset(bool bFull)
  330. {
  331. m_chatBudget = c_chatBudgetMax;
  332. SetDPGroup(NULL, false);
  333. if (bFull)
  334. SetBannedSideMask(0);
  335. GetPlayerScoreObject()->Disconnect(g.timeNow);
  336. GetPlayerScoreObject()->Reset(bFull);
  337. CFSShip::Reset(bFull);
  338. }
  339. void IncrementChatBudget(void)
  340. {
  341. if (m_chatBudget < c_chatBudgetMax)
  342. m_chatBudget++;
  343. }
  344. bool DecrementChatBudget(bool bPay)
  345. {
  346. bool bSend;
  347. if (bPay)
  348. {
  349. bSend = m_chatBudget >= c_chatBudgetCost;
  350. m_chatBudget -= c_chatBudgetCost;
  351. if (m_chatBudget < -c_chatBudgetCost)
  352. m_chatBudget = -c_chatBudgetCost;
  353. }
  354. else
  355. bSend = m_chatBudget >= 0;
  356. return bSend;
  357. }
  358. void ForceLoadoutChange(void);
  359. void SaveDesiredLoadout(void)
  360. {
  361. {
  362. IpartIGC* ppart = GetIGCShip()->GetMountedPart(ET_Magazine, 0);
  363. m_ptDesiredLoadout[0] = (ppart && (ppart->GetPrice() == 0)) ? ppart->GetPartType() : NULL;
  364. }
  365. {
  366. IpartIGC* ppart = GetIGCShip()->GetMountedPart(ET_Dispenser, 0);
  367. m_ptDesiredLoadout[1] = (ppart && (ppart->GetPrice() == 0)) ? ppart->GetPartType() : NULL;
  368. }
  369. {
  370. IpartIGC* ppart = GetIGCShip()->GetMountedPart(ET_ChaffLauncher, 0);
  371. m_ptDesiredLoadout[2] = (ppart && (ppart->GetPrice() == 0)) ? ppart->GetPartType() : NULL;
  372. }
  373. for (Mount i = 0; (i < c_maxCargo); i++)
  374. {
  375. IpartIGC* ppart = GetIGCShip()->GetMountedPart(NA, -1 - i);
  376. m_ptDesiredLoadout[i + 3] = (ppart &&
  377. (ppart->GetPrice() == 0) &&
  378. (IlauncherIGC::IsLauncher(ppart->GetObjectType())))
  379. ? ppart->GetPartType()
  380. : NULL;
  381. }
  382. }
  383. IpartTypeIGC** GetDesiredLoadout(void)
  384. {
  385. return m_ptDesiredLoadout;
  386. }
  387. private:
  388. IpartTypeIGC* m_ptDesiredLoadout[c_maxCargo + 3];
  389. bool RemoveFromSide(bool fSendSideChange);
  390. unsigned char m_bannedSideMask;
  391. short m_chatBudget;
  392. PersistPlayerScoreObjectList m_perplrscoreList;
  393. SquadMembershipList m_pSquadMembershipList;
  394. CFSCluster* m_pfsClusterFlying;
  395. unsigned char m_ucLastUpdate;
  396. ClientActiveTurretUpdate m_atu;
  397. ClientShipUpdate m_su;
  398. Time m_timeUpdate;
  399. Time m_dwStartTime;
  400. int m_characterId; // character id in the database--constant over sessions
  401. CFMGroup * m_pgrp; // the *location* group I'm a member of--can only be one of:
  402. // everyone, flying(sector), or docked(sector)
  403. bool m_fInUse : 1;
  404. bool m_fReady : 1;
  405. bool m_fCanCheat : 1;
  406. Cookie m_cookie;
  407. static int m_latencyTotal; // aggregate over all updates
  408. static int m_cUpdates;
  409. static int m_latencyMax;
  410. CFMConnection * m_pcnxn;
  411. IclusterIGC* m_pclusterLifepod;
  412. Vector m_positionLifepod;
  413. ZString m_strCDKey;
  414. friend void FedSrvSiteBase::ChangeCluster(IshipIGC* pship,
  415. IclusterIGC* pclusterOld,
  416. IclusterIGC* pclusterNew);
  417. friend HRESULT FedSrvSiteBase::OnAppMessage(FedMessaging * pthis, CFMConnection & cnxn, FEDMESSAGE * pfm);
  418. };
  419. class CFSDrone : public CFSShip
  420. {
  421. public:
  422. CFSDrone(IshipIGC* pship);
  423. ~CFSDrone();
  424. virtual void Launch(IstationIGC* pstation);
  425. virtual void Dock(IstationIGC * pstation);
  426. void SetLastDamageReport(Time t)
  427. {
  428. m_timeLastDamageReport = t;
  429. }
  430. Time GetLastDamageReport(void) const
  431. {
  432. return m_timeLastDamageReport;
  433. }
  434. DroneTypeID GetDroneTypeID(void) const
  435. {
  436. return m_dtid;
  437. }
  438. void SetDroneTypeID(DroneTypeID dtid)
  439. {
  440. m_dtid = dtid;
  441. }
  442. private:
  443. Time m_timeLastDamageReport;
  444. DroneTypeID m_dtid;
  445. bool m_fInUse : 1;
  446. bool m_fUpdateToggle; // a drone update is valid every other cycle;
  447. static char m_rgfsDrone[];
  448. static int m_cDrones;
  449. static int m_ifsdNext; // next slot to use
  450. };
  451. #endif // _FSSHIP_H_