2 * Iter Vehemens ad Necem (IVAN)
3 * Copyright (C) Timo Kiviluoto
4 * Released under the GNU General
7 * See LICENSING which should be included
8 * along with this file for more details
39 #define COMMAND(name) static truth name (character *Char)
42 ////////////////////////////////////////////////////////////////////////////////
45 static void cstrTrim (char *buf
) {
47 while (*p
&& *((unsigned char *)(p
)) <= ' ') p
++;
48 if (!p
[0]) { buf
[0] = '\0'; return; } /* empty line */
49 if (p
> buf
) { t
= buf
; while (*p
) *t
++ = *p
++; }
50 p
= buf
+strlen(buf
)-1;
51 while (p
>= buf
&& *((unsigned char *)(p
)) <= ' ') p
--;
52 if (p
< buf
) { buf
[0] = '\0'; return; } /* empty line */
57 ////////////////////////////////////////////////////////////////////////////////
58 command::command(cchar
*name
, truth (*LinkedFunction
)(character
*), cchar
*Description
, char Key1
, char Key2
, truth UsableInWilderness
, truth WizardModeFunction
) :
60 LinkedFunction(LinkedFunction
),
61 Description(Description
),
62 Key1(Key1
), Key2(Key2
),
63 UsableInWilderness(UsableInWilderness
),
64 WizardModeFunction(WizardModeFunction
)
69 char command::GetKey () const { return !ivanconfig::GetUseAlternativeKeys() ? Key1
: Key2
; }
72 ////////////////////////////////////////////////////////////////////////////////
73 static const char *adirNames
[9] = {
87 void commandsystem::ConfigureKeys () {
92 fname
<< ivanconfig::GetMyDir();
94 fname
<< getenv("HOME");
97 FILE *fl
= fopen(fname
.CStr(), "r");
99 while (fgets(buf
, 510, fl
)) {
101 char k1
= 0, k2
= 0, i1
;
104 } else if (buf
[2] != '=') {
105 if (buf
[1] != '=') continue;
113 for (int f
= 0; (cmd
= commandsystem::GetCommand(f
)) != 0; ++f
) {
114 if (!strcmp(buf
+i1
, cmd
->GetName().CStr())) cmd
->SetKeys(k1
, k2
);
116 for (int f
= 0; f
<= 8; f
++) if (!strcmp(buf
+i1
, adirNames
[f
])) game::SetAbnormalMoveKey(f
, k1
);
122 void commandsystem::SaveKeys (truth forced
) {
127 fname
<< ivanconfig::GetMyDir();
129 fname
<< getenv("HOME");
131 fname
<< "/.keys.rc";
133 if (inputfile::fileExists(fname
)) return;
135 FILE *fl
= fopen(fname
.CStr(), "w");
137 for (; isWizard
< 2; isWizard
++) {
138 fputs(isWizard
? "\n# wizard actions\n" : "# actions\n", fl
);
139 for (int f
= 0; (cmd
= commandsystem::GetCommand(f
)) != 0; ++f
) {
140 if (cmd
->IsWizardModeFunction()) {
141 if (!isWizard
) continue;
143 if (isWizard
) continue;
145 cchar
*dsc
= cmd
->GetName().CStr();
146 char k1
= cmd
->GetKey1(), k2
= cmd
->GetKey2();
147 if (!dsc
|| !dsc
[0]) continue;
148 if (k1
&& k2
&& k1
!= k2
) fprintf(fl
, "%c%c", k1
, k2
);
149 else if (k1
) fprintf(fl
, "%c", k1
);
150 else if (k2
) fprintf(fl
, "%c", k2
);
151 fprintf(fl
, "=%s\n", dsc
);
154 fputs("\n# alternate movement\n", fl
);
155 for (int f
= 0; f
<= 8; f
++) {
156 char ch
= game::GetAbnormalMoveKey(f
);
157 if (ch
) fputc(ch
, fl
);
158 fprintf(fl
, "=%s\n", adirNames
[f
]);
165 ////////////////////////////////////////////////////////////////////////////////
166 std::vector
<command
*> commandsystem::mCommands
;
169 void commandsystem::RegisterCommand (command
*cmd
) {
170 for (unsigned int f
= 0; f
< mCommands
.size(); ++f
) {
171 if (mCommands
[f
]->GetName() == cmd
->GetName()) {
178 mCommands
.push_back(cmd
);
182 ////////////////////////////////////////////////////////////////////////////////
183 static truth
Consume (character
* Char
, cchar
*ConsumeVerb
, sorter Sorter
) {
184 lsquare
*Square
= Char
->GetLSquareUnder();
185 stack
*Inventory
= Char
->GetStack();
186 stack
*StackUnder
= Square
->GetStack();
187 if ((game::IsInWilderness() || !StackUnder
->SortedItems(Char
, Sorter
)) && !Inventory
->SortedItems(Char
, Sorter
)) {
188 ADD_MESSAGE("You have nothing to %s!", ConsumeVerb
);
192 festring Question
= CONST_S("What do you wish to ")+ConsumeVerb
+'?';
193 if (!game::IsInWilderness() && StackUnder
->SortedItems(Char
, Sorter
))
194 Inventory
->DrawContents(Item
, StackUnder
, Char
, Question
, CONST_S("Items in your inventory"), CONST_S("Items on the ground"), CONST_S(""), 0, NO_MULTI_SELECT
, Sorter
);
196 Inventory
->DrawContents(Item
, Char
, Question
, NO_MULTI_SELECT
, Sorter
);
197 return !Item
.empty() ? Char
->ConsumeItem(Item
[0], ConsumeVerb
+CONST_S("ing")) : false;
201 ////////////////////////////////////////////////////////////////////////////////
202 #include "commands/0list.cpp"
205 commandsystem::commandsystem () {
206 RegisterCommand(new command("Apply", &Apply
, "apply", 'a', 'a', false));
207 RegisterCommand(new command("Talk", &Talk
, "chat", 'C', 'C', false));
208 RegisterCommand(new command("Close", &Close
, "close", 'c', 'c', false));
209 RegisterCommand(new command("Dip", &Dip
, "dip", '!', '!', false));
210 RegisterCommand(new command("Dump", &Dump
, "dump potion/can contents", 'U', 'U', false));
211 RegisterCommand(new command("Drink", &Drink
, "drink", 'D', 'D', true));
212 RegisterCommand(new command("Drop", &Drop
, "drop", 'd', 'd', true));
213 RegisterCommand(new command("Eat", &Eat
, "eat", 'e', 'e', true));
214 RegisterCommand(new command("WhatToEngrave", &WhatToEngrave
, "engrave", 'G', 'G', false));
215 RegisterCommand(new command("EquipmentScreen", &EquipmentScreen
, "equipment menu", 'E', 'E', true));
216 RegisterCommand(new command("Go", &Go
, "go", 'g', 'g', false));
217 RegisterCommand(new command("GoDown", &GoDown
, "go down/enter area", '>', '>', true));
218 RegisterCommand(new command("GoUp", &GoUp
, "go up", '<', '<', true));
219 RegisterCommand(new command("IssueCommand", &IssueCommand
, "issue command(s) to team member(s)", 'I', 'I', false));
220 RegisterCommand(new command("Kick", &Kick
, "kick", 'k', 'K', false));
221 RegisterCommand(new command("Look", &Look
, "look", 'l', 'L', true));
222 RegisterCommand(new command("AssignName", &AssignName
, "name", 'n', 'n', false));
223 RegisterCommand(new command("Offer", &Offer
, "offer", 'O', 'f', false));
224 RegisterCommand(new command("Open", &Open
, "open", 'o', 'O', false));
225 RegisterCommand(new command("PickUp", &PickUp
, "pick up", ',', ',', false));
226 RegisterCommand(new command("Pray", &Pray
, "pray", 'p', 'p', false));
227 RegisterCommand(new command("Quit", &Quit
, "quit", 'Q', 'Q', true));
228 RegisterCommand(new command("Read", &Read
, "read", 'r', 'r', false));
229 RegisterCommand(new command("Rest", &Rest
, "rest/heal", 'h', 'h', true));
230 RegisterCommand(new command("Save", &Save
, "save game", 'S', 'S', true));
231 RegisterCommand(new command("ScrollMessagesDown", &ScrollMessagesDown
, "scroll messages down", '+', '+', true));
232 RegisterCommand(new command("ScrollMessagesUp", &ScrollMessagesUp
, "scroll messages up", '-', '-', true));
233 RegisterCommand(new command("ShowConfigScreen", &ShowConfigScreen
, "show config screen", '\\', '\\', true));
234 RegisterCommand(new command("ShowInventory", &ShowInventory
, "show inventory", 'i', 'i', true));
235 RegisterCommand(new command("ShowKeyLayout", &ShowKeyLayout
, "show key layout", '?', '?', true));
236 RegisterCommand(new command("DrawMessageHistory", &DrawMessageHistory
, "show message history", 'M', 'M', true));
237 RegisterCommand(new command("ShowWeaponSkills", &ShowWeaponSkills
, "show weapon skills", '@', '@', true));
238 RegisterCommand(new command("Search", &Search
, "search", 's', 's', false));
239 RegisterCommand(new command("Sit", &Sit
, "sit", '_', '_', false));
240 RegisterCommand(new command("Throw", &Throw
, "throw", 't', 't', false));
241 RegisterCommand(new command("ToggleRunning", &ToggleRunning
, "toggle running", 'u', 'U', true));
242 RegisterCommand(new command("ForceVomit", &ForceVomit
, "vomit", 'V', 'V', false));
243 RegisterCommand(new command("NOP", &NOP
, "wait", '.', '.', true));
244 RegisterCommand(new command("WieldInRightArm", &WieldInRightArm
, "wield in right arm", 'w', 'w', true));
245 RegisterCommand(new command("WieldInLeftArm", &WieldInLeftArm
, "wield in left arm", 'W', 'W', true));
246 RegisterCommand(new command("Burn", &Burn
, "burn", 'B', 'B', false));
248 RegisterCommand(new command("WizardMode", &WizardMode
, "wizard mode activation", 'X', 'X', true));
250 RegisterCommand(new command("Zap", &Zap
, "zap", 'z', 'z', false));
252 /* Sort according to key */
253 RegisterCommand(new command("RaiseStats", &RaiseStats
, "raise stats", '1', '1', true, true));
254 RegisterCommand(new command("LowerStats", &LowerStats
, "lower stats", '2', '2', true, true));
255 RegisterCommand(new command("SeeWholeMap", &SeeWholeMap
, "see whole map", '3', '3', true, true));
256 RegisterCommand(new command("WalkThroughWalls", &WalkThroughWalls
, "toggle walk through walls mode", '4', '4', true, true));
257 RegisterCommand(new command("RaiseGodRelations", &RaiseGodRelations
, "raise your relations to the gods", '5', '5', true, true));
258 RegisterCommand(new command("LowerGodRelations", &LowerGodRelations
, "lower your relations to the gods", '6', '6', true, true));
259 RegisterCommand(new command("WizardWish", &WizardWish
, "wish something", '=', '=', true, true));
260 RegisterCommand(new command("GainDivineKnowledge", &GainDivineKnowledge
, "gain knowledge of all gods", '\"', '\"', true, true));
261 RegisterCommand(new command("GainAllItems", &GainAllItems
, "gain all items", '$', '$', true, true));
262 RegisterCommand(new command("SecretKnowledge", &SecretKnowledge
, "reveal secret knowledge", '*', '*', true, true));
263 RegisterCommand(new command("DetachBodyPart", &DetachBodyPart
, "detach a limb", '0', '0', true, true));
264 RegisterCommand(new command("SummonMonster", &SummonMonster
, "summon monster", '&', '&', false, true));
265 RegisterCommand(new command("LevelTeleport", &LevelTeleport
, "level teleport", '|', '|', false, true));
266 RegisterCommand(new command("Possess", &Possess
, "possess creature", '{', '{', false, true));
267 RegisterCommand(new command("Polymorph", &Polymorph
, "polymorph", '[', '[', true, true));
268 RegisterCommand(new command("GetScroll", &GetScroll
, "get scroll", 'R', 'R', true, true));
269 RegisterCommand(new command("OpenMondedr", &OpenMondedr
, "open Mondedr", 'M', 'M', true, true));
270 RegisterCommand(new command("ShowCoords", &ShowCoords
, "show current coordinates", '(', '(', true, true));
271 RegisterCommand(new command("WizardHeal", &WizardHeal
, "wizard healing", 'H', 'H', true, true));
272 RegisterCommand(new command("WizardBlow", &WizardBlow
, "wizard blowing", '%', '%', false, true));
273 RegisterCommand(new command("WizardTeam", &WizardTeam
, "wizard teaming", '/', '/', false, true));
278 static commandsystem cmdsystem
;