Skip to content

Commit

Permalink
feat: spell of monst summoning
Browse files Browse the repository at this point in the history
  • Loading branch information
goblinhack committed Jul 11, 2023
1 parent eb427f2 commit dcbe9aa
Show file tree
Hide file tree
Showing 28 changed files with 247 additions and 15 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ Content:
- 3 x doors
- 3 x cloaks
- 2 x traps
- 2 x spells
- 2 x potions
- 1 x player
<!-- end type marker -->
Expand Down
3 changes: 1 addition & 2 deletions python/things/spells/spell_summon_monst_A.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


def on_targeted(me, x, y):
my.topcon("targetted me {} {},{}".format(my.thing_name_get(me), x, y))
my.place_at(me, "random_monst_class_A", x, y)


Expand All @@ -21,7 +20,7 @@ def tp_init(name, text_long_name, text_short_name):
my.spell_base_name(self, name)
my.spell_cost(self, 2)
my.text_a_or_an(self, "a")
my.text_description_long(self, "Summon an unfriendly monster of the least dangerous type")
my.text_description_long(self, "Summon an unfriendly monster of the least dangerous type, class A if you want to get technical.")
my.text_description_short(self, "Spell, summon monst A.")
my.text_description_very_short(self, "SumMonstA")
my.z_depth(self, my.MAP_DEPTH_OBJ)
Expand Down
1 change: 1 addition & 0 deletions src/game_load.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ std::istream &operator>>(std::istream &in, Bits< ThingInfop & > my)
in >> bits(my.t->tick_last_awoke);
in >> bits(my.t->tick_last_did_something);
in >> bits(my.t->tick_last_seen_by_player);
in >> bits(my.t->tick_born);
in >> bits(my.t->tick_last_dropped);
in >> bits(my.t->tick_last_teleported);
in >> bits(my.t->tick_last_escape);
Expand Down
1 change: 1 addition & 0 deletions src/game_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ std::ostream &operator<<(std::ostream &out, Bits< ThingInfop & > const my)
out << bits(my.t->tick_last_awoke);
out << bits(my.t->tick_last_did_something);
out << bits(my.t->tick_last_seen_by_player);
out << bits(my.t->tick_born);
out << bits(my.t->tick_last_dropped);
out << bits(my.t->tick_last_teleported);
out << bits(my.t->tick_last_escape);
Expand Down
36 changes: 36 additions & 0 deletions src/level_monst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,44 @@ Tpp Level::get_random_monst(point p, monst_environ_t monst_environ, monst_class_
}
}

Tpp Level::get_random_monst(point p, monst_class_t monst_class, int difficulty_offset)
{
TRACE_NO_INDENT();

auto monst_environ = MONST_ENVIRON_NORMAL;
if (is_deep_water(p)) {
monst_environ = MONST_ENVIRON_DEEP_WATER;
} else if (is_water(p)) {
monst_environ = MONST_ENVIRON_SHALLOW_WATER;
}

return get_random_monst(p, monst_environ, monst_class);
}

Tpp Level::get_random_monst(point p, monst_environ_t monst_environ, int difficulty_offset)
{
TRACE_NO_INDENT();

for (int monst_class = MONST_CLASS_A; monst_class < MONST_CLASS_MAX; monst_class++) {
auto roll = d1000();
if (roll < d1000_chance_creating_monst[ monst_environ ][ monst_class ]) {
return get_random_monst(p, monst_environ, (monst_class_t) monst_class, difficulty_offset);
}
}
return get_random_monst(p, monst_environ, (monst_class_t) (MONST_CLASS_MAX - 1), difficulty_offset);
}

