Skip to content

Commit

Permalink
bug: do not use up spell points when cancelling spell
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jul 15, 2023
1 parent 5245738 commit 31c4de3
Show file tree
Hide file tree
Showing 14 changed files with 799 additions and 654 deletions.
Binary file modified data/gfx.tgz
Binary file not shown.
18 changes: 9 additions & 9 deletions python/gfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,22 +419,22 @@ def init_tiles_16x16_main():
"skill_super_health",
############################################################
"",
"spell_magic_missile_activated",
"spell_magic_missile",
"spell_summon_monst_A_activated",
"spell_magic_missile_activated",
"spell_summon_monst_A",
"spell_summon_monst_B_activated",
"spell_summon_monst_A_activated",
"spell_summon_monst_B",
"spell_summon_monst_C_activated",
"spell_summon_monst_B_activated",
"spell_summon_monst_C",
"spell_summon_monst_D_activated",
"spell_summon_monst_C_activated",
"spell_summon_monst_D",
"spell_summon_monst_E_activated",
"spell_summon_monst_D_activated",
"spell_summon_monst_E",
"spell_summon_food_activated",
"spell_summon_monst_E_activated",
"spell_summon_food",
"",
"",
"spell_summon_food_activated",
"spell_summon_rock",
"spell_summon_rock_activated",
"",
"",
############################################################
Expand Down
5 changes: 3 additions & 2 deletions python/spell_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
my.map_load_spell_tree(
spell_data=[
"fd", "spell_summon_food",
"rk", "spell_summon_rock",
"mm", "spell_magic_missile",
"sA", "spell_summon_monst_A",
"sB", "spell_summon_monst_B",
Expand Down Expand Up @@ -42,9 +43,9 @@
tree_data=[
"fd ",
" ",
"sA->sB->sC->sD->sE ",
" ",
"rk ",
" ",
"sA->sB->sC->sD->sE ",
" ",
" ",
" ",
Expand Down
39 changes: 39 additions & 0 deletions python/things/spells/spell_summon_rock.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import my
import tp


def on_targeted(me, x, y):
my.place_at(me, "random_rock", x, y)


def tp_init(name, text_long_name, text_short_name):
global self
self = tp.Tp(name, text_long_name, text_short_name)
# begin sort marker
my.gfx_targeted_projectile(self, "projectile_magical_effect")
my.is_loggable(self, True)
my.is_spell(self, True)
my.is_target_select(self, True)
my.is_usable(self, True)
my.on_targeted_do(self, "me.on_targeted()")
my.range_max(self, 7)
my.spell_base_name(self, name)
my.spell_cost(self, 3)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Summon a slab of solid rock that you can use as a means of defense of treat as a new pet and something to talk to.")
my.text_description_short(self, "Spell, summon rock")
my.text_description_very_short(self, "SumRock")
my.z_depth(self, my.MAP_DEPTH_OBJ)
my.z_prio(self, my.MAP_Z_PRIO_BEHIND)
# end sort marker

my.tile(self, tile="spell_summon_rock")
my.tile(self, tile="spell_summon_rock_activated")
my.tp_update(self)


def init():
tp_init(name="spell_summon_rock", text_long_name="summon rock", text_short_name="summon rock")


init()
10 changes: 3 additions & 7 deletions src/game_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Game::place_player(void)
auto w = level->thing_new("sword_plutonium", point(x, y));
t->carry(w, carry_options);
}
if (1) {
if (0) {
auto w = level->thing_new("staff_descent", point(x, y));
t->carry(w, carry_options);
}
Expand Down Expand Up @@ -267,10 +267,6 @@ void Game::place_player(void)
auto w = level->thing_new("axe", point(x, y));
t->carry(w, carry_options);
}
if (0) {
auto w = level->thing_new("staff_energy", point(x, y));
t->carry(w, carry_options);
}
if (1) {
auto w = level->thing_new("torch", point(x, y));
t->carry(w, carry_options);
Expand Down Expand Up @@ -322,9 +318,9 @@ void Game::place_player(void)
}
}
}
if (1) {
if (0) {
{
for (auto sk = 0; sk < 1; sk++) {
for (auto sk = 0; sk < 2; sk++) {
auto b = level->thing_new("spellbook", point(x, y));
t->carry(b, carry_options);
}
Expand Down
49 changes: 49 additions & 0 deletions src/my_wid_actionbar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,52 @@ void wid_actionbar_robot_mode_toggle(void);
void wid_actionbar_robot_mode_off(void);
void wid_actionbar_close_all_popups(void);
void wid_actionbar_robot_mode_update(void);

extern Widp wid_actionbar;

uint8_t wid_actionbar_ascend(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_close(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_collect(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_configure(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_descend(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_inventory(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_load(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_quit(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_repeat_wait(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_robot(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_save(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_wait(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_zoom_in(Widp w, int x, int y, uint32_t button);
uint8_t wid_actionbar_zoom_out(Widp w, int x, int y, uint32_t button);
void wid_actionbar_ai_tick(Widp w);
void wid_actionbar_ascend_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_ascend_over_end(Widp w);
void wid_actionbar_close_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_close_over_end(Widp w);
void wid_actionbar_collect_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_collect_over_end(Widp w);
void wid_actionbar_configure_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_configure_over_end(Widp w);
void wid_actionbar_descend_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_descend_over_end(Widp w);
void wid_actionbar_inventory_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_inventory_over_end(Widp w);
void wid_actionbar_load_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_load_over_end(Widp w);
void wid_actionbar_quit_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_quit_over_end(Widp w);
void wid_actionbar_robot_mode_off(void);
void wid_actionbar_robot_mode_toggle(void);
void wid_actionbar_robot_mode_update(void);
void wid_actionbar_robot_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_robot_over_end(Widp w);
void wid_actionbar_save_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_save_over_end(Widp w);
void wid_actionbar_wait_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_wait_over_end(Widp w);
void wid_actionbar_zoom_in_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_zoom_in_over_end(Widp w);
void wid_actionbar_zoom_out_over_begin(Widp w, int relx, int rely, int wheelx, int wheely);
void wid_actionbar_zoom_out_over_end(Widp w);
void wid_actionbar_ascii_init(void);
void wid_actionbar_pixelart_init(void);
15 changes: 15 additions & 0 deletions src/thing_charges.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,48 @@ int Thing::charge_count_set(int v)
{
TRACE_NO_INDENT();
new_infop();
if (is_player()) {
game->set_request_to_remake_rightbar();
}
return (infop()->charge_count = v);
}

int Thing::charge_count_decr(int v)
{
TRACE_NO_INDENT();
new_infop();
if (is_player()) {
game->set_request_to_remake_rightbar();
}
return (infop()->charge_count -= v);
}

int Thing::charge_count_incr(int v)
{
TRACE_NO_INDENT();
new_infop();
if (is_player()) {
game->set_request_to_remake_rightbar();
}
return (infop()->charge_count += v);
}

int Thing::charge_count_decr(void)
{
TRACE_NO_INDENT();
new_infop();
if (is_player()) {
game->set_request_to_remake_rightbar();
}
return (infop()->charge_count--);
}

int Thing::charge_count_incr(void)
{
TRACE_NO_INDENT();
new_infop();
if (is_player()) {
game->set_request_to_remake_rightbar();
}
return (infop()->charge_count++);
}
8 changes: 4 additions & 4 deletions src/thing_spell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,14 +180,14 @@ bool Thing::spell_use(Thingp what)
return false;
}

magic_decr(what->spell_cost());
msg("You cast %s.", what->text_the().c_str());
used(what, this, false /* remove after use */);

if (what->is_target_select()) {
msg("You prepare to cast %s.", what->text_the().c_str());
return item_choose_target(what);
}

msg("You cast %s.", what->text_the().c_str());
used(what, this, false /* remove after use */);

return true;
}

Expand Down
1 change: 1 addition & 0 deletions src/thing_template_ids.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ std::initializer_list< std::string > tps = {
"spellbook",
"spell_magic_missile",
"spell_summon_food",
"spell_summon_rock",
"spell_summon_monst_A",
"spell_summon_monst_B",
"spell_summon_monst_C",
Expand Down
27 changes: 15 additions & 12 deletions src/thing_use.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void Thing::used(Thingp what, Thingp target, bool remove_after_use, UseOptions *
on_use(what, target);
} else {
on_use(what);
game->change_state(Game::STATE_NORMAL, "choosing a target");
game->change_state(Game::STATE_NORMAL, "choose a target");
}

//
Expand Down Expand Up @@ -279,16 +279,6 @@ void Thing::used(Thingp what, Thingp target, bool remove_after_use, UseOptions *
}
}

if (what->is_skill()) {
dbg("Used skill %s", what->to_short_string().c_str());
return;
}

if (what->is_spell()) {
dbg("Used spell %s", what->to_short_string().c_str());
return;
}

auto existing_owner = what->top_owner();
if (existing_owner != this) {
if (is_dead) {
Expand Down Expand Up @@ -317,18 +307,31 @@ void Thing::used(Thingp what, Thingp target, bool remove_after_use, UseOptions *
what->charge_count_decr();
if (what->charge_count()) {
dbg("Used %s (has %d charges left)", what->to_short_string().c_str(), what->charge_count());
game->set_request_to_remake_rightbar();
return;
}
}

if (what->is_spell()) {
magic_decr(what->spell_cost());
}

if (target) {
on_final_use(what, target);
} else {
on_final_use(what);
}
}

if (what->is_skill()) {
dbg("Used skill %s", what->to_short_string().c_str());
return;
}

if (what->is_spell()) {
dbg("Used spell %s", what->to_short_string().c_str());
return;
}

dbg("Used %s", what->to_short_string().c_str());

//
Expand Down

0 comments on commit 31c4de3

Please sign in to comment.