2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
20 #include <netman.h> // for IsNetworkGame()
35 #include <vismeter.h> // Visibility meter.
37 IRes
*gHndHealth
= NULL
;
39 IRes
*gHndBioFull
= NULL
;
41 //--------------------------------------------------------------------------------------
42 // HP Meter initializer
43 //--------------------------------------------------------------------------------------
46 Rect meters_rect
= {{BIO_X
,BIO_Y
},{BIO_X
+ 260,BIO_Y
+ 64}}; // 128
48 void DPCMetersInit(int which
)
50 gHndHealth
= LoadPCX("hpbar");
51 gHndBio
= LoadPCX("bio");
52 gHndBioFull
= LoadPCX("biofull");
53 AssertMsg(gHndHealth
, "DPCMetersInit: Missing health bar art");
54 AssertMsg(gHndBio
, "DPCMetersInit: Missing bio art");
55 AssertMsg(gHndBioFull
, "DPCMetersInit: Missing bio full art");
60 use_rect
.ul
.x
= meters_rect
.ul
.x
;
61 use_rect
.ul
.y
= smode
.h
- (480 - meters_rect
.ul
.y
);
62 use_rect
.lr
.x
= use_rect
.ul
.x
+ RectWidth(&meters_rect
);
63 use_rect
.lr
.y
= use_rect
.ul
.y
+ RectHeight(&meters_rect
);
65 DPCOverlaySetRect(which
,use_rect
);
67 // @NOTE: Visibility meter code
71 //--------------------------------------------------------------------------------------
72 // Main Meters shutdown
73 //--------------------------------------------------------------------------------------
74 void DPCMetersTerm(void)
76 SafeFreeHnd(&gHndHealth
);
77 SafeFreeHnd(&gHndBio
);
78 SafeFreeHnd(&gHndBioFull
);
80 // @NOTE: Visibility meter code
84 //--------------------------------------------------------------------------------------
85 // Draw health meters.
86 //--------------------------------------------------------------------------------------
92 // @TODO: compute top and bottom margins for real
93 static float gStatusH
= 0.25; // %of screen
94 static float gStatusMargin
= 4.0f
/480.0f
; // %of screen
95 static int air_x
[2] = {655, 644};
96 static int hp_x
[2] = {1, 505};
98 static void DrawMeters(unsigned long inDeltaTicks
)
102 Rect r
= DPCOverlayGetRect(kOverlayMeters
);
104 // set initial vals in case we don't have relevant properties
110 if (gHndHealth
== NULL
)
112 //WARNING(("Could not get meter art!\n"));
116 // Determine the percentages.
117 ObjID po
= PlayerObject();
118 ObjGetHitPoints(po
, &hp
);
123 if (GetPlayerMode() == kPM_Dead
)
127 ObjGetMaxHitPoints(po
, &hpmax
);
129 grs_clip saveClip
= grd_gc
.clip
; // Clip it good!
131 grd_gc
.clip
= saveClip
;
132 gr_set_fcolor(gDPCTextColor
);
134 grs_bitmap
*bm
= (grs_bitmap
*) gHndHealth
->Lock();
137 if ((hp
== 0) || (hpmax
== 0))
143 clippix
= (bm
->w
* hp
/ hpmax
);
151 gr_safe_set_cliprect(HP_X
+ r
.ul
.x
,HP_Y
+ r
.ul
.y
,HP_X
+ r
.ul
.x
+ clippix
,HP_Y
+ r
.ul
.y
+ bm
->h
);
152 gr_bitmap(bm
, HP_X
+ r
.ul
.x
, HP_Y
+ r
.ul
.y
);
153 gHndHealth
->Unlock();
155 AssertMsg(gDPCFont
, "DrawMeters: No font!");
156 grd_gc
.clip
= saveClip
;
157 sprintf(temp
,"%d", hp
); // / %d",hp,hpmax);
158 gr_font_string(gDPCFont
,temp
, HPTEXT_X
+ r
.ul
.x
, HPTEXT_Y
+ r
.ul
.y
);
161 // @NOTE: Visibility meter code
162 int bot
= (int)(grd_canvas
->bm
.h
* (1.0f
- gStatusMargin
));
164 if (bot
> grd_canvas
->bm
.h
- 1)
166 bot
= grd_canvas
->bm
.h
-1;
169 int top
= bot
-(int)(grd_canvas
->bm
.h
*gStatusH
);
170 // @ render_stat_bars(msec,top,bot);
172 // compute rect for vis meter
173 enum {kExtentX
= 640, kExtentY
= 480};
174 Rect vis_r
= { 0, top
, 0, bot
};
175 vis_r
.ul
.x
= hp_x
[1] * grd_canvas
->bm
.w
/kExtentX
;
176 vis_r
.lr
.x
= air_x
[0] * grd_canvas
->bm
.w
/kExtentX
;
178 VisMeterUpdate(inDeltaTicks
, &vis_r
);
181 //--------------------------------------------------------------------------------------
183 //--------------------------------------------------------------------------------------
184 void DPCMetersDraw(unsigned long inDeltaTicks
)
187 // @Note: Draws the bio meter.
188 IRes
*useres
= (!DPC_mouse
) ? gHndBio
: gHndBioFull
;
190 grs_bitmap
*bm
= (grs_bitmap
*)useres
->Lock();
191 Rect r
= DPCOverlayGetRect(kOverlayMeters
);
192 gr_bitmap(bm
, r
.ul
.x
, r
.ul
.y
);
196 mouse_get_xy(&mpt
.x
,&mpt
.y
);
197 if (RectTestPt(&r
,mpt
))
199 if (mpt
.x
- r
.ul
.x
< HPTEXT_X
)
201 DPCStringFetch(gHelpString
, sizeof(gHelpString
), "MouseHelpHP", "misc");
205 DrawMeters(inDeltaTicks
);
208 //--------------------------------------------------------------------------------------
209 // Basic Meters handling. Also covers the inventory popup by virtue of
210 // calling the InvFindObjSlot which covers both quick slots & real slots
211 //--------------------------------------------------------------------------------------
212 bool DPCMetersHandleMouse(Point pt
)
216 if (DPC_cursor_mode
== SCM_DRAGOBJ
)
217 DPCInvAddObj(PlayerObject(),drag_obj
);
219 AutoAppIPtr(DPCPlayer
);
221 if (DPC_cursor_mode
== SCM_LOOK
)
223 ObjID fakeobj
= OBJ_NULL
;
224 extern Rect fake_rects
[4];
225 Rect r
= DPCOverlayGetRect(kOverlayTicker
);
226 Rect r2
= DPCOverlayGetRect(kOverlayMeters
);
228 usept
.x
= pt
.x
+ r2
.ul
.x
;
229 usept
.y
= pt
.y
+ r2
.ul
.y
;
231 // okay, we have to fixup the fake_rects for high resolution positioning, thus the offset
238 RectOffsettedRect(&fake_rects
[0], offset
, &userect
);
239 if (RectTestPt(&userect
,usept
))
241 fakeobj
= pDPCPlayer
->GetEquip(PlayerObject(), kEquipFakeNanites
);
245 RectOffsettedRect(&fake_rects
[1], offset
, &userect
);
246 if (RectTestPt(&userect
,usept
))
248 fakeobj
= pDPCPlayer
->GetEquip(PlayerObject(), kEquipFakeCookies
);
251 if (fakeobj
!= OBJ_NULL
)
253 DPCLookPopup(fakeobj
);
260 //--------------------------------------------------------------------------------------
261 // Handle drag/drop. This is mainly intended so we can split nanites.
262 // It only works in multiplayer, since it's kinda pointless in SP.
263 extern void DPCSplitStack(ObjID o
, BOOL leaveEmpty
);
264 bool DPCMetersDragDrop(Point pt
, BOOL start
)
266 AutoAppIPtr(NetManager
);
267 if (!pNetManager
->IsNetworkGame())
270 // For now, this only deals with the case where the player wants to
271 // split his nanites or cookies
272 if ((DPC_cursor_mode
== SCM_SPLIT
) && start
)
274 AutoAppIPtr(DPCPlayer
);
275 extern Rect fake_rects
[4];
277 Rect r
= DPCOverlayGetRect(kOverlayTicker
);
278 Rect r2
= DPCOverlayGetRect(kOverlayMeters
);
280 usept
.x
= pt
.x
+ r2
.ul
.x
;
281 usept
.y
= pt
.y
+ r2
.ul
.y
;
283 // okay, we have to fixup the fake_rects for high resolution positioning, thus the offset
290 RectOffsettedRect(&fake_rects
[0], offset
, &userect
);
292 if (RectTestPt(&userect
, usept
))
294 ObjID o
= pDPCPlayer
->GetEquip(PlayerObject(), kEquipFakeNanites
);
298 DPCSplitStack(o
, TRUE
);
305 //--------------------------------------------------------------------------------------
306 // Check for transparency in the source art
307 //--------------------------------------------------------------------------------------
308 bool DPCMetersCheckTransp(Point p
)
312 int pix = HandleGetPix(gHndBio,p);
315 //mprintf("SICT: %d (%d)\n",retval,pix);