Welcome to the Builder Academy

Question Trapped Items/Disarm Trap

More
28 Jun 2012 06:42 #305 by Papaya Pete
I can't really think of a mud in which I've seen this, but is there a snippit out there for adding traps to doors and containers? Going along with that, of course, would be the disarm/disable trap skill.

Please Log in or Create an account to join the conversation.

More
25 Aug 2017 18:40 - 25 Aug 2017 18:48 #6832 by Papaya Pete
Wow, 5 years? It's been that long since I asked this question? Time flies when you're having fun!

I've been working on this snippet as I've been in the mood to code again recently. It's been years though, and I'm a bit rusty, so I'm having an issue that I can't figure out (but is most likely very simple and I'm missing it).

I'm adding traps to exits and containers by using flags, taking advantage of a door flag system someone else on here (name fails me) set up. It's pretty basic: if you want an exit to have a trap, turn on the TRAPPED flag along with whatever desired trap you have in mind (I'm making a long list of different traps that can be used, with them doing progressively more damage the further down the list you go). You can even have multiple traps, with them blocking your progress through the exit until they are disarmed/fired off. You can also set whether they reset themselves; will those traps keep firing off each time you go through an exit, or just once when you pass through?

Anyways, here's the issue.
Code:
1) DOOR 2) PICKPROOF 3) LOCKED 4) CLOSED 5) HIDDEN 6) CLIMBING 7) JUMPING 8) TRAPPED 9) TRAPBLOCK 10) TRAPRESET 11) WSICKTRAP 12) DARTTRAP 13) PRANKSTER 14) WPOISONTRAP 15) WFLAMETRAP 16) SBLADETRAP 17) MFLAMETRAP 18) ARROWTRAP 19) SPIKETRAP 20) LBLADETRAP 21) SHOCKTRAP 22) MSICKTRAP 23) MPOISONTRAP 24) LSICKTRAP 25) LPOISONTRAP 26) LFLAMETRAP Exit flags: NOBITS Enter Exit flags, 0 to quit :

This is what my exit flag menu looks like. Looks Ok, and I can toggle on and off flags 1-15 just fine. However, when I toggle flag 16...
Code:
1) DOOR 2) PICKPROOF 3) LOCKED 4) CLOSED 5) HIDDEN 6) CLIMBING 7) JUMPING 8) TRAPPED 9) TRAPBLOCK 10) TRAPRESET 11) WSICKTRAP 12) DARTTRAP 13) PRANKSTER 14) WPOISONTRAP 15) WFLAMETRAP 16) SBLADETRAP 17) MFLAMETRAP 18) ARROWTRAP 19) SPIKETRAP 20) LBLADETRAP 21) SHOCKTRAP 22) MSICKTRAP 23) MPOISONTRAP 24) LSICKTRAP 25) LPOISONTRAP 26) LFLAMETRAP Exit flags: SBLADETRAP MFLAMETRAP ARROWTRAP SPIKETRAP LBLADETRAP SHOCKTRAP MSICKTRAP MPOISONTRAP LSICKTRAP LPOISONTRAP LFLAMETRAP UNDEFINED UNDEFINED UNDEFINED UNDEFINED UNDEFINED UNDEFINED Enter Exit flags, 0 to quit :

