convert line ends
[canaan.git] / prj / cam / src / ai / ainet.cpp
blob8a5f77009d6f39c8ec31e70d02c059711f4c4b0f
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/ai/ainet.cpp,v 1.5 2000/02/19 12:48:44 toml Exp $
8 //
9 // This module serves as the primary interface between AIs and networking.
12 #include <lg.h>
13 #include <appagg.h>
15 #include <netprops.h>
16 #include <netman.h>
18 #include <phnet.h>
20 #include <ainet.h>
21 #include <aibasctm.h>
22 #include <memall.h>
23 #include <dbmem.h> // must be last header!
25 ///////////////////////////////////////////////////////////////////////////////
27 // CLASS: cAINetwork
30 STDMETHODIMP_(const char *) cAINetwork::GetName()
32 return "Networking component";
35 ///////////////////////////////////////
37 STDMETHODIMP_(void) cAINetwork::Init()
39 SetNotifications(kAICN_ModeChange);
40 SetNotifications(kAICN_SimStart);
43 ///////////////////////////////////////
45 // When the AI changes modes, update its heartbeat rate appropriately.
46 // At the moment, the rates are hardcoded; this should probably be
47 // stored in some more flexible fashion in the long run...
50 // @TBD: These rates are chosen out of a hat, and should be tuned:
51 #define EFFICIENT_RATE 10000
52 STDMETHODIMP_(void) cAINetwork::OnModeChange(eAIMode previous, eAIMode mode)
54 AutoAppIPtr(NetManager);
55 switch(mode) {
56 case kAIM_Asleep:
57 case kAIM_Dead:
58 case kAIM_SuperEfficient:
59 case kAIM_Efficient:
60 if (previous > kAIM_Efficient)
61 PhysNetSetSleep(GetID(), TRUE);
62 break;
63 case kAIM_Normal:
64 case kAIM_Combat:
65 ObjSetHeartbeat(GetID(), mode==kAIM_Normal ? NORMAL_RATE : COMBAT_RATE);
66 if (previous < kAIM_Normal)
67 PhysNetSetSleep(GetID(), FALSE, TRUE);
68 break;
69 default:
70 Warning(("cAINetwork Mode Change: Unknown mode %d\n", mode));
71 break;
75 ///////////////////////////////////////////////////////////////////////////////
77 STDMETHODIMP_(void) cAINetwork::OnSimStart()
79 // This is now done in aiman::AllNetPlayersJoined() instead, due
80 // to timing constraints:
81 //eAIMode mode = m_pAIState->GetMode();
82 //AutoAppIPtr(NetManager);
83 //PhysNetSetSleep(GetID(), mode <= kAIM_Efficient);
84 //ObjSetHeartbeat(GetID(), mode==kAIM_Combat ? COMBAT_RATE : NORMAL_RATE);
87 ///////////////////////////////////////////////////////////////////////////////