Skip to content

Commit

Permalink
bug: always do at least 1 damage even for damaged weapons to avoid ro…
Browse files Browse the repository at this point in the history
…bot loops
  • Loading branch information
goblinhack committed Nov 8, 2023
1 parent b2f9aa3 commit 2297b1a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/dungeon_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,21 +117,27 @@ void dungeon_test(void)

if (player->is_waiting_to_descend_dungeon) {
player->log("Waiting to descend dungeon");
pcg_random_allowed++;
player->descend_dungeon(true, game->level->world_at + point3d(0, 0, 2));
pcg_random_allowed--;
}

if (player->is_waiting_to_descend_sewer) {
player->log("Waiting to descend sewer");
pcg_random_allowed++;
if (! player->descend_sewer()) {
player->err("Failed to descend sewer");
}
pcg_random_allowed--;
}

if (player->is_waiting_to_ascend_sewer) {
player->log("Waiting to ascend sewer");
pcg_random_allowed++;
if (! player->ascend_sewer()) {
player->err("Failed to ascend sewer");
}
pcg_random_allowed--;
}

//
Expand Down
4 changes: 2 additions & 2 deletions src/my_thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2821,6 +2821,8 @@ typedef class Thing_
void add_friend(Thingp attacker);
void add_friend(Tpp attacker);
void add_goal_penalty(Thingp attacker);
void add_random_enchants(void);
void add_random_runic(void);
void ai_choose_can_see_goals(std::multiset< Goal > &goals, int minx, int miny, int maxx, int maxy);
void ai_choose_search_goals(std::multiset< Goal > &goals, int search_type);
void ai_get_next_hop(void);
Expand Down Expand Up @@ -2930,8 +2932,6 @@ typedef class Thing_
void dump_equip(void);
void dump(std::string prefix, std::ostream &out);
void enchant_common(Thingp);
void add_random_enchants(void);
void add_random_runic(void);
void enemies_tick(void);
void entranced_tick(void);
void entranced_update(void);
Expand Down
13 changes: 10 additions & 3 deletions src/thing_weapon_breaking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ int Thing::weapon_dmg_modify(int damage, Thingp victim)

int dmg_in = damage;
damage -= (int) ceil(((((float) damage)) / 100.0) * ((float) weapon_dmgd_pct()));
dbg("Weapon is damaged, hits for %d -> %d", dmg_in, damage);
if (damage < 0) {
damage = 0;

//
// If this is zero then we can get into endless robot loops trying to escape and
// hitting a web and making no progress.
//
if (damage < 1) {
damage = 1;
}

dbg("Weapon is damaged, hits for %d -> %d", dmg_in, damage);

return damage;
}

Expand Down
4 changes: 4 additions & 0 deletions src/wid_choose_next_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,16 @@ uint8_t wid_choose_next_dungeons_enter(Widp w, int x, int y, uint32_t button)

if (ctx->is_ascending) {
LOG("Ascend to %s", next_level->world_at.to_string().c_str());
pcg_random_allowed++;
player->ascend_dungeon(true, next_level->world_at);
pcg_random_allowed--;
}

if (ctx->is_descending) {
LOG("Descend to %s", next_level->world_at.to_string().c_str());
pcg_random_allowed++;
player->descend_dungeon(true, next_level->world_at);
pcg_random_allowed--;
}

wid_choose_next_dungeons_destroy(wid_get_top_parent(w));
Expand Down

0 comments on commit 2297b1a

Please sign in to comment.