-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathornpc_doverb.h
144 lines (140 loc) · 7.91 KB
/
ornpc_doverb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 2004.03.08 ORNPC_doverb [Z, GLULX]
! Gives an NPC the ability to perform actions as the player would.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!--------------------------------------------------------------------------------------
! Created by Jim Fisher
!-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
! License:
! This work is licensed under the Creative Commons Attribution-ShareAlike License
! (http://creativecommons.org/licenses/by-sa/1.0/).
!
! In summary: you must credit the original author(s); if you alter, transform, or
! build upon this software, you may distribute the SOURCE FORM of the resulting
! work only under a license identical to this one. Note that the ShareAlike clause
! does not affect the way in which you distribute the COMPILED FORM of works built upon
! this software. Copyright remains with the original author(s), from whom you
! must seek permission if you wish to vary any of the terms of this license.
! The author(s) would also welcome bug reports and enhancement suggestions.
!--------------------------------------------------------------------------------------
! AutoDep : ORNPCVerb
!--------------------------------------------------------------------------------------
! NPC Componant Priority: 5
! The lower the number, the further down the "class" line. The greater the number,
! the earlier it needs to come on the class line. Modules with the same priority can
! effectively be exchanged in order without effect.
!--------------------------------------------------------------------------------------
! This module brings together the ORNPCVerb module and OREnglish to enable an NPC to
! perform actions in exactly the same way as the PC. To get an NPC to perform an action,
! the DoVerb routine is exposed which takes the action, noun, and second as parameters:
!
! troll.DoVerb(##Wave);
! troll.DoVerb(##Take, Gem);
! troll.DoVerb(##Insert, Gem, Pocket);
!
! Additionally, the "follow_orders" property can list all verbs that the NPC will obey.
! As an alternative, the "will_follow_all_orders" property can be set to true to get the
! NPC to attempt to perform all actions except those specified in the "ignore_orders"
! property list.
!--------------------------------------------------------------------------------------
! To register this module with your library, add the line:
!
! #include "ORNPC_doverb"; !Constant USE_ORNPC_doverb;
!
! to the library header file (OR_Library_Include). To use in a game, add the line:
!
! Constant USE_ORNPC_doverb; to the game file;
!
! to the game file;
!--------------------------------------------------------------------------------------
! Revision History
! 2002.02.05 Initial Creation (Not really, but this was the earliest date I could
! find without searching my code archive.)
! 2002.02.26 Fit to new template.
! 2002.05.08 2 bugs and fixes, found by Stephen Robert Norris.
! 1) Before rules not being called by NPCs
! 2) Unrecognized orders attempted
! 2002.05.12 Additional code in DoVerb Routine to set and save the inp1 and inp2
! variables (again sent in by Stepen Norris.)
! 2002.09.02 Converted attributes previously defined in this module to properties.
! 2004.03.08 Added check to ensure OREnglish is being included.
!--------------------------------------------------------------------------------------
message " Processing library extension ORNPC_doverb...";
!======================================================================================
! D E P E N D A N C I E S section (for bringing in dependant modules)
!======================================================================================
! #ifndef <REPLACEWITHINCLUDENAME>_DONEREPLACE; default USE_<REPLACEWITHINCLUDENAME> 0; message " [ORNPC_doverb forcing inclusion of <REPLACEWITHINCLUDENAME>]"; #include "<REPLACEWITHINCLUDENAME>"; #endif;
#ifndef ORLibraryInclude; message fatalerror "ORNPC_doverb has dependences and cannot stand alone. Leverage the OR_Library_Include file to automatically meet module prerequisites."; #endif;
! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
#ifndef ORNPCVerb_DONEREPLACE; default USE_ORNPCVerb 0; message " [ORNPC_doverb forcing inclusion of ORNPCVerb]"; #include "ORNPCVerb"; #endif;
!======================================================================================
#ifndef LIBRARY_PARSER; #ifndef ORNPC_doverb_DONEREPLACE; constant ORNPC_doverb_DONEREPLACE; #ifdef ORNPC_doverb_DONEREPLACE; #endif; !--suppress warning
! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
! R E P L A C E section (for code that preceeds the inclusion of PARSER)
!======================================================================================
!======================================================================================
#ifnot; message " ...Already Included. Skipping."; #endif; #ifnot; #ifndef LIBRARY_VERBLIB; #ifndef ORNPC_doverb_DONEMESSAGE; constant ORNPC_doverb_DONEMESSAGE; #ifdef ORNPC_doverb_DONEMESSAGE; #endif; !--suppress warning
! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
! M E S S A G E section (for code that falls between PARSER and VERBLIB )
!======================================================================================
#ifndef OREnglish; message fatalerror "ERROR!!!! ORNPC_doverb requires the OREnglish file.";#endif;
class ORNPC_doverb
with will_follow_all_orders false
, ignore_orders 0
, follow_orders 0
, DoVerb[act n s svAL svActr svActn svN svS svInp1 svInp2 retval;
!---1) save current information
svAL=actors_location;
svActr=actor;
svActn=action;
svN=noun;
svS=second;
svInp1 = inp1;
svInp2 = inp2;
!---2) specify new values
actors_location=parent(self);
actor=self;
action=act;
noun=n;
second=s;
inp1 = noun;
inp2 = second;
MoveFloatingObjects();
!---3) perform action (assuming Before doesn't interupt it)
retval=BeforeRoutines();
if(retval==false) retval=ActionPrimitive();
!---4) restore saved information
actors_location=svAL;
actor=svActr;
action=svActn;
noun=svN;
second=svS;
inp1 = svInp1;
inp2 = svInp2;
MoveFloatingObjects();
return retval;
]
, orders [;
if(action==##NotUnderstood) rfalse;
if(self==player && valueorrun(self,ownwill)==false) rfalse;
if(self.will_follow_all_orders==true || WordInProperty(action,self,follow_orders)==true){
if(WordInProperty(action,self,ignore_orders)==true) rfalse;
return self.doVerb(action, noun, second);
}
rfalse;
]
, ownwill false
;
!======================================================================================
#endif; #ifnot; #ifndef LIBRARY_GRAMMAR; #ifndef ORNPC_doverb_DONECODE;constant ORNPC_doverb_DONECODE; #ifdef ORNPC_doverb_DONECODE; #endif; !--suppress warning
! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
! C O D E section (for code that falls between VERBLIB and GRAMMAR)
!======================================================================================
!======================================================================================
#endif; #ifnot; #ifndef ORNPC_doverb_DONEGRAMMAR; constant ORNPC_doverb_DONEGRAMMAR; #ifdef ORNPC_doverb_DONEGRAMMAR; #endif; !--suppress warning
! -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
! G R A M M A R section (for code that follows the inclusion of GRAMMAR)
!======================================================================================
!======================================================================================
#endif; #endif; #endif;#endif;
!======================================================================================