8 #define MAX_DEBUG_MARKS 80
14 } debugmarks
[MAX_DEBUG_MARKS
];
16 static int ndebugmarks
= 0;
17 static StringList DebugList
;
22 if (settings
->enable_debug_keys
)
25 if (justpushed(DEBUG_GOD_KEY
))
28 sound(SND_MENU_SELECT
);
31 if (justpushed(DEBUG_SAVE_KEY
))
33 game_save(settings
->last_save_slot
);
34 sound(SND_SWITCH_WEAPON
);
35 console
.Print("Game saved.");
38 if (justpushed(F6KEY
))
40 game
.debug
.DrawBoundingBoxes
^= 1;
41 sound(SND_COMPUTER_BEEP
);
44 if (justpushed(F9KEY
))
49 if (inputs
[DEBUG_FLY_KEY
])
51 player
->yinertia
= -0x880;
52 if (!player
->hurt_time
) player
->hurt_time
= 20; // make invincible
56 /*if (game.debug.debugmode)
58 //debug("%d fps", game.debug.fps);
62 //debug("<GOD MODE>");
63 player->weapons[player->curWeapon].level = 2;
64 player->weapons[player->curWeapon].xp = player->weapons[player->curWeapon].max_xp[2];
65 player->weapons[player->curWeapon].ammo = player->weapons[player->curWeapon].maxammo;
66 player->hp = player->maxHealth;
69 debug("%d,%d", (player->x>>CSF)/TILE_W, (player->y>>CSF)/TILE_H);
70 debug("[%c%c%c%c]", player->blockl?'l':' ', player->blockr?'r':' ', player->blocku?'u':' ', player->blockd?'d':' ');
71 //debug("%d", player->xinertia);
72 //debug("%d", player->yinertia);*/
74 debug("Have Puppy: %d", game.flags[274]);
75 debug("Kakeru: %d", game.flags[275]);
76 debug("Runner Gone: %d", game.flags[276]);
77 debug("No Shinobu: %d", game.flags[277]);
78 debug("Door Open: %d", game.flags[278]);
79 debug("Mick: %d", game.flags[279]);
80 debug("Gave 1st: %d", game.flags[590]);
81 debug("Gave 2nd: %d", game.flags[591]);
82 debug("Gave 3rd: %d", game.flags[592]);
83 debug("Gave 4th: %d", game.flags[593]);
84 debug("Gave 5th: %d", game.flags[594]);
88 for(i=0;i<player->ninventory;i++)
89 debug("%d", player->inventory[i]);
99 void DrawBoundingBoxes()
104 if (o
->onscreen
|| o
== player
)
112 else if (o
->flags
& FLAG_INVULNERABLE
)
116 else if (o
->flags
& FLAG_SHOOTABLE
)
120 else if (o
->flags
& FLAG_SOLID_MUSHY
)
129 AddDebugMark(o
->Left(), o
->Top(), o
->Right(), o
->Bottom(),
130 DM_BOX
, color
>>16, (color
>>8)&0xff, color
&0xff);
135 void DrawAttrPoints()
140 draw_pointlist(o
, &sprites
[o
->sprite
].block_l
);
141 draw_pointlist(o
, &sprites
[o
->sprite
].block_r
);
142 draw_pointlist(o
, &sprites
[o
->sprite
].block_u
);
143 draw_pointlist(o
, &sprites
[o
->sprite
].block_d
);
147 static void draw_pointlist(Object
*o
, SIFPointList
*points
)
149 int xoff
= (o
->x
>> CSF
);
150 int yoff
= (o
->y
>> CSF
);
152 for(int i
=0;i
<points
->count
;i
++)
154 DebugPixel((xoff
+ points
->point
[i
].x
) << CSF
, \
155 (yoff
+ points
->point
[i
].y
) << CSF
, 255, 0, 255);
160 void c------------------------------() {}
163 // debug text display debug() useful for reporting game vars etc
164 void debug(const char *fmt
, ...)
170 vsnprintf(buffer
, sizeof(buffer
), fmt
, ar
);
173 DebugList
.AddString(buffer
);
176 void debug_draw(void)
180 const char *text
= DebugList
.StringAt(i
);
183 int x
= (SCREEN_WIDTH
- 8) - GetFontWidth(text
, 0, true);
184 int y
= 4 + (i
* (GetFontHeight() + 1));
185 font_draw_shaded(x
, y
, text
, 0, &greenfont
);
191 DebugList
.MakeEmpty();
195 void c------------------------------() {}
198 extern char *object_names
[]; // from autogen'd objnames.cpp
200 // given an object type returns the name of the object e.g. "OBJ_TOROKO"
201 const char *DescribeObjectType(int type
)
203 if (type
>= 0 && type
< OBJ_LAST
&& object_names
[type
])
204 return stprintf("OBJ_%s(%d)", object_names
[type
], type
);
206 return stprintf("[Type %d]", type
);
209 // tries to convert a string, such as OBJ_TOROKO, into it's numeric type,
210 // with a small bit of english-language intelligence.
211 int ObjectNameToType(const char *name_in
)
213 // if all characters are numeric they're specifying by number
214 // so simply return the atoi
219 return atoi(name_in
);
222 if (!isdigit(name_in
[i
])) break;
225 char *name
= strdup(name_in
); // make string writeable
227 // some string preprocessing
228 for(int i
=0;name
[i
];i
++)
236 name
[i
] = toupper(name
[i
]);
240 // remove the "OBJ_" suffix if it's present
241 const char *searchstring
= name
;
242 if (strbegin(name
, "OBJ_"))
245 // search for it in the object_names table
246 for(int i
=0;i
<OBJ_LAST
;i
++)
248 if (object_names
[i
] && !strcmp(object_names
[i
], searchstring
))
255 stat("ObjectNameToType: couldn't find object 'OBJ_%s'", searchstring
);
260 const char *DescribeDir(int dir
)
264 case LEFT
: return "LEFT";
265 case RIGHT
: return "RIGHT";
266 case UP
: return "UP";
267 case DOWN
: return "DOWN";
268 case CENTER
: return "CENTER";
269 default: return stprintf("[Invalid Direction %d]", dir
);
274 void c------------------------------() {}
277 const char *strhex(int value
)
280 return stprintf("-0x%x", -value
);
282 return stprintf("0x%x", value
);
287 void c------------------------------() {}
290 void DrawDebugMarks(void)
296 for(i
=0;i
<ndebugmarks
;i
++)
298 x
= (debugmarks
[i
].x
>> CSF
) - (map
.displayed_xscroll
>> CSF
);
299 y
= (debugmarks
[i
].y
>> CSF
) - (map
.displayed_yscroll
>> CSF
);
300 x2
= (debugmarks
[i
].x2
>> CSF
) - (map
.displayed_xscroll
>> CSF
);
301 y2
= (debugmarks
[i
].y2
>> CSF
) - (map
.displayed_yscroll
>> CSF
);
306 switch(debugmarks
[i
].type
)
309 DrawPixel(x
, y
, r
, g
, b
);
313 DrawPixel(x
, y
, r
, g
, b
);
314 DrawPixel(x
+1, y
, r
, g
, b
);
315 DrawPixel(x
-1, y
, r
, g
, b
);
316 DrawPixel(x
, y
+1, r
, g
, b
);
317 DrawPixel(x
, y
-1, r
, g
, b
);
321 FillRect(x
, 0, x
, SCREEN_HEIGHT
, r
, g
, b
);
325 FillRect(0, y
, SCREEN_WIDTH
, y
, r
, g
, b
);
329 DrawRect(x
, y
, x2
, y2
, r
, g
, b
);
337 void AddDebugMark(int x
, int y
, int x2
, int y2
, char type
, uchar r
, uchar g
, uchar b
)
339 if (ndebugmarks
>= MAX_DEBUG_MARKS
)
342 debugmarks
[ndebugmarks
].x
= x
;
343 debugmarks
[ndebugmarks
].y
= y
;
344 debugmarks
[ndebugmarks
].x2
= x2
;
345 debugmarks
[ndebugmarks
].y2
= y2
;
346 debugmarks
[ndebugmarks
].r
= r
;
347 debugmarks
[ndebugmarks
].g
= g
;
348 debugmarks
[ndebugmarks
].b
= b
;
349 debugmarks
[ndebugmarks
].type
= type
;
353 // draw a pixel of the specified color at [x,y] in object coordinates
354 void DebugPixel(int x
, int y
, uchar r
, uchar g
, uchar b
)
356 AddDebugMark(x
, y
, 0, 0, DM_PIXEL
, r
, g
, b
);
359 void DebugCrosshair(int x
, int y
, uchar r
, uchar g
, uchar b
)
361 AddDebugMark(x
, y
, 0, 0, DM_CROSSHAIR
, r
, g
, b
);
364 void crosshair(int x
, int y
)
366 debugVline(x
, 255, 0, 0);
367 debugHline(y
, 0, 255, 0);
370 void DebugPixelNonCSF(int x
, int y
, uchar r
, uchar g
, uchar b
) { DebugPixel(x
<<CSF
,y
<<CSF
,r
,g
,b
); }
371 void DebugCrosshairNonCSF(int x
, int y
, uchar r
, uchar g
, uchar b
) { DebugCrosshair(x
<<CSF
,y
<<CSF
,r
,g
,b
); }
373 void debugVline(int x
, uchar r
, uchar g
, uchar b
)
375 AddDebugMark(x
, 0, 0, 0, DM_XLINE
, r
, g
, b
);
378 void debugHline(int y
, uchar r
, uchar g
, uchar b
)
380 AddDebugMark(0, y
, 0, 0, DM_YLINE
, r
, g
, b
);
383 void debugbox(int x1
, int y1
, int x2
, int y2
, uchar r
, uchar g
, uchar b
)
385 AddDebugMark(x1
, y1
, x2
, y2
, DM_BOX
, r
, g
, b
);
388 void debugtile(int x
, int y
, uchar r
, uchar g
, uchar b
)
392 x
*= (TILE_W
<< CSF
);
393 y
*= (TILE_H
<< CSF
);
396 x2
= x1
+ (TILE_W
<< CSF
);
397 y2
= y1
+ (TILE_H
<< CSF
);
398 AddDebugMark(x1
, y1
, x2
, y2
, DM_BOX
, r
, g
, b
);