Skip to content

Commit cd7945e

Browse files
committed
bug: don't bomb out on pcg warnings / also start to enchance UTF output for dungeon test
1 parent 7299eee commit cd7945e

15 files changed

+252
-36
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<!-- Bugs -->
22
<!-- ------ -->
33
<!-- player reflection off -->
4+
<!-- max damage per round should be 50 percent -->
5+
<!-- no flattened grass initially? -->
46
<!-- ------ -->
57
<!-- -->
68
<!-- Performance -->

python/things/fungus/fungus_common.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33

44
def tp_init(self):
55
# begin sort marker
6-
my.collision_hit_priority(self, 1)
7-
my.gfx_ascii_shown_as_gray_in_shadow(self, True)
8-
my.gfx_ascii_shown_in_bg(self, True)
9-
my.is_attackable_by_player(self, True)
10-
my.is_attackable_by_monst(self, True)
116
my.collision_check(self, True)
127
my.collision_hit_priority(self, 1)
138
my.collision_hit_priority(self, 3)
9+
my.gfx_ascii_shown_as_gray_in_shadow(self, True)
10+
my.gfx_ascii_shown_in_bg(self, True)
1411
my.gfx_ascii_shown(self, True)
1512
my.gfx_pixelart_animated(self, True)
1613
my.gfx_pixelart_reflection(self, True)
@@ -19,9 +16,10 @@ def tp_init(self):
1916
my.gfx_pixelart_shown_in_bg(self, True)
2017
my.gfx_pixelart_submergible(self, True)
2118
my.is_able_to_be_teleported(self, True)
22-
my.is_hittable(self, True)
2319
my.is_able_to_fall(self, True)
2420
my.is_able_to_freeze(self, True)
21+
my.is_attackable_by_monst(self, True)
22+
my.is_attackable_by_player(self, True)
2523
my.is_bag_item(self, True)
2624
my.is_biome_dungeon(self, True)
2725
my.is_biome_swamp(self, True)
@@ -31,9 +29,10 @@ def tp_init(self):
3129
my.is_described_when_hovering_over(self, True)
3230
my.is_food(self, True)
3331
my.is_fungus(self, True)
34-
my.is_light_blocker_for_monst(self, True) # to give cover
32+
my.is_hittable(self, True)
3533
my.is_interesting(self, True)
3634
my.is_item(self, True)
35+
my.is_light_blocker_for_monst(self, True) # to give cover
3736
my.is_only_one_per_tile(self, True)
3837
my.is_organic(self, True)
3938
my.is_throwable(self, True)

python/things/fungus/fungus_healing.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,25 @@ def on_death(me, x, y):
99
def tp_init(name, tiles=[]):
1010
self = tp.Tp(name, "divine fungus", "divine fungus")
1111
# begin sort marker
12+
my.collision_check(self, True)
13+
my.collision_hit_priority(self, 3)
1214
my.gfx_ascii_shown_as_gray_in_shadow(self, True)
1315
my.gfx_ascii_shown_in_bg(self, True)
1416
my.gfx_ascii_shown(self, True)
1517
my.gfx_pixelart_animated(self, True)
1618
my.gfx_pixelart_reflection(self, True)
17-
my.gfx_pixelart_shadow(self, True)
18-
my.gfx_pixelart_shadow_short(self, True)
1919
my.gfx_pixelart_shadow_long(self, True)
2020
my.gfx_pixelart_shadow(self, True)
21-
my.is_attackable_by_player(self, True)
22-
my.collision_check(self, True)
23-
my.collision_hit_priority(self, 3)
24-
my.is_attackable_by_monst(self, True)
21+
my.gfx_pixelart_shadow_short(self, True)
2522
my.gfx_pixelart_shadow_solid(self, True)
2623
my.gfx_pixelart_shown_in_bg(self, True)
2724
my.gfx_pixelart_submergible(self, True)
28-
my.is_hittable(self, True)
2925
my.health_initial_dice(self, "1")
3026
my.is_able_to_be_teleported(self, True)
3127
my.is_able_to_fall(self, True)
3228
my.is_able_to_freeze(self, True)
33-
my.is_light_blocker_for_monst(self, True) # to give cover to the player
29+
my.is_attackable_by_monst(self, True)
30+
my.is_attackable_by_player(self, True)
3431
my.is_biome_dungeon(self, True)
3532
my.is_biome_swamp(self, True)
3633
my.is_combustible(self, True)
@@ -39,8 +36,10 @@ def tp_init(name, tiles=[]):
3936
my.is_described_when_hovering_over(self, True)
4037
my.is_fungus_healing(self, True)
4138
my.is_fungus(self, True)
42-
my.is_light_blocker_for_monst(self, True) # to give cover
39+
my.is_hittable(self, True)
4340
my.is_interesting(self, True)
41+
my.is_light_blocker_for_monst(self, True) # to give cover
42+
my.is_light_blocker_for_monst(self, True) # to give cover to the player
4443
my.is_only_one_per_tile(self, True)
4544
my.is_organic(self, True)
4645
my.light_color(self, "pink")

