Skip to content

Commit

Permalink
bug: the robot should only learn random skills and spells that are av…
Browse files Browse the repository at this point in the history
…ailable
  • Loading branch information
goblinhack committed Aug 7, 2023
1 parent e017723 commit 1299fe4
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/my_game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ class Skill
Skillp skill_right = {};
};

bool skill_has_precursor(Skillp);
bool skill_is_available(Skillp);

class Spell
{
public:
Expand All @@ -213,6 +216,9 @@ class Spell
Spellp spell_right = {};
};

bool spell_has_precursor(Spellp);
bool spell_is_available(Spellp);

class Game
{
public:
Expand Down
5 changes: 4 additions & 1 deletion src/thing_obstacle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ bool Thing::is_obs_ai(Thingp it)
}

//
// Dead/extinguished braziers
// Dead/extinguished braziers cause no collision
//
if (it->is_dead) {
if (debug && is_debug_type()) {
Expand All @@ -422,6 +422,9 @@ bool Thing::is_obs_ai(Thingp it)
return false;
}

//
// Check for open doors.
//
if (! it->is_open) {
if (it->is_door()) {
if (is_able_to_open_doors()) {
Expand Down
61 changes: 49 additions & 12 deletions src/thing_skill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright Neil McGill, goblinhack@gmail.com
//

#include "my_array_bounds_check.hpp"
#include "my_game.hpp"
#include "my_monst.hpp"
#include "my_sound.hpp"
Expand Down Expand Up @@ -317,26 +318,62 @@ bool Thing::can_learn_a_skill(void)
return false;
}

//
// Learn a random skill out of the available ones
//
bool Thing::learn_random_skill(void)
{
TRACE_NO_INDENT();

std::vector< Tpp > cands;
for (auto tpp : tp_get_skills()) {
bool add = true;
FOR_ALL_SKILLS(oid)
{
auto o = game->level->thing_find(oid);
if (o) {
if (o->tp() == tpp) {
add = false;
break;

for (auto iter : game->skill_tree) {
auto tree_name = iter.first;
for (auto y = 0; y < SKILL_TREE_DOWN; y++) {
for (auto x = 0; x < SKILL_TREE_ACROSS; x++) {
TRACE_NO_INDENT();

auto new_skill = get(game->skill_tree[ tree_name ], x, y);
if (! new_skill) {
continue;
}

if (! skill_has_precursor(new_skill) || skill_is_available(new_skill)) {
//
// Available
//
} else {
//
// Not available
//
continue;
}

//
// Check this skill is not already known
//
bool skill_cand = true;
FOR_ALL_SKILLS(oid)
{
auto current_skill = game->level->thing_find(oid);
if (! current_skill) {
continue;
}

if (current_skill->tp() == new_skill->tpp) {
//
// Already known
//
skill_cand = false;
break;
}
}

if (skill_cand) {
cands.push_back(new_skill->tpp);
}
}
}
if (add) {
cands.push_back(tpp);
}
}

if (cands.empty()) {
Expand Down
61 changes: 49 additions & 12 deletions src/thing_spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright Neil McGill, goblinhack@gmail.com
//

#include "my_array_bounds_check.hpp"
#include "my_game.hpp"
#include "my_monst.hpp"
#include "my_sound.hpp"
Expand Down Expand Up @@ -347,26 +348,62 @@ bool Thing::can_learn_a_spell(void)
return false;
}

//
// Learn a random spell out of the available ones
//
bool Thing::learn_random_spell(void)
{
TRACE_NO_INDENT();

std::vector< Tpp > cands;
for (auto tpp : tp_get_spells()) {
bool add = true;
FOR_ALL_SPELLS(oid)
{
auto o = game->level->thing_find(oid);
if (o) {
if (o->tp() == tpp) {
add = false;
break;

for (auto iter : game->spell_tree) {
auto tree_name = iter.first;
for (auto y = 0; y < SPELL_TREE_DOWN; y++) {
for (auto x = 0; x < SPELL_TREE_ACROSS; x++) {
TRACE_NO_INDENT();

auto new_spell = get(game->spell_tree[ tree_name ], x, y);
if (! new_spell) {
continue;
}

if (! spell_has_precursor(new_spell) || spell_is_available(new_spell)) {
//
// Available
//
} else {
//
// Not available
//
continue;
}

//
// Check this spell is not already known
//
bool spell_cand = true;
FOR_ALL_SPELLS(oid)
{
auto current_spell = game->level->thing_find(oid);
if (! current_spell) {
continue;
}

if (current_spell->tp() == new_spell->tpp) {
//
// Already known
//
spell_cand = false;
break;
}
}

if (spell_cand) {
cands.push_back(new_spell->tpp);
}
}
}
if (add) {
cands.push_back(tpp);
}
}

if (cands.empty()) {
Expand Down
10 changes: 5 additions & 5 deletions src/wid_skill_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static uint8_t wid_skill_close(Widp w, int x, int y, uint32_t button)
return true;
}

void wid_skill_over_begin(Widp w, int relx, int rely, int wheelx, int wheely)
static void wid_skill_over_begin(Widp w, int relx, int rely, int wheelx, int wheely)
{
TRACE_NO_INDENT();
DBG2("Skill: Begin over skill");
Expand All @@ -193,7 +193,7 @@ void wid_skill_over_begin(Widp w, int relx, int rely, int wheelx, int wheely)
game->wid_tp_info_create(skill->tpp);
}

void wid_skill_tree_over_begin(Widp w, int relx, int rely, int wheelx, int wheely)
static void wid_skill_tree_over_begin(Widp w, int relx, int rely, int wheelx, int wheely)
{
auto new_skill_tree = wid_get_string_context(w);

Expand All @@ -206,7 +206,7 @@ void wid_skill_tree_over_begin(Widp w, int relx, int rely, int wheelx, int wheel
game->wid_choose_skill();
}

void wid_skill_over_end(Widp w)
static void wid_skill_over_end(Widp w)
{
TRACE_NO_INDENT();
DBG2("Skill: End over skill");
Expand All @@ -222,7 +222,7 @@ void wid_skill_over_end(Widp w)
//
// Is this skill learned only after another?
//
static bool skill_has_precursor(Skillp skill_curr)
bool skill_has_precursor(Skillp skill_curr)
{
for (auto iter : game->skill_tree) {
auto tree_name = iter.first;
Expand Down Expand Up @@ -254,7 +254,7 @@ static bool skill_has_precursor(Skillp skill_curr)
//
// Have we unlocked a skill?
//
static bool skill_is_available(Skillp skill_next)
bool skill_is_available(Skillp skill_next)
{
for (auto iter : game->skill_tree) {
auto tree_name = iter.first;
Expand Down
4 changes: 2 additions & 2 deletions src/wid_spell_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void wid_spell_over_end(Widp w)
//
// Is this spell learned only after another?
//
static bool spell_has_precursor(Spellp spell_curr)
bool spell_has_precursor(Spellp spell_curr)
{
for (auto iter : game->spell_tree) {
auto tree_name = iter.first;
Expand Down Expand Up @@ -254,7 +254,7 @@ static bool spell_has_precursor(Spellp spell_curr)
//
// Have we unlocked a spell?
//
static bool spell_is_available(Spellp spell_next)
bool spell_is_available(Spellp spell_next)
{
for (auto iter : game->spell_tree) {
auto tree_name = iter.first;
Expand Down

0 comments on commit 1299fe4

Please sign in to comment.