diff --git a/doc/lua.adoc b/doc/lua.adoc index d90ff446d..ffd320520 100644 --- a/doc/lua.adoc +++ b/doc/lua.adoc @@ -489,25 +489,25 @@ The hash parameter accepts the following keys: | class | string | monster class, eg "D" | x, y | integers | | coord | table of two integer | -| peaceful | 0 or 1 | -| asleep | 0 or 1 | +| peaceful | boolean | +| asleep | boolean | | name | string | name of the monster -| female | 0 or 1 | -| invisible | 0 or 1 | -| cancelled | 0 or 1 | -| revived | 0 or 1 | -| avenge | 0 or 1 | +| female | boolean | +| invisible | boolean | +| cancelled | boolean | +| revived | boolean | +| avenge | boolean | | fleeing | 0 - 127 | | blinded | 0 - 127 | | paralyzed | 0 - 127 | -| stunned | 0 or 1 | -| confused | 0 or 1 | -| waiting | 0 or 1 | monster will wait until hero gets next to it -| tail | 0 or 1 | generate worm without a tail? -| group | 0 or 1 | generate a group of monsters? -| adjacentok | 0 or 1 | is adjacent location ok, if given one is not suitable? -| ignorewater | 0 or 1 | ignore water when choosing location for the monster -| countbirth | 0 or 1 | do we count this monster as generated +| stunned | boolean | +| confused | boolean | +| waiting | boolean | monster will wait until hero gets next to it +| tail | boolean | generate worm without a tail? +| group | boolean | generate a group of monsters? +| adjacentok | boolean | is adjacent location ok, if given one is not suitable? +| ignorewater | boolean | ignore water when choosing location for the monster +| countbirth | boolean | do we count this monster as generated | appear_as | string | monster can appear as object, monster, or terrain. Add "obj:", "mon:", or "ter:" prefix to the value. | | inventory | function | objects generated in the function are given to the monster |=== diff --git a/include/global.h b/include/global.h index a0501850b..ec6b71167 100644 --- a/include/global.h +++ b/include/global.h @@ -67,6 +67,7 @@ typedef xchar boolean; /* 0 or 1 */ #define TRUE ((boolean) 1) #define FALSE ((boolean) 0) #endif +#define BOOL_RANDOM (-1) enum optchoice { opt_in, opt_out}; diff --git a/src/sp_lev.c b/src/sp_lev.c index d50d83741..33c13e1f8 100755 --- a/src/sp_lev.c +++ b/src/sp_lev.c @@ -2032,22 +2032,13 @@ create_monster(monster* m, struct mkroom* croom) } mtmp->female = m->female; - if (m->peaceful >= 0) { + if (m->peaceful > BOOL_RANDOM) { mtmp->mpeaceful = m->peaceful; /* changed mpeaceful again; have to reset malign */ set_malign(mtmp); } - if (m->asleep >= 0) { -#ifdef UNIXPC - /* optimizer bug strikes again */ - if (m->asleep) - mtmp->msleeping = 1; - else - mtmp->msleeping = 0; -#else + if (m->asleep > BOOL_RANDOM) mtmp->msleeping = m->asleep; -#endif - } if (m->seentraps) mtmp->mtrapseen = m->seentraps; if (m->cancelled) @@ -3124,35 +3115,35 @@ lspo_monster(lua_State *L) } else { lcheck_param_table(L); - tmpmons.peaceful = get_table_int_opt(L, "peaceful", -1); /* TODO: alias hostile=!peaceful */ - tmpmons.asleep = get_table_int_opt(L, "asleep", -1); + tmpmons.peaceful = get_table_boolean_opt(L, "peaceful", BOOL_RANDOM); + tmpmons.asleep = get_table_boolean_opt(L, "asleep", BOOL_RANDOM); tmpmons.name.str = get_table_str_opt(L, "name", NULL); tmpmons.appear = 0; tmpmons.appear_as.str = (char *) 0; tmpmons.sp_amask = get_table_align(L); - tmpmons.female = get_table_int_opt(L, "female", 0); - tmpmons.invis = get_table_int_opt(L, "invisible", 0); - tmpmons.cancelled = get_table_int_opt(L, "cancelled", 0); - tmpmons.revived = get_table_int_opt(L, "revived", 0); - tmpmons.avenge = get_table_int_opt(L, "avenge", 0); + tmpmons.female = get_table_boolean_opt(L, "female", FALSE); + tmpmons.invis = get_table_boolean_opt(L, "invisible", FALSE); + tmpmons.cancelled = get_table_boolean_opt(L, "cancelled", FALSE); + tmpmons.revived = get_table_boolean_opt(L, "revived", FALSE); + tmpmons.avenge = get_table_boolean_opt(L, "avenge", FALSE); tmpmons.fleeing = get_table_int_opt(L, "fleeing", 0); tmpmons.blinded = get_table_int_opt(L, "blinded", 0); tmpmons.paralyzed = get_table_int_opt(L, "paralyzed", 0); - tmpmons.stunned = get_table_int_opt(L, "stunned", 0); - tmpmons.confused = get_table_int_opt(L, "confused", 0); - tmpmons.waiting = get_table_int_opt(L, "waiting", 0); + tmpmons.stunned = get_table_boolean_opt(L, "stunned", FALSE); + tmpmons.confused = get_table_boolean_opt(L, "confused", FALSE); + tmpmons.waiting = get_table_boolean_opt(L, "waiting", FALSE); tmpmons.seentraps = 0; /* TODO: list of trap names to bitfield */ tmpmons.has_invent = 0; - if (!get_table_int_opt(L, "tail", 1)) + if (!get_table_boolean_opt(L, "tail", TRUE)) tmpmons.mm_flags |= MM_NOTAIL; - if (!get_table_int_opt(L, "group", 1)) + if (!get_table_boolean_opt(L, "group", TRUE)) tmpmons.mm_flags |= MM_NOGRP; - if (get_table_int_opt(L, "adjacentok", 0)) + if (get_table_boolean_opt(L, "adjacentok", FALSE)) tmpmons.mm_flags |= MM_ADJACENTOK; - if (get_table_int_opt(L, "ignorewater", 0)) + if (get_table_boolean_opt(L, "ignorewater", FALSE)) tmpmons.mm_flags |= MM_IGNOREWATER; - if (!get_table_int_opt(L, "countbirth", 1)) + if (!get_table_boolean_opt(L, "countbirth", TRUE)) tmpmons.mm_flags |= MM_NOCOUNTBIRTH; mappear = get_table_str_opt(L, "appear_as", NULL); diff --git a/test/test_des.lua b/test/test_des.lua index fea216326..d4ad200b9 100644 --- a/test/test_des.lua +++ b/test/test_des.lua @@ -86,12 +86,14 @@ function test_monster() des.monster({ id = "ogre", x = 10, y = 15 }) des.monster({ class = "D", coord = {11,16} }) des.monster({ x = 73, y = 16 }); + des.monster({ id = "watchman", peaceful = true }) des.monster({ id = "watchman", peaceful = 1 }) des.monster({ class = "H", peaceful = 0 }) des.monster({ id = "giant mimic", appear_as = "obj:boulder" }); des.monster({ id = "giant mimic", appear_as = "ter:altar" }); des.monster({ id = "chameleon", appear_as = "mon:bat" }); - des.monster({ class = "H", asleep = 1, female = 1, invisible = 1, cancelled = 1, revived = 1, avenge = 1, fleeing = 20, blinded = 20, paralyzed = 20, stunned = 20, confused = 20 }) + des.monster({ class = "H", asleep = 1, female = 1, invisible = 1, cancelled = 1, revived = 1, avenge = 1, stunned = 1, confused = 1, fleeing = 20, blinded = 20, paralyzed = 20 }) + des.monster({ class = "H", asleep = true, female = true, invisible = true, cancelled = true, revived = true, avenge = true, stunned = true, confused = true }); des.monster({ id = "ogre", x = 10, y = 15, name = "Fred", inventory = function() des.object(); @@ -100,6 +102,11 @@ function test_monster() des.object({ id = "statue", contents=0 }) end }); + des.monster({ id = "long worm", tail = false }); + des.monster({ id = "hill orc", group = false }); + des.monster({ id = "lurker above", adjacentok = true }); + des.monster({ id = "gnome", ignorewater = true }); + des.monster({ id = "xan", countbirth = false }); des.reset_level(); des.level_init(); end