src/ascii.cpp

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "my_array_bounds_check.hpp"
66
#include "my_ascii.hpp"
77
#include "my_color_defs.hpp"
8+
#include "my_console.hpp"
89
#include "my_font.hpp"
910
#include "my_game.hpp"
1011
#include "my_sdl_event.hpp"
@@ -23,7 +24,8 @@ int16_t ascii_mouse_y;
2324
class AsciiCell
2425
{
2526
public:
26-
Tilep tile[ TILE_LAYER_MAX ] {};
27+
wchar_t ch[ TILE_LAYER_MAX ] {};
28+
Tilep tile[ TILE_LAYER_MAX ] {};
2729

2830
Texp tex[ TILE_LAYER_MAX ] {};
2931

@@ -181,6 +183,7 @@ void ascii_set(int depth, int x, int y, const Texp tex, float tx, float ty, floa
181183

182184
AsciiCell *cell = &getref_no_check(cells, x, y);
183185

186+
cell->ch[ depth ] = 0;
184187
cell->tex[ depth ] = tex;
185188
cell->tx[ depth ] = tx;
186189
cell->ty[ depth ] = ty;
@@ -194,6 +197,21 @@ void ascii_set(int depth, int x, int y, const Tilep tile)
194197

195198
AsciiCell *cell = &getref_no_check(cells, x, y);
196199

200+
cell->ch[ depth ] = 0;
201+
cell->tile[ depth ] = tile;
202+
cell->tx[ depth ] = 0;
203+
cell->ty[ depth ] = 0;
204+
cell->dx[ depth ] = 1;
205+
cell->dy[ depth ] = 1;
206+
}
207+
208+
void ascii_set(int depth, int x, int y, const Tilep tile, wchar_t ch)
209+
{
210+
if (unlikely(! ascii_ok_for_scissors(x, y))) { return; }
211+
212+
AsciiCell *cell = &getref_no_check(cells, x, y);
213+
214+
cell->ch[ depth ] = ch;
197215
cell->tile[ depth ] = tile;
198216
cell->tx[ depth ] = 0;
199217
cell->ty[ depth ] = 0;
@@ -207,6 +225,7 @@ void ascii_set(int depth, int x, int y, const Tilep tile, float tx, float ty, fl
207225

208226
AsciiCell *cell = &getref_no_check(cells, x, y);
209227

228+
cell->ch[ depth ] = 0;
210229
cell->tile[ depth ] = tile;
211230
cell->tx[ depth ] = tx;
212231
cell->ty[ depth ] = ty;
@@ -216,7 +235,10 @@ void ascii_set(int depth, int x, int y, const Tilep tile, float tx, float ty, fl
216235

217236
void ascii_set(int depth, int x, int y, const char *tilename) { ascii_set(depth, x, y, tile_find(tilename)); }
218237

219-
void ascii_set(int depth, int x, int y, const wchar_t ch) { ascii_set(depth, x, y, font_ui->unicode_to_tile(ch)); }
238+
void ascii_set(int depth, int x, int y, const wchar_t ch)
239+
{
240+
ascii_set(depth, x, y, font_ui->unicode_to_tile(ch), ch);
241+
}
220242

221243
void ascii_putf__(int x, int y, color fg, color bg, const std::wstring text)
222244
{
@@ -357,6 +379,7 @@ void ascii_putf__(int x, int y, color fg, color bg, const std::wstring text)
357379
auto depth = TILE_LAYER_FG_0;
358380

359381
cell->tile[ depth ] = tile;
382+
cell->ch[ depth ] = ch;
360383
cell->color_tl[ depth ] = fg;
361384
cell->color_tr[ depth ] = fg;
362385
cell->color_bl[ depth ] = fg;
@@ -379,6 +402,7 @@ void ascii_putf__(int x, int y, color fg, color bg, const std::wstring text)
379402
cell->tile[ depth ] = nullptr;
380403
}
381404

405+
cell->ch[ depth ] = ch;
382406
cell->color_tl[ depth ] = bg;
383407
cell->color_tr[ depth ] = bg;
384408
cell->color_bl[ depth ] = bg;
@@ -946,6 +970,75 @@ static void ascii_blit(void)
946970
}
947971
}
948972

973+
void ascii_dump(void)
974+
{
975+
TRACE_NO_INDENT();
976+
977+
int x;
978+
int y;
979+
980+
putchar('+');
981+
for (x = 0; x < TERM_WIDTH; x++) {
982+
putchar('-');
983+
}
984+
putchar('+');
985+
putchar('\n');
986+
987+
for (y = 0; y < TERM_HEIGHT; y++) {
988+
putchar('|');
989+
for (x = 0; x < TERM_WIDTH; x++) {
990+
const AsciiCell *cell = &getref_no_check(cells, x, y);
991+
992+
color bg = COLOR_NONE;
993+
color fg = COLOR_NONE;
994+
995+
for (int depth = TILE_LAYER_BG_0; depth < TILE_LAYER_FG_0; depth++) {
996+
auto col = cell->color_tl[ depth ];
997+
if (col != COLOR_NONE) { bg = col; }
998+
}
999+
1000+
for (int depth = TILE_LAYER_FG_0; depth < TILE_LAYER_MAX; depth++) {
1001+
auto col = cell->color_tl[ depth ];
1002+
if (col != COLOR_NONE) { fg = col; }
1003+
}
1004+
1005+
char fgstr[ 80 ];
1006+
if ((fg != COLOR_NONE) && (bg != COLOR_NONE)) {
1007+
snprintf(fgstr, sizeof(fgstr), "\e[38;2;%u;%u;%u;48;2;%u;%u;%um", fg.r, fg.g, fg.b, bg.r, bg.g, bg.b);
1008+
fputs(fgstr, stdout);
1009+
} else if (fg != COLOR_NONE) {
1010+
snprintf(fgstr, sizeof(fgstr), "\e[38;2;%u;%u;%um", fg.r, fg.g, fg.b);
1011+
fputs(fgstr, stdout);
1012+
} else if (bg != COLOR_NONE) {
1013+
snprintf(fgstr, sizeof(fgstr), "\e[48;2;%u;%u;%um", bg.r, bg.g, bg.b);
1014+
fputs(fgstr, stdout);
1015+
} else {
1016+
snprintf(fgstr, sizeof(fgstr), "\e[39m\e[49m");
1017+
fputs(fgstr, stdout);
1018+
}
1019+
1020+
bool got_one = false;
1021+
for (int depth = TILE_LAYER_MAX - 1; depth >= 0; depth--) {
1022+
if (cell->ch[ depth ]) {
1023+
putwchar(cell->ch[ depth ]);
1024+
got_one = true;
1025+
break;
1026+
}
1027+
}
1028+
if (! got_one) { putchar(' '); }
1029+
}
1030+
putchar('|');
1031+
putchar('\n');
1032+
}
1033+
1034+
putchar('+');
1035+
for (x = 0; x < TERM_WIDTH; x++) {
1036+
putchar('-');
1037+
}
1038+
putchar('+');
1039+
putchar('\n');
1040+
}
1041+
9491042
//
9501043
// The big ascii renderer
9511044
//

src/console.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Copyright Neil McGill, [email protected]
33
//
44

5+
#include "my_color.hpp"
6+
#include "my_color_defs.hpp"
57
#include "my_console.hpp"
68
#include "my_main.hpp"
79
#include "my_sys.hpp"
@@ -194,3 +196,50 @@ void term_log(const char *s)
194196
putchar(c);
195197
}
196198
}
199+
200+
int term_color_to_console_color(color c)
201+
{
202+
if (c == BLACK) return TERM_COLOR_BLACK;
203+
if (c == BLUE) return TERM_COLOR_BLACK;
204+
if (c == BROWN) return TERM_COLOR_BLACK;
205+
if (c == COLOR_NONE) return TERM_COLOR_RESET;
206+
if (c == CYAN) return TERM_COLOR_CYAN;
207+
if (c == DARKBLUE) return TERM_COLOR_BLUE;
208+
if (c == DARKGRAY) return TERM_COLOR_BLACK;
209+
if (c == DARKGREEN) return TERM_COLOR_GREEN;
210+
if (c == DARKOLIVEGREEN2) return TERM_COLOR_GREEN;
211+
if (c == DARKOLIVEGREEN) return TERM_COLOR_GREEN;
212+
if (c == DARKRED) return TERM_COLOR_RED;
213+
if (c == DEEPWATER) return TERM_COLOR_BLUE;
214+
if (c == FORESTGREEN) return TERM_COLOR_GREEN;
215+
if (c == GOLD) return TERM_COLOR_YELLOW;
216+
if (c == GRAY10) return TERM_COLOR_BLUE;
217+
if (c == GRAY30) return TERM_COLOR_BLUE;
218+
if (c == GRAY40) return TERM_COLOR_BLUE;
219+
if (c == GRAY50) return TERM_COLOR_BLUE;
220+
if (c == GRAY5) return TERM_COLOR_BLUE;
221+
if (c == GRAY60) return TERM_COLOR_WHITE;
222+
if (c == GRAY70) return TERM_COLOR_WHITE;
223+
if (c == GRAY80) return TERM_COLOR_WHITE;
224+
if (c == GRAY90) return TERM_COLOR_WHITE;
225+
if (c == GRAY) return TERM_COLOR_WHITE;
226+
if (c == GREEN) return TERM_COLOR_GREEN;
227+
if (c == LAVA) return TERM_COLOR_RED;
228+
if (c == LIGHTBLUE) return TERM_COLOR_BLUE;
229+
if (c == LIGHTGREEN) return TERM_COLOR_GREEN;
230+
if (c == LIMEGREEN) return TERM_COLOR_GREEN;
231+
if (c == LIME) return TERM_COLOR_GREEN;
232+
if (c == MAGENTA) return TERM_COLOR_PINK;
233+
if (c == ORANGE) return TERM_COLOR_RED;
234+
if (c == PEACHPUFF) return TERM_COLOR_RED;
235+
if (c == PINK) return TERM_COLOR_RED;
236+
if (c == PURPLE) return TERM_COLOR_PINK;
237+
if (c == RED) return TERM_COLOR_RED;
238+
if (c == SILVER) return TERM_COLOR_WHITE;
239+
if (c == STEELBLUE) return TERM_COLOR_WHITE;
240+
if (c == WATER) return TERM_COLOR_CYAN;
241+
if (c == WHITE) return TERM_COLOR_WHITE;
242+
if (c == YELLOW) return TERM_COLOR_YELLOW;
243+
if (c == PURPLE) return TERM_COLOR_BLUE;
244+
return TERM_COLOR_BLUE;
245+
}