Tpp Level::get_random_monst(point p, int difficulty_offset)
{
TRACE_NO_INDENT();

auto monst_environ = MONST_ENVIRON_NORMAL;
if (is_deep_water(p)) {
monst_environ = MONST_ENVIRON_DEEP_WATER;
} else if (is_water(p)) {
monst_environ = MONST_ENVIRON_SHALLOW_WATER;
}

for (int monst_class = MONST_CLASS_A; monst_class < MONST_CLASS_MAX; monst_class++) {
auto roll = d1000();
if (roll < d1000_chance_creating_monst[ monst_environ ][ monst_class ]) {
Expand Down
12 changes: 6 additions & 6 deletions src/level_wandering_monst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ bool Level::create_wandering_monster(void)
}

if (biome == BIOME_DUNGEON) {
if (is_corridor(x, y) || is_bridge(x, y) || is_water(x, y) || is_hazard(x, y)) {
if (is_corridor(x, y) || is_bridge(x, y) || is_hazard(x, y)) {
continue;
}
}
Expand All @@ -64,15 +64,15 @@ bool Level::create_wandering_monster(void)
//
auto roll = d1000() + difficulty_depth * 10;
if (roll < 950) {
tp = get_random_monst(p, MONST_ENVIRON_NORMAL, MONST_CLASS_A);
tp = get_random_monst(p, MONST_CLASS_A);
} else if (roll < 980) {
tp = get_random_monst(p, MONST_ENVIRON_NORMAL, MONST_CLASS_B);
tp = get_random_monst(p, MONST_CLASS_B);
} else if (roll < 990) {
tp = get_random_monst(p, MONST_ENVIRON_NORMAL, MONST_CLASS_C);
tp = get_random_monst(p, MONST_CLASS_C);
} else if (roll < 995) {
tp = get_random_monst(p, MONST_ENVIRON_NORMAL, MONST_CLASS_D);
tp = get_random_monst(p, MONST_CLASS_D);
} else {
tp = get_random_monst(p, MONST_ENVIRON_NORMAL, MONST_CLASS_E);
tp = get_random_monst(p, MONST_CLASS_E);
}

if (tp) {
Expand Down
2 changes: 2 additions & 0 deletions src/my_level.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,8 @@ class Level
Tpp get_biome_ice_random_monst(Dungeonp, point p, monst_environ_t);
Tpp get_random_monst(point p, monst_environ_t, monst_class_t, int difficulty_offset);
Tpp get_random_monst(point p, monst_environ_t, int difficulty_offset);
Tpp get_random_monst(point p, monst_class_t, int difficulty_offset);
Tpp get_random_monst(point p, int difficulty_offset);

// begin sort marker2 {
bool buffbox_over(const int slot);
Expand Down
9 changes: 8 additions & 1 deletion src/my_monst.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ typedef struct ThingInfo_ {
int stat_thv = {};
int stat_thv_bonus = {};
int submerged_offset = {}; // Pixels
int tick_resurrect_when = {};
// end sort marker1 }

int8_t bounce_count = {}; // Graphical bounce count
Expand All @@ -189,6 +188,10 @@ typedef struct ThingInfo_ {
ts_t ts_lunge_end {};
// end sort marker2 }

//
// When this thing came into being or was spawned
//
int tick_born {-1 /* std::numeric_limits< uint32_t >::max() */};
//
// Used for calling on_idle()
//
Expand Down Expand Up @@ -239,6 +242,10 @@ typedef struct ThingInfo_ {
// This is to ensure things do not wake and immediately attack
//
int tick_last_awoke {-1 /* std::numeric_limits< uint32_t >::max() */};
//
// When to resurrect
//
int tick_resurrect_when = {-1 /* std::numeric_limits< uint32_t >::max() */};

//
// List of things I own:
Expand Down
11 changes: 11 additions & 0 deletions src/my_python.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
\
static char *kwlist[] = {#n1, #n2, #n3, 0}; \
\
TRACE_NO_INDENT(); \
if (! PyArg_ParseTupleAndKeywords(args, keywds, "ddi", kwlist, &d1, &d2, &i1)) { \
Py_RETURN_FALSE; \
} \
Expand All @@ -175,6 +176,7 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
Py_RETURN_FALSE; \
} \
\
TRACE_NO_INDENT(); \
(__fn__)(d1, d2, i1); \
\
Py_RETURN_TRUE; \
Expand All @@ -188,6 +190,7 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
\
static char *kwlist[] = {#n1, #n2, 0}; \
\
TRACE_NO_INDENT(); \
if (! PyArg_ParseTupleAndKeywords(args, keywds, "dd", kwlist, &d1, &d2)) { \
Py_RETURN_FALSE; \
} \
Expand All @@ -197,6 +200,7 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
Py_RETURN_FALSE; \
} \
\
TRACE_NO_INDENT(); \
(__fn__)(d1, d2); \
\
Py_RETURN_TRUE; \
Expand All @@ -209,10 +213,12 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
\
static char *kwlist[] = {"wid_id", #n1, 0}; \
\
TRACE_NO_INDENT(); \
if (! PyArg_ParseTupleAndKeywords(args, keywds, "d", kwlist, &d1)) { \
Py_RETURN_FALSE; \
} \
\
TRACE_NO_INDENT(); \
(__fn__)(d1); \
\
Py_RETURN_TRUE; \
Expand All @@ -227,10 +233,12 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
\
static char *kwlist[] = {#n1, #n2, #n3, 0}; \
\
TRACE_NO_INDENT(); \
if (! PyArg_ParseTupleAndKeywords(args, keywds, "iii", kwlist, &n1, &n2, &n3)) { \
Py_RETURN_FALSE; \
} \
\
TRACE_NO_INDENT(); \
(__fn__)(n1, n2, n3); \
\
Py_RETURN_TRUE; \
Expand All @@ -243,10 +251,12 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
\
static char *kwlist[] = {(char *) #n1, 0}; \
\
TRACE_NO_INDENT(); \
if (! PyArg_ParseTupleAndKeywords(args, keywds, "i", kwlist, &n1)) { \
Py_RETURN_FALSE; \
} \
\
TRACE_NO_INDENT(); \
(__fn__)(n1); \
\
Py_RETURN_TRUE; \
Expand All @@ -255,6 +265,7 @@ std::vector< std::string > py_call_std_vector_string_fn(const char *module, cons
#define PY_BODY_VOID_FN(__fn__) \
PyObject *__fn__##_(PyObject *obj, PyObject *args, PyObject *keywds) \
{ \
TRACE_NO_INDENT(); \
(__fn__)(); \
\
Py_RETURN_TRUE; \
Expand Down
7 changes: 7 additions & 0 deletions src/my_thing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2563,6 +2563,13 @@ typedef class Thing_
int tick_last_seen_by_player_set(uint32_t);
int tick_last_seen_by_player(void);

int tick_born_decr(uint32_t);
int tick_born_decr(void);
int tick_born_incr(uint32_t);
int tick_born_incr(void);
int tick_born_set(uint32_t);
int tick_born(void);

int tick_last_dropped_decr(uint32_t);
int tick_last_dropped_decr(void);
int tick_last_dropped_incr(uint32_t);
Expand Down
1 change: 1 addition & 0 deletions src/my_thing_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3171,6 +3171,7 @@ class Tp *string2tp(const std::string &s, int *len);
class Tp *string2tp(const std::wstring &s, int *len);
class Tp *tp_find(const std::string &name);
class Tp *tp_find_wildcard(const std::string &name);
class Tp *tp_find_wildcard(Levelp, point p, const std::string &name);
class Tp *tp_find(uint32_t id);
class Tp *tp_load(int id, const std::string &file, const std::string &long_name, const std::string &sh_name);
class Tp *tp_random_ascend_dungeon(void);
Expand Down
3 changes: 2 additions & 1 deletion src/py_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "my_globals_extra.hpp"
#include "my_log.hpp"
#include "my_main.hpp"
#include "my_python.hpp"
#include "my_string.hpp"
#include "my_sys.hpp"
Expand All @@ -21,7 +22,7 @@ static void py_log_(const char *fmt, va_list args)
len = (int) strlen(buf);
vsnprintf(buf + len, MAXLONGSTR - len, fmt, args);

putf(MY_STDOUT, buf);
DBG("%s", buf);
}

void PY_LOG(const char *fmt, ...)
Expand Down
2 changes: 2 additions & 0 deletions src/py_music.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ PyObject *music_load_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "rate", (char *) "file", (char *) "name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "Iss", kwlist, &rate, &file, &name)) {
ERR("music_load: Bad arguments");
Py_RETURN_FALSE;
Expand Down Expand Up @@ -50,6 +51,7 @@ PyObject *music_play_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "s", kwlist, &name)) {
ERR("music_play: Bad arguments");
Py_RETURN_FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/py_room.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ PyObject *map_load_room_(PyObject *obj, PyObject *args, PyObject *keywds)
(char *) "depth",
nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "|Oiisiiiiiiiiiiiiiiii", kwlist, &py_room_data, &xxx, &yyy,
&room_name, &up, &down, &left, &right, &is_ascend_dungeon, &is_descend_dungeon,
&is_lock, &is_key, &is_secret, &biome_dungeon, &biome_swamp, &biome_ice,
Expand Down
1 change: 1 addition & 0 deletions src/py_skill_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PyObject *map_load_skill_tree_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "skill_data", (char *) "tree_data", (char *) "tree_name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "|OOs", kwlist, &py_skill_data, &py_tree_data, &py_tree_name)) {
DIE("map_load_skill_tree: Bad args");
Py_RETURN_FALSE;
Expand Down
3 changes: 3 additions & 0 deletions src/py_sound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ PyObject *sound_load_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "volume", (char *) "file", (char *) "name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "fss", kwlist, &volume, &file, &name)) {
ERR("sound_load: Bad arguments");
Py_RETURN_FALSE;
Expand Down Expand Up @@ -48,6 +49,7 @@ PyObject *sound_play_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "s", kwlist, &name)) {
ERR("sound_play: Bad arguments");
Py_RETURN_FALSE;
Expand Down Expand Up @@ -76,6 +78,7 @@ PyObject *sound_play_channel_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "channel", (char *) "name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "is", kwlist, &channel, &name)) {
ERR("sound_play_channel: Bad arguments");
Py_RETURN_FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/py_spell_tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ PyObject *map_load_spell_tree_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "spell_data", (char *) "tree_data", (char *) "tree_name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "|OOs", kwlist, &py_spell_data, &py_tree_data, &py_tree_name)) {
DIE("map_load_spell_tree: Bad args");
Py_RETURN_FALSE;
Expand Down
1 change: 1 addition & 0 deletions src/py_tex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ PyObject *tex_load_(PyObject *obj, PyObject *args, PyObject *keywds)

static char *kwlist[] = {(char *) "file", (char *) "name", nullptr};

TRACE_NO_INDENT();
if (! PyArg_ParseTupleAndKeywords(args, keywds, "ss", kwlist, &file, &name)) {
ERR("tex_load: Bad arguments");
Py_RETURN_FALSE;
Expand Down

0 comments on commit dcbe9aa

Please sign in to comment.