Skip to content

Commit

Permalink
bug: fix level crash on start
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jul 17, 2023
1 parent d195022 commit a8a60d0
Show file tree
Hide file tree
Showing 12 changed files with 71 additions and 36 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ Content:
<!-- begin type marker -->
- 108 x monsters
- 52 x food
- 20 x treasure
- 24 x treasure
- 14 x weapons
- 14 x spells
- 13 x items
Expand Down
4 changes: 2 additions & 2 deletions python/things/treasure/spellbook1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def tp_init(name, text_long_name, text_short_name):
self = tp.Tp(name, text_long_name, text_short_name)
# begin sort marker
my.charge_count(self, 1)
my.collision_hit_priority(self, 5)
my.environ_dislikes_fire(self, 10)
my.gfx_ascii_shown(self, True)
Expand All @@ -14,7 +15,6 @@ def tp_init(name, text_long_name, text_short_name):
my.gfx_pixelart_show_highlighted(self, True)
my.gfx_pixelart_show_outlined(self, True)
my.gfx_pixelart_submergible(self, True)
my.charge_count(self, 1)
my.gold_value_dice(self, "500")
my.is_able_to_be_teleported(self, True)
my.is_able_to_fall(self, True)
Expand All @@ -40,8 +40,8 @@ def tp_init(name, text_long_name, text_short_name):
my.item_height(self, 4)
my.item_width(self, 4)
my.noise_on_dropping(self, 50)
my.rarity(self, my.RARITY_COMMON)
my.normal_placement_rules(self, True)
my.rarity(self, my.RARITY_COMMON)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_short(self, "A dusty spellbook.")
Expand Down
6 changes: 3 additions & 3 deletions python/things/treasure/spellbook2.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def tp_init(name, text_long_name, text_short_name):
self = tp.Tp(name, text_long_name, text_short_name)
# begin sort marker
my.charge_count(self, 2)
my.collision_hit_priority(self, 5)
my.environ_dislikes_fire(self, 10)
my.gfx_ascii_shown(self, True)
Expand All @@ -14,7 +15,6 @@ def tp_init(name, text_long_name, text_short_name):
my.gfx_pixelart_show_highlighted(self, True)
my.gfx_pixelart_show_outlined(self, True)
my.gfx_pixelart_submergible(self, True)
my.charge_count(self, 2)
my.gold_value_dice(self, "1000")
my.is_able_to_be_teleported(self, True)
my.is_able_to_fall(self, True)
Expand All @@ -35,15 +35,15 @@ def tp_init(name, text_long_name, text_short_name):
my.is_throwable(self, True)
my.is_treasure_class_B(self, True)
my.is_treasure(self, True)
my.rarity(self, my.RARITY_UNCOMMON)
my.is_usable(self, True)
my.item_height(self, 4)
my.item_width(self, 4)
my.noise_on_dropping(self, 50)
my.normal_placement_rules(self, True)
my.rarity(self, my.RARITY_UNCOMMON)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_long2(self, "This rare book is bursting with knowledge. Well, two spells. Use them well.")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_short(self, "A dusty spellbook.")
my.tick_prio(self, my.MAP_TICK_PRIO_NORMAL)
my.z_depth(self, my.MAP_DEPTH_OBJ)
Expand Down
8 changes: 4 additions & 4 deletions python/things/treasure/spellbook3.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def tp_init(name, text_long_name, text_short_name):
self = tp.Tp(name, text_long_name, text_short_name)
# begin sort marker
my.charge_count(self, 3)
my.collision_hit_priority(self, 5)
my.environ_dislikes_fire(self, 10)
my.gfx_ascii_shown(self, True)
Expand All @@ -14,7 +15,6 @@ def tp_init(name, text_long_name, text_short_name):
my.gfx_pixelart_show_highlighted(self, True)
my.gfx_pixelart_show_outlined(self, True)
my.gfx_pixelart_submergible(self, True)
my.charge_count(self, 3)
my.gold_value_dice(self, "1500")
my.is_able_to_be_teleported(self, True)
my.is_able_to_fall(self, True)
Expand All @@ -35,17 +35,17 @@ def tp_init(name, text_long_name, text_short_name):
my.is_throwable(self, True)
my.is_treasure_class_C(self, True)
my.is_treasure(self, True)
my.rarity(self, my.RARITY_RARE)
my.stat_luck_bonus(self, -2)
my.is_treasure_type(self, True)
my.is_usable(self, True)
my.item_height(self, 4)
my.item_width(self, 4)
my.noise_on_dropping(self, 50)
my.normal_placement_rules(self, True)
my.rarity(self, my.RARITY_RARE)
my.stat_luck_bonus(self, -2)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_long2(self, "This book is beautifully crafted with gold. The only worrying thing is that the bookmark inside appears to be a tongue...")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_short(self, "A dark and dusty spellbook.")
my.tick_prio(self, my.MAP_TICK_PRIO_NORMAL)
my.z_depth(self, my.MAP_DEPTH_OBJ)
Expand Down
8 changes: 4 additions & 4 deletions python/things/treasure/spellbook4.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def tp_init(name, text_long_name, text_short_name):
self = tp.Tp(name, text_long_name, text_short_name)
# begin sort marker
my.charge_count(self, 4)
my.collision_hit_priority(self, 5)
my.environ_dislikes_fire(self, 10)
my.gfx_ascii_shown(self, True)
Expand All @@ -14,7 +15,6 @@ def tp_init(name, text_long_name, text_short_name):
my.gfx_pixelart_show_highlighted(self, True)
my.gfx_pixelart_show_outlined(self, True)
my.gfx_pixelart_submergible(self, True)
my.charge_count(self, 4)
my.gold_value_dice(self, "2000")
my.is_able_to_be_teleported(self, True)
my.is_able_to_fall(self, True)
Expand All @@ -37,15 +37,15 @@ def tp_init(name, text_long_name, text_short_name):
my.is_treasure(self, True)
my.is_treasure_type(self, True)
my.is_usable(self, True)
my.stat_luck_bonus(self, -4)
my.item_height(self, 5)
my.item_width(self, 5)
my.noise_on_dropping(self, 80)
my.rarity(self, my.RARITY_VERY_RARE)
my.normal_placement_rules(self, True)
my.rarity(self, my.RARITY_VERY_RARE)
my.stat_luck_bonus(self, -4)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_long2(self, "This book is emblazoned with a skull on its cover and the ink inside is a disconcerting red color. This book is very rare. Use its contents wisely.")
my.text_description_long(self, "Read this spellbook to learn some new spells into your brain matter thing.")
my.text_description_short(self, "A skull emblazoned dusty spellbook.")
my.tick_prio(self, my.MAP_TICK_PRIO_NORMAL)
my.z_depth(self, my.MAP_DEPTH_OBJ)
Expand Down
8 changes: 4 additions & 4 deletions python/things/treasure/spellbook5.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
def tp_init(name, text_long_name, text_short_name):
self = tp.Tp(name, text_long_name, text_short_name)
# begin sort marker
my.charge_count(self, 5)
my.collision_hit_priority(self, 5)
my.environ_dislikes_fire(self, 10)
my.gfx_ascii_shown(self, True)
Expand All @@ -14,7 +15,6 @@ def tp_init(name, text_long_name, text_short_name):
my.gfx_pixelart_show_highlighted(self, True)
my.gfx_pixelart_show_outlined(self, True)
my.gfx_pixelart_submergible(self, True)
my.charge_count(self, 5)
my.gold_value_dice(self, "3000")
my.is_able_to_be_teleported(self, True)
my.is_able_to_fall(self, True)
Expand All @@ -35,17 +35,17 @@ def tp_init(name, text_long_name, text_short_name):
my.is_throwable(self, True)
my.is_treasure_class_C(self, True)
my.is_treasure(self, True)
my.rarity(self, my.RARITY_VERY_RARE)
my.is_treasure_type(self, True)
my.is_usable(self, True)
my.item_height(self, 5)
my.item_width(self, 5)
my.stat_luck_bonus(self, -8)
my.noise_on_dropping(self, 90)
my.normal_placement_rules(self, True)
my.rarity(self, my.RARITY_VERY_RARE)
my.stat_luck_bonus(self, -8)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Read this darkest of spellbooks to learn some new spells into your brain matter thing.")
my.text_description_long2(self, "This book is emblazoned with a monstrous demonic face on its cover. It has a dark energy about it. Best to learn the spells inside quickly and get rid of it soon!")
my.text_description_long(self, "Read this darkest of spellbooks to learn some new spells into your brain matter thing.")
my.text_description_short(self, "A dusty spellbook.")
my.tick_prio(self, my.MAP_TICK_PRIO_NORMAL)
my.z_depth(self, my.MAP_DEPTH_OBJ)
Expand Down
10 changes: 10 additions & 0 deletions src/player_dmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
int Thing::distance_to_player(void)
{
TRACE_AND_INDENT();

if (! game->level) {
return DMAP_IS_WALL;
}

auto player = game->level->player;
if (! player) {
return DMAP_IS_WALL;
Expand All @@ -30,6 +35,11 @@ int Thing::distance_to_player(void)
int Thing::distance_to_player_on_different_level(void)
{
TRACE_AND_INDENT();

if (! game->level) {
return DMAP_IS_WALL;
}

auto player = game->level->player;
if (! player) {
return DMAP_IS_WALL;
Expand Down
15 changes: 10 additions & 5 deletions src/thing_enchant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,18 @@ bool Thing::enchant_with_stone(Thingp what)
}

//
// Drop an enchantstone
// Drop a enchantstone
//
auto found = false;
for (const auto t : carried_item_only_vector()) {
if (t->is_enchantstone()) {
t->is_drained = true;
t->dead("drained and used");
for (const auto enchantstone : carried_item_only_vector()) {
if (enchantstone->is_enchantstone()) {
if (enchantstone->charge_count()) {
enchantstone->charge_count_decr();
}
if (! enchantstone->charge_count()) {
enchantstone->is_drained = true;
enchantstone->dead("drained and used");
}
found = true;
break;
}
Expand Down
20 changes: 20 additions & 0 deletions src/thing_popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,26 @@ void Thing::popup(std::string const &m)
return;
}

if (! game->level) {
return;
}

auto player = game->level->player;
if (! player) {
return;
}

//
// Check we're on the same level
//
if (player->level != level) {
return;
}

if (level->is_starting) {
return;
}

//
// Get the top owner as that will be the popup owner. We keep track
// of who created the popup so we can avoid > 1 popup per thing which
Expand Down
13 changes: 9 additions & 4 deletions src/thing_skill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,15 @@ bool Thing::skill_add(Tpp what)
// Drop a skillstone
//
auto found = false;
for (const auto t : carried_item_only_vector()) {
if (t->is_skillstone()) {
t->is_drained = true;
t->dead("drained and used");
for (const auto skillstone : carried_item_only_vector()) {
if (skillstone->is_skillstone()) {
if (skillstone->charge_count()) {
skillstone->charge_count_decr();
}
if (! skillstone->charge_count()) {
skillstone->is_drained = true;
skillstone->dead("drained and used");
}
found = true;
break;
}
Expand Down
8 changes: 4 additions & 4 deletions src/thing_spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ bool Thing::spell_add(Tpp what)
if (spellbook->is_spellbook()) {
if (spellbook->charge_count()) {
spellbook->charge_count_decr();
if (! spellbook->charge_count()) {
spellbook->is_drained = true;
spellbook->dead("drained and used");
}
}
if (! spellbook->charge_count()) {
spellbook->is_drained = true;
spellbook->dead("drained and used");
}
found = true;
break;
Expand Down
5 changes: 0 additions & 5 deletions src/wid_skill_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,29 +399,24 @@ void Game::wid_choose_from_skill_tree(std::string current_tree_name)
br.y = tl.y + (WID_SKILL_BUTTON_HEIGHT - 1) - 1;
wid_set_pos(b, tl, br);

bool skill_is_active_or_available = false;

//
// Do we have this skill?
//
if (player->has_skill(skill->tpp)) {
//
// Yes
//
skill_is_active_or_available = true;
wid_set_style(b, UI_WID_STYLE_DARK);
} else if (! skill_has_precursor(skill)) {
//
// Can we attain this skill?
//
skill_is_active_or_available = true;
wid_set_style(b, UI_WID_STYLE_GREEN);
wid_set_on_mouse_up(b, wid_skills_mouse_up);
} else if (skill_is_available(skill)) {
//
// Can we attain this skill?
//
skill_is_active_or_available = true;
wid_set_style(b, UI_WID_STYLE_GREEN);
wid_set_on_mouse_up(b, wid_skills_mouse_up);
} else {
Expand Down

0 comments on commit a8a60d0

Please sign in to comment.