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
, truth UsableInWilderness
, truth WizardModeFunction
) :
60 LinkedFunction(LinkedFunction
),
61 Description(Description
),
63 UsableInWilderness(UsableInWilderness
),
64 WizardModeFunction(WizardModeFunction
)
69 ////////////////////////////////////////////////////////////////////////////////
71 static const char *adirNames[9] = {
86 void commandsystem::ConfigureKeys () {
91 fname
<< ivanconfig::GetMyDir();
93 fname
<< getenv("HOME");
95 fname
<< "/.ivan.keys.rc";
96 FILE *fl
= fopen(fname
.CStr(), "r");
98 while (fgets(buf
, 510, fl
)) {
101 if (buf
[0] == '=' && buf
[1] != '=') {
104 } else if (buf
[1] != '=') {
110 for (int f
= 0; (cmd
= commandsystem::GetCommand(f
)) != 0; ++f
) {
111 if (!strcmp(buf
+i1
, cmd
->GetName().CStr())) cmd
->SetKey(k1
);
113 //for (int f = 0; f <= 8; f++) if (!strcmp(buf+i1, adirNames[f])) game::SetNormalMoveKey(f, k1);
119 void commandsystem::SaveKeys (truth forced
) {
124 fname
<< ivanconfig::GetMyDir();
126 fname
<< getenv("HOME");
128 fname
<< "/.ivan.keys.rc";
130 if (inputfile::fileExists(fname
)) return;
132 FILE *fl
= fopen(fname
.CStr(), "w");
134 for (; isWizard
< 2; isWizard
++) {
135 fputs(isWizard
? "\n# wizard actions\n" : "# actions\n", fl
);
136 for (int f
= 0; (cmd
= commandsystem::GetCommand(f
)) != 0; ++f
) {
137 if (cmd
->IsWizardModeFunction()) {
138 if (!isWizard
) continue;
140 if (isWizard
) continue;
142 cchar
*dsc
= cmd
->GetName().CStr();
143 char k1
= cmd
->GetKey();
144 if (!dsc
|| !dsc
[0]) continue;
145 fprintf(fl
, "%c", (k1
? k1
: '\x7f'));
146 fprintf(fl
, "=%s\n", dsc
);
150 fputs("\n# alternate movement\n", fl);
151 for (int f = 0; f <= 8; f++) {
152 char ch = game::GetAbnormalMoveKey(f);
153 if (ch) fputc(ch, fl);
154 fprintf(fl, "=%s\n", adirNames[f]);
162 ////////////////////////////////////////////////////////////////////////////////
163 std::vector
<command
*> commandsystem::mCommands
;
166 void commandsystem::RegisterCommand (command
*cmd
) {
167 for (unsigned int f
= 0; f
< mCommands
.size(); ++f
) {
168 if (mCommands
[f
]->GetName() == cmd
->GetName()) {
175 mCommands
.push_back(cmd
);
179 ////////////////////////////////////////////////////////////////////////////////
180 static truth
Consume (character
* Char
, cchar
*ConsumeVerb
, sorter Sorter
) {
181 lsquare
*Square
= Char
->GetLSquareUnder();
182 stack
*Inventory
= Char
->GetStack();
183 stack
*StackUnder
= Square
->GetStack();
184 if ((game::IsInWilderness() || !StackUnder
->SortedItems(Char
, Sorter
)) && !Inventory
->SortedItems(Char
, Sorter
)) {
185 ADD_MESSAGE("You have nothing to %s!", ConsumeVerb
);
189 festring Question
= CONST_S("What do you wish to ")+ConsumeVerb
+'?';
190 if (!game::IsInWilderness() && StackUnder
->SortedItems(Char
, Sorter
))
191 Inventory
->DrawContents(Item
, StackUnder
, Char
, Question
, CONST_S("Items in your inventory"), CONST_S("Items on the ground"), CONST_S(""), 0, NO_MULTI_SELECT
|SELECT_ZEROPICK_FIRST
, Sorter
);
193 Inventory
->DrawContents(Item
, Char
, Question
, NO_MULTI_SELECT
, Sorter
);
194 return !Item
.empty() ? Char
->ConsumeItem(Item
[0], ConsumeVerb
+CONST_S("ing")) : false;
198 ////////////////////////////////////////////////////////////////////////////////
199 #include "commands/0list.cpp"
202 commandsystem::commandsystem () {
203 RegisterCommand(new command("Apply", &Apply
, "apply", 'a'));
204 RegisterCommand(new command("Talk", &Talk
, "chat", 'C'));
205 RegisterCommand(new command("Close", &Close
, "close", 'c'));
206 RegisterCommand(new command("Dip", &Dip
, "dip", '!'));
207 RegisterCommand(new command("Dump", &Dump
, "dump potion/can contents", 'U'));
208 RegisterCommand(new command("Drink", &Drink
, "drink", 'D', true));
209 RegisterCommand(new command("Drop", &Drop
, "drop", 'd', true));
210 RegisterCommand(new command("Eat", &Eat
, "eat", 'e', true));
211 RegisterCommand(new command("WhatToEngrave", &WhatToEngrave
, "engrave", 'G'));
212 RegisterCommand(new command("EquipmentScreen", &EquipmentScreen
, "equipment menu", 'E', true));
213 RegisterCommand(new command("Go", &Go
, "go", 'g'));
214 RegisterCommand(new command("GoDown", &GoDown
, "go down/enter area", '>', true));
215 RegisterCommand(new command("GoUp", &GoUp
, "go up", '<', true));
216 RegisterCommand(new command("IssueCommand", &IssueCommand
, "issue command(s) to team member(s)", 'I'));
217 RegisterCommand(new command("Kick", &Kick
, "kick", 'k'));
218 RegisterCommand(new command("Look", &Look
, "look", 'l', true));
219 RegisterCommand(new command("AssignName", &AssignName
, "name", 'n'));
220 RegisterCommand(new command("Offer", &Offer
, "offer", 'O'));
221 RegisterCommand(new command("Open", &Open
, "open", 'o'));
222 RegisterCommand(new command("PickUp", &PickUp
, "pick up", ','));
223 RegisterCommand(new command("Pray", &Pray
, "pray", 'p'));
224 RegisterCommand(new command("Quit", &Quit
, "quit", 'Q', true));
225 RegisterCommand(new command("Read", &Read
, "read", 'r'));
226 RegisterCommand(new command("Rest", &Rest
, "rest/heal", 'h', true));
227 RegisterCommand(new command("Save", &Save
, "save game", 'S', true));
228 RegisterCommand(new command("ScrollMessagesDown", &ScrollMessagesDown
, "scroll messages down", '=', true));
229 RegisterCommand(new command("ScrollMessagesUp", &ScrollMessagesUp
, "scroll messages up", '-', true));
230 RegisterCommand(new command("ShowConfigScreen", &ShowConfigScreen
, "show config screen", '\\', true));
231 RegisterCommand(new command("ShowInventory", &ShowInventory
, "show inventory", 'i', true));
232 RegisterCommand(new command("ShowKeyLayout", &ShowKeyLayout
, "show key layout", '?', true));
233 RegisterCommand(new command("DrawMessageHistory", &DrawMessageHistory
, "show message history", 'M', true));
234 RegisterCommand(new command("ShowWeaponSkills", &ShowWeaponSkills
, "show weapon skills", '@', true));
235 RegisterCommand(new command("Search", &Search
, "search", 's'));
236 RegisterCommand(new command("Sit", &Sit
, "sit", '_'));
237 RegisterCommand(new command("Throw", &Throw
, "throw", 't'));
238 RegisterCommand(new command("ToggleRunning", &ToggleRunning
, "toggle running", 'u', true));
239 RegisterCommand(new command("ForceVomit", &ForceVomit
, "vomit", 'V'));
240 RegisterCommand(new command("NOP", &NOP
, "wait", '.', true));
241 RegisterCommand(new command("WieldInRightArm", &WieldInRightArm
, "wield in right arm", 'w', true));
242 RegisterCommand(new command("WieldInLeftArm", &WieldInLeftArm
, "wield in left arm", 'W', true));
243 RegisterCommand(new command("Burn", &Burn
, "burn", 'B'));
245 RegisterCommand(new command("WizardMode", &WizardMode
, "wizard mode activation", 'X', true));
247 RegisterCommand(new command("Zap", &Zap
, "zap", 'z'));
249 /* Sort according to key */
250 RegisterCommand(new command("RaiseStats", &RaiseStats
, "raise stats", '1', true, true));
251 RegisterCommand(new command("LowerStats", &LowerStats
, "lower stats", '2', true, true));
252 RegisterCommand(new command("SeeWholeMap", &SeeWholeMap
, "see whole map", '3', true, true));
253 RegisterCommand(new command("WalkThroughWalls", &WalkThroughWalls
, "toggle walk through walls mode", '4', true, true));
254 RegisterCommand(new command("RaiseGodRelations", &RaiseGodRelations
, "raise your relations to the gods", '5', true, true));
255 RegisterCommand(new command("LowerGodRelations", &LowerGodRelations
, "lower your relations to the gods", '6', true, true));
256 RegisterCommand(new command("WizardWish", &WizardWish
, "wish something", '`', true, true));
257 RegisterCommand(new command("GainDivineKnowledge", &GainDivineKnowledge
, "gain knowledge of all gods", '\"', true, true));
258 RegisterCommand(new command("GainAllItems", &GainAllItems
, "gain all items", '$', true, true));
259 RegisterCommand(new command("SecretKnowledge", &SecretKnowledge
, "reveal secret knowledge", '*', true, true));
260 RegisterCommand(new command("DetachBodyPart", &DetachBodyPart
, "detach a limb", '0', true, true));
261 RegisterCommand(new command("SummonMonster", &SummonMonster
, "summon monster", '&', false, true));
262 RegisterCommand(new command("LevelTeleport", &LevelTeleport
, "level teleport", '|', false, true));
263 RegisterCommand(new command("Possess", &Possess
, "possess creature", '{', false, true));
264 RegisterCommand(new command("Polymorph", &Polymorph
, "polymorph", '[', true, true));
265 RegisterCommand(new command("GetScroll", &GetScroll
, "get scroll", 'R', true, true));
266 RegisterCommand(new command("OpenMondedr", &OpenMondedr
, "open Mondedr", 'N', true, true));
267 RegisterCommand(new command("OpenXinTomb", &OpenXinTomb
, "open Xinroch Tomb", 'T', true, true));
268 RegisterCommand(new command("ShowCoords", &ShowCoords
, "show current coordinates", '(', true, true));
269 RegisterCommand(new command("WizardHeal", &WizardHeal
, "wizard healing", 'H', true, true));
270 RegisterCommand(new command("WizardBlow", &WizardBlow
, "wizard blowing", '%', false, true));
271 RegisterCommand(new command("WizardTeam", &WizardTeam
, "wizard teaming", '/', false, true));
276 static commandsystem cmdsystem
;