I get this mess. I've doubled check constants.c and structs.h; I've seen this before and it was goofing up in these spots.
Code:
/** Exit bits for doors. * @pre Must be in the same order as the defines. * Must end array with a single newline. */ const char *exit_bits[] = { "DOOR", "PICKPROOF", "LOCKED", "CLOSED", "HIDDEN", "CLIMBING", "JUMPING", "TRAPPED", "TRAPBLOCK", "TRAPRESET", "WSICKTRAP", "DARTTRAP", "PRANKSTER", "WPOISONTRAP", "WFLAMETRAP", "SBLADETRAP", "MFLAMETRAP", "ARROWTRAP", "SPIKETRAP", "LBLADETRAP", "SHOCKTRAP", "MSICKTRAP", "MPOISONTRAP", "LSICKTRAP", "LPOISONTRAP", "LFLAMETRAP", "\n" };
Code:
/* Exit info: used in room_data.dir_option.exit_info */ #define EX_ISDOOR (1 << 0) /**< Exit is a door */ #define EX_PICKPROOF (1 << 1) /**< The door is closed */ #define EX_LOCKED (1 << 2) /**< The door is locked */ #define EX_CLOSED (1 << 3) /**< Lock can't be picked */ #define EX_HIDDEN (1 << 4) /**< Exit is hidden, secret */ #define EX_CLIMBING (1 << 5) /**< Requires one to climb to pass through */ #define EX_JUMPING (1 << 6) /**< Requires one to jump to pass through */ #define EX_TRAPPED (1 << 7) /**< Exit is trapped, used for checking */ #define EX_TRAPBLOCK (1 << 8) /**< Trap prevents players from passing through */ #define EX_TRAPRESET (1 << 9) /**< Trap automatically resets itself. */ #define EX_WSICKTRAP (1 << 10) /**< Trapped, is a weak sickness trap. */ #define EX_DARTTRAP (1 << 11) /**< Trapped, weak dart trap */ #define EX_PRANKSTER (1 << 12) /**< Trapped, hammer swings down from ceiling. */ #define EX_WPOISONTRAP (1 << 13) /**< Trapped, is a weak poison trap. */ #define EX_WFLAMETRAP (1 << 14) /**< Trapped, weak flame trap */ #define EX_SBLADETRAP (1 << 15) /**< Trapped, a small blade */ #define EX_MFLAMETRAP (1 << 16) /**< is a medium fire trap. */ #define EX_ARROWTRAP (1 << 17) /**< arrows shoot out */ #define EX_SPIKETRAP (1 << 18) /**< spikes eject out of the ground but retract */ #define EX_LBLADETRAP (1 << 19) /**< a large circular blade trap */ #define EX_SHOCKTRAP (1 << 20) /**< shocking trap */ #define EX_MSICKTRAP (1 << 21) /**< Major illness trap */ #define EX_MPOISONTRAP (1 << 22) /**< major poison trap */ #define EX_LSICKTRAP (1 << 23) /**< lethal illness trap */ #define EX_LPOISONTRAP (1 << 24) /**< lethal poison trap */ #define EX_LFLAMETRAP (1 << 25) /**< a large explosion */ #define NUM_EXIT_FLAGS 26

Everything here looks fine. When I try to toggle any flags after 16, nothing happens. Nothing is turned off or on. Any ideas what I did wrong here? Did I just put in too many flags and broke it? Any thoughts or direction would be greatly appreciated.



Edit: I see someone else is working on this too, that's great! I've actually gotten the traps to work thus far; they will do damage depending on the trap that is triggered, and give an appropriate message. Traps that block the exit work that way, but I haven't put in traps reseting themselves (at this point they automatically do; they'll keep going off each time the exit is passed through) nor single-use traps losing their trap flags on use. Before I add in trap detection and disarming I wanted to put the traps in completely. One thing at a time, am I right? Cheers!
Last edit: 25 Aug 2017 18:48 by Papaya Pete. Reason: Just making a small note.

Please Log in or Create an account to join the conversation.

More
26 Aug 2017 07:51 #6833 by thomas
Replied by thomas on topic Trapped Items/Disarm Trap
Hi :)

From structs.h:
Code:
struct room_direction_data { char *general_description; /**< Show to char looking in this direction. */ char *keyword; /**< for interacting (open/close) this direction */ sh_int /*bitvector_t*/ exit_info; /**< Door, and what type? */ obj_vnum key; /**< Key's vnum (-1 for no key) */ room_rnum to_room; /**< Where direction leads, or NOWHERE if not defined */ };
A door flag is a short (sh_int) which means that there are only 16 bits in it (numbered 0-15).
So, putting in "1 << 16" into it (where "1" here represents a 32-bit integer), overflows.
The behaviour of such an overflow is not specified in the C specs, so it is implementation-defined. Apparently, on your platform, it inserts -1 (ie, binary 1111111111111111) into the field.

Solution: make exit_info a bigger field, for instance an int. The world has moved on, memory is cheaper now.

Please Log in or Create an account to join the conversation.

More
26 Aug 2017 08:26 #6834 by Papaya Pete
I figured it was something so simple! And I thought it was so strange how it just stopped right at the same flag. Thank you!

I've gotten traps to work on exits; now I'm working on how a character can search for them. It's likely because it's so late at night, but before I ask any questions I'll keep looking it over. Usually, I just look at how other functions do what I need to do (example: finding the exit the player is wanting to search, and if it's an invalid exit, telling the player "That's not an exit.").

Please Log in or Create an account to join the conversation.

More
27 Aug 2017 10:58 #6837 by thomas
Replied by thomas on topic Trapped Items/Disarm Trap
What have you tried? I would look at the lock/unlock/open code for doors for seeing how those are iterated over.

Please Log in or Create an account to join the conversation.

More
28 Aug 2017 02:54 #6842 by Papaya Pete
I cannot remember what I was trying at first but I remembered that I had done something similar (reading what direction the player wanted to do something) before in the spy skill snippet. I used that and it compiles fine. I have a working exittrap function that sets off traps (or disarmed them), depending on the situation. The skill to search for traps is almost in place, I just have to double check things and test it before I move on.

Please Log in or Create an account to join the conversation.

Time to create page: 0.322 seconds