Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NWN2: Add a Trigger class with a trap implementation #377

wants to merge 35 commits into from


Copy link

@rjshae rjshae commented Oct 14, 2018

This pull request incorporates code changes to add the Trigger class for NWN2 and
embeds a new Trap class into the Door, Placeable, and Trigger classes. Detecting
and disabling traps requires skill checks; skills in turn depend on character feats, so
this adds in a partly-implemented Feats class. Traps can be detected but are not
triggered by a friendly faction, so a Factions class was implemented. For
completeness, personal reputation was included for the Factions class. Various small
details were included as needed, such as synergy skills and racial feats dependent on
area type. The types.h file was updated to include constants for the various 2da file
rows used.

Note that trap highlighting and cursor change for a trap mouse-over is not included
with this pull.

rjshae added 2 commits Oct 5, 2018
Create an initial Trap class definition by including NWN2 script
function calls as well as variables set in the .gff file for traps.
This class will be inherited by Door, Placeable, and Trigger classes;
it is not intended as a stand-alone object. The class includes calls
to process detect, disarm, and trigger events on the trap. A Trap
class instance can be created either from a GFF3Struct or by a
Creature class instance using a data row in the traps.2da file.
The latter is intended for a trigger region created from a trap item
or spell.

Note: This version of the trap.cpp file compiles with multiple
warnings for unused variables.
@rjshae rjshae force-pushed the trigger_class branch 4 times, most recently from 15fb907 to e6a0287 Oct 16, 2018
Copy link

@DrMcCoy DrMcCoy left a comment

Very nice, thanks! :D
And sorry for the slow turn-around; I've been pretty busy unfortunately.

Two things, though. First, some style issues, marked below. Also, please make sure that Doxygen comments (/**, ///<) have a period (or a question mark) at the end. Conversely, the first line of the commit message should not have a period at the end.

Second, LeakSan caught a few leaks here: . If you could plug them, that would be great.

src/engines/nwn2/trap.cpp Outdated Show resolved Hide resolved
src/engines/nwn2/trap.cpp Outdated Show resolved Hide resolved
src/engines/nwn2/trap.cpp Outdated Show resolved Hide resolved
src/engines/nwn2/trap.h Outdated Show resolved Hide resolved
Copy link
Contributor Author

@rjshae rjshae commented Nov 5, 2018

All right, I'll have a look when I get a chance. I'm finishing up another project at the moment. Thanks.

rjshae added 22 commits Nov 21, 2018
This partly implements the four disarm trap options documented in
the NWN2 manual entry for the Disable Device skill. The following
remain incomplete:

 - Examine trap: find the dialog.tlk rows for reporting the results
   of a trap Disable Device examine skill check, then post the
   appropriate string to the player's message window.
 - Recover trap: on a successful recover trap skill check, add an
   item with the matching resref to the agent creature's inventory.
Factions are stored at the module level of the game, so the
Factions class is added to the Module class and accessed by the
Object class via the _module variable in the Area class. A faction
ID is assigned to a Creature, Door, Placeable, and Trigger object,
with the faction vs. faction reputations determining whether a
Creature or Trap behaves in a friendly, neutral, or hostile manner.
(Traps will not trigger vs. a friendly faction, for example.)

Creatures can store additional reputation information for
individuals that can be modified via script calls. This is held by
a Reputation class. Each creature stores how other creatures feel
about them, with the default being the faction reputation.

Initially, Faction data is just retrieved from the repute.2da data
file. The door and placeable classes will check the faction
reputation before determining whether to trigger their trap.
Copy link
Contributor Author

@rjshae rjshae commented Nov 22, 2018

At the moment I'm stumped trying to address the memory leak. I changed this code:

Common::SeekableReadStream *stream = ResMan.getResource("repute", Aurora::kFileTypeFAC);
if (!stream)
throw Common::Exception("No repute.FAC available");
Aurora::GFF3File *gff = new Aurora::GFF3File(stream, MKTAG('F', 'A', 'C', ' '));

to this:

Common::ScopedPtr<Common::SeekableReadStream> stream(ResMan.getResource("repute", Aurora::kFileTypeFAC));
if (!stream)
throw Common::Exception("No repute.FAC available");
Common::ScopedPtr<Aurora::GFF3File> gff(new Aurora::GFF3File(&(*stream), MKTAG('F', 'A', 'C', ' ')));

but I'm getting a segmentation fault. I've tried various other ways of re-writing the GFF3File call, but none of those compiled. Obviously there's something about the ScopedPtr construct I'm not getting.

Copy link

@DrMcCoy DrMcCoy commented Nov 22, 2018

Copy link

@DrMcCoy DrMcCoy commented Nov 22, 2018

Copy link
Contributor Author

@rjshae rjshae commented Nov 22, 2018

Ah, yes. The thing is that GFF3File takes over the stream, and deletes it in its destructor. So when you have the stream in a ScopedPtr, you need to transfer ownership with release().

That resolved it. Thank you for your help.

Copy link

@DrMcCoy DrMcCoy commented Nov 23, 2018

Merged as 8b3fbd8...1fbce05, thanks! :)

(I did meld the style and leak fixes into the original commits, though)

@DrMcCoy DrMcCoy closed this Nov 23, 2018
@rjshae rjshae deleted the trigger_class branch Feb 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants