convert line ends
[canaan.git] / prj / cam / src / deepc / game / dpcalarm.cpp
blobdf3d138fa66779314fb69425a5af452d631bb0ac
1 /*
2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
4 */
6 // alarm icon
7 #include <2d.h>
8 #include <appagg.h>
10 #include <resapi.h>
11 #include <simtime.h>
12 #include <playrobj.h>
13 #include <scrnmode.h>
14 #include <schema.h>
15 #include <filevar.h>
16 #include <propbase.h>
17 #include <scrptapi.h>
19 #include <mprintf.h>
21 #include <dpcalarm.h>
22 #include <dpcovrly.h>
23 #include <dpcovcst.h>
24 #include <dpcplayr.h>
25 #include <dpcutils.h>
26 #include <dpcprop.h>
27 #include <dpcspawn.h>
29 IRes *gAlarmHnd;
31 //static Rect alarm_rect = {{10, 10},{10 + 80, 10 + 78}};
32 static Rect alarm_rect = {{10, 278},{10 + 64, 278 + 64}};
34 // Here's the type of my global
35 struct sAlarmCount
37 int m_count;
40 // Here's my descriptor, which identifies my stuff to the tag file & editor
41 sFileVarDesc gAlarmCountDesc =
43 kMissionVar, // Where do I get saved?
44 "ALARMCOUNT", // Tag file tag
45 "Alarm Count", // friendly name
46 FILEVAR_TYPE(sAlarmCount), // Type (for editing)
47 { 1, 0}, // version
48 { 1, 0}, // last valid version
49 "DPC", // optional: what game am I in NULL means all
52 // The actual global variable
53 cFileVar<sAlarmCount,&gAlarmCountDesc> gAlarmCount;
54 //--------------------------------------------------------------------------------------
55 void DPCAlarmInit(int which)
57 Rect use_rect;
58 gAlarmHnd= LoadPCX("alarm");
59 DPCOverlaySetFlags(which, kOverlayFlagTranslucent);
61 sScrnMode smode;
62 ScrnModeGet(&smode);
64 use_rect.ul.x = alarm_rect.ul.x;
65 use_rect.ul.y = smode.h - (480 - alarm_rect.ul.y);
66 use_rect.lr.x = use_rect.ul.x + RectWidth(&alarm_rect);
67 use_rect.lr.y = use_rect.ul.y + RectHeight(&alarm_rect);
69 DPCOverlaySetRect(which, use_rect);
72 //--------------------------------------------------------------------------------------
73 void DPCAlarmTerm(void)
75 SafeFreeHnd(&gAlarmHnd);
78 //--------------------------------------------------------------------------------------
79 void DPCAlarmDraw(unsigned long inDeltaTicks)
81 Point p;
82 Rect r = DPCOverlayGetRect(kOverlayAlarm);
83 int t, deltat;
84 int w,h;
85 int duration;
87 char temp[255];
88 t = GetSimTime();
89 if (!gPropHackTime->Get(PlayerObject(),&duration))
90 return;
91 deltat = duration - t;
92 if (deltat < 0)
94 DPCAlarmDisableAll();
96 else
98 sprintf(temp,"%.1f",(float)(deltat)/1000.0F);
99 w = gr_font_string_width(gDPCFont, temp);
100 h = gr_font_string_height(gDPCFont, temp);
101 p.x = r.ul.x + (RectWidth(&r) - w) / 2;
102 p.y = r.ul.y + RectHeight(&r) + 2;
103 gr_set_fcolor(gDPCTextColor);
104 gr_font_string(gDPCFont, temp, p.x, p.y);
107 //--------------------------------------------------------------------------------------
108 IRes *DPCAlarmBitmap(void)
110 return(gAlarmHnd);
112 //--------------------------------------------------------------------------------------
113 static IRes *gHackIconHnd;
114 static Rect full_rect = {{10,278},{10 + 64, 278 + 64}};
116 //--------------------------------------------------------------------------------------
117 void DPCHackIconInit(int which)
119 gHackIconHnd= LoadPCX("HackIcon");
121 DPCOverlaySetFlags(which, kOverlayFlagTranslucent);
123 sScrnMode smode;
124 ScrnModeGet(&smode);
125 Rect use_rect;
127 use_rect.ul.x = full_rect.ul.x;
128 use_rect.ul.y = smode.h - (480 - full_rect.ul.y);
129 use_rect.lr.x = use_rect.ul.x + RectWidth(&full_rect);
130 use_rect.lr.y = use_rect.ul.y + RectHeight(&full_rect);
132 DPCOverlaySetRect(which, use_rect);
135 //--------------------------------------------------------------------------------------
136 void DPCHackIconTerm(void)
138 SafeFreeHnd(&gHackIconHnd);
141 //--------------------------------------------------------------------------------------
142 IRes *DPCHackIconBitmap(void)
144 return(gHackIconHnd);
146 //--------------------------------------------------------------------------------------
147 void DPCHackIconDraw(unsigned long inDeltaTicks)
149 Point p;
150 ObjID plr;
151 int t, deltat;
152 int w,h;
153 int duration;
154 char temp[255];
155 Rect r = DPCOverlayGetRect(kOverlayHackIcon);
157 AutoAppIPtr(DPCPlayer);
159 plr = PlayerObject();
160 if (plr == OBJ_NULL)
161 return;
163 t = GetSimTime();
164 if (!gPropHackTime->Get(plr,&duration))
165 return;
166 deltat = duration - t;
168 // okay, this is kind of dumb to do during drawing
169 // but life is hard, then you die
170 if (deltat <= 0)
172 SchemaPlay((Label *)"xer04",NULL);
173 DPCOverlayChange(kOverlayHackIcon, kOverlayModeOff);
174 gPropHackVisibility->Set(plr,1.0);
175 pDPCPlayer->RecalcData(plr);
176 return;
179 sprintf(temp,"%.1f",(float)(deltat)/1000.0F);
180 w = gr_font_string_width(gDPCFont, temp);
181 h = gr_font_string_height(gDPCFont, temp);
182 p.x = r.ul.x + (RectWidth(&r) - w) / 2;
183 p.y = r.ul.y + RectHeight(&r) + 2;
184 gr_set_fcolor(gDPCTextColor);
185 gr_font_string(gDPCFont, temp, p.x, p.y);
187 //--------------------------------------------------------------------------------------
188 void DPCAlarmAdd(int time)
190 // so that there is never both hacked and alert at same time
191 AutoAppIPtr(DPCPlayer);
192 DPCOverlayChange(kOverlayHackIcon, kOverlayModeOff);
193 gPropHackVisibility->Set(PlayerObject(),1.0);
194 pDPCPlayer->RecalcData(PlayerObject());
196 if (gAlarmCount.m_count == 0)
197 DPCOverlayChange(kOverlayAlarm,kOverlayModeOn);
198 //else
199 //mprintf("Hey! AlarmCount is %d!\n",gAlarmCount.m_count);
201 gAlarmCount.m_count++;
202 gPropHackTime->Set(PlayerObject(),time);
204 //--------------------------------------------------------------------------------------
205 void DPCAlarmRemove(void)
207 if (gAlarmCount.m_count > 0)
209 gAlarmCount.m_count--;
210 if (gAlarmCount.m_count == 0)
212 DPCOverlayChange(kOverlayAlarm, kOverlayModeOff);
213 gPropHackTime->Set(PlayerObject(),0);
217 //--------------------------------------------------------------------------------------
218 void DPCAlarmDisableAll(void)
220 // iterate through all objects, and anything with a population system on it,
221 // and is alarmed, send it a reset, which will in turn reset any associated
222 // cameras.
223 ObjID obj;
224 sPropertyObjIter iter;
225 int ecostate;
226 BOOL alert = FALSE;
227 AutoAppIPtr(ScriptMan);
229 gPropEcology->IterStart(&iter);
230 while (gPropEcology->IterNext(&iter, &obj))
232 // are we an ecology
233 if (gPropEcoState->IsRelevant(obj))
235 gPropEcoState->Get(obj, &ecostate);
236 if (ecostate == kEcologyAlert)
238 // resetting the ecology will in turn reset any associated
239 // cameras & alarms
240 sScrMsg msg(obj,"Reset");
241 // This method may be running on any machine, so make sure the
242 // message gets through to the owner of the object:
243 msg.flags |= kSMF_MsgPostToOwner;
244 pScriptMan->SendMessage(&msg);
248 gPropEcology->IterStop(&iter);
250 //--------------------------------------------------------------------------------------
251 sOverlayFunc OverlayAlarm =
253 DPCAlarmDraw, // draw
254 DPCAlarmInit, // init
255 DPCAlarmTerm, // term
256 NULL, // mouse
257 NULL, // dclick (really use)
258 NULL, // dragdrop
259 NULL, // key
260 DPCAlarmBitmap, // bitmap
261 "", // upschema
262 "", // downschema
263 NULL, // state
264 NULL, // transparency
265 0, // distance
266 FALSE, // needmouse
267 75, // alpha
270 sOverlayFunc OverlayHackIcon =
272 DPCHackIconDraw, // draw
273 DPCHackIconInit, // init
274 DPCHackIconTerm, // term
275 NULL, // mouse
276 NULL, // dclick (really use)
277 NULL, // dragdrop
278 NULL, // key
279 DPCHackIconBitmap, // bitmap
280 "", // upschema
281 "", // downschema
282 NULL, // state
283 NULL, // transparency
284 0, // distance
285 FALSE, // needmouse
286 128, // alpha