X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fserver%2Fthings.c;h=eaeeb9ee8b9b09d9a5e511e6a082504e2a8b830d;hb=08787351493beb2ad649e94d24eebca0e97192c8;hp=5a866bb2f35a7f6395b4b7d005b8dcece45507da;hpb=28b8b4234e395c3fdc4800e5cfb3dcd70a15cadf;p=plomrogue diff --git a/src/server/things.c b/src/server/things.c index 5a866bb..eaeeb9e 100644 --- a/src/server/things.c +++ b/src/server/things.c @@ -10,12 +10,14 @@ #include /* NULL, size_t */ #include /* uint8_t, uint16_t, int16_t, UINT8_MAX, UINT16_MAX */ #include /* free() */ -#include /* memset(), strcmp(), strdup() */ +#include /* memset(), strcmp(), strdup(), strlen() */ #include "../common/rexit.h" /* exit_err() */ #include "../common/try_malloc.h" /* try_malloc() */ #include "../common/yx_uint8.h" /* yx_uint8 */ #include "cleanup.h" /* set_cleanup_flag() */ #include "hardcoded_strings.h" /* s */ +#include "field_of_view.h" /* build_fov_map() */ +#include "map.h" /* mv_yx_in_dir_legal() */ #include "rrand.h" /* rrand() */ #include "thing_actions.h" /* actor_wait */ #include "world.h" /* world */ @@ -119,6 +121,10 @@ extern struct Thing * add_thing(int16_t id, uint8_t type, uint8_t y, uint8_t x) t->lifepoints = tt->lifepoints; t->pos.y = y; t->pos.x = x; + if (t->lifepoints && world.exists) + { + build_fov_map(t); + } return t; } @@ -262,6 +268,54 @@ extern struct Thing * get_player() +extern void try_thing_proliferation(struct Thing * t) +{ + struct ThingType * tt = get_thing_type(t->type); + if (tt->proliferate) + { + if (1 == tt->proliferate || 1 == (rrand() % tt->proliferate)) + { + struct yx_uint8 candidates[6]; + uint8_t n_candidates = 0; + char dirs[7] = "dxswed"; + struct yx_uint8 start = t->pos; + uint8_t i; + for (i = 0; i < strlen(dirs); i++) + { + if ( mv_yx_in_dir_legal(dirs[i], &start) + && '.' == world.map.cells[start.y*world.map.length+start.x]) + { + uint8_t drop = 0; + if (tt->lifepoints) + { + for (t = world.things; t; t = t->next) + { + if ( t->lifepoints + && start.y == t->pos.y && start.x == t->pos.x) + { + drop = 1; + } + } + } + if (!drop) + { + candidates[n_candidates] = start; + n_candidates++; + } + } + } + if (!n_candidates) + { + return; + } + i = rrand() % n_candidates; + add_thing(-1, tt->id, candidates[i].y, candidates[i].x); + } + } +} + + + extern void add_things(uint8_t type, uint8_t n) { uint8_t i;