src/dungeon.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,27 @@
33
//
44

55
#include "my_array_bounds_check.hpp"
6+
#include "my_ascii.hpp"
67
#include "my_dmap.hpp"
78
#include "my_dungeon.hpp"
9+
#include "my_game.hpp"
810
#include "my_level.hpp"
911
#include "my_level_static.hpp"
12+
#include "my_player.hpp"
1013
#include "my_room.hpp"
14+
#include "my_sdl_proto.hpp"
1115
#include "my_template.hpp"
16+
#include "my_thing.hpp"
1217
#include "my_vector_bounds_check.hpp"
18+
#include "my_wid.hpp"
19+
#include "my_wid_actionbar.hpp"
20+
#include "my_wid_asciimap.hpp"
21+
#include "my_wid_botcon.hpp"
22+
#include "my_wid_console.hpp"
23+
#include "my_wid_leftbar.hpp"
24+
#include "my_wid_rightbar.hpp"
25+
#include "my_wid_thing_info.hpp"
26+
#include "my_wid_topcon.hpp"
1327

1428
//
1529
// The algorithm
@@ -4611,16 +4625,40 @@ void dungeon_test(void)
46114625
point3d world_at;
46124626
point grid_at;
46134627

4628+
g_opt_ascii = true;
4629+
sdl_display_reset();
4630+
46144631
//
46154632
// Create the new level
46164633
//
4634+
game->init();
4635+
46174636
auto new_level = new Level(biome);
46184637
auto difficulty_depth = 0;
46194638
auto dungeon_walk_order_level_no = 0;
46204639

46214640
new_level->create(world_at, grid_at, dungeon_seed, difficulty_depth, dungeon_walk_order_level_no);
4622-
new_level->tick();
4641+
game->level = new_level;
4642+
4643+
pcg_random_allowed++;
4644+
game->place_player();
4645+
game->robot_mode_requested = true;
4646+
game->start();
4647+
game->tick_begin_now();
4648+
game->tick_end();
4649+
game->tick_begin_now();
4650+
pcg_random_allowed--;
4651+
4652+
while (game->tick_current < 100) {
4653+
SDL_Delay(5);
4654+
game->level->tick();
4655+
wid_gc_all();
4656+
wid_display_all();
4657+
ascii_dump();
4658+
}
46234659
delete new_level;
46244660

4661+
game->fini();
4662+
46254663
if (! dungeon_seed--) { DIE("end of test"); }
46264664
}

0 commit comments

Comments
 (0)