2. Now the whole spell-casting system (lines 165-464)
Back to List
Browsing Balances.inf
0165 Attribute known_about; ! Player has seen this spell somewhere
0166 Attribute reversed; ! Effect of this known spell reversed
0167
0168 Attribute is_spell;
0169 Class Spell
0170 with name "spell" "spells", article "the",
0171 number 0,
0172 word_name
0173 [; print (address) (self.&name)-->0;
0174 ],
0175 short_name
0176 [; self.word_name(); print " spell"; give self known_about; rtrue;
0177 ],
0178 specification
0179 [; self.short_name();
0180 print ": ", (string) self.purpose;
0181 ],
0182 before
0183 [; Examine: self.specification(); ".";
0184 ],
0185 has is_spell;
0186
0187 Object memory
0188 with capacity 5,
0189 number_known 1,
0190 describe_contents
0191 [ i j k;
0192 objectloop (i in self) if (i.number==100) j++;
0193 if (j>0)
0194 { print "The ";
0195 objectloop (i in self)
0196 if (i.number==100)
0197 { k++; i.word_name();
0198 if (k==j-1) print " and ";
0199 if (k<j-1) print ", ";
0200 }
0201 if (j==1) print " spell is"; else print " spells are";
0202 print " yours forever. Other than that, y";
0203 }
0204 else print "Y";
0205 print "ou have ";
0206 j=0; k=0;
0207 objectloop (i in self) if (i.number<100) j++;
0208 if (j>0)
0209 { print "the ";
0210 objectloop (i in self)
0211 if (i.number<100)
0212 { k++;
0213 print (name) i;
0214 if (i.number==2) print " (twice)";
0215 if (i.number==3) print " (thrice)";
0216 if (i.number==4) print " (four times)";
0217 if (i.number>=5) print " (many times)";
0218 if (k==j-1) print " and ";
0219 if (k<j-1) print ", ";
0220 }
0221 }
0222 else print "no spells";
0223 " memorised.";
0224 ],
0225 learn_spell
0226 [ sp;
0227 if (sp.number==100) "You always know that spell.";
0228 print "Using your best study habits, you commit the ";
0229 sp.word_name();
0230 print " spell to memory";
0231 if (sp notin self) sp.number=0;
0232 move sp to self;
0233 self.number_known++;
0234 sp.number++;
0235 if (sp.number==1) print ".";
0236 if (sp.number==2) print " once again.";
0237 if (sp.number==3) print " a third time.";
0238 if (sp.number>3) print " yet another time.";
0239 if (self.number_known <= self.capacity) { new_line; rtrue; }
0240 self.forget_spell(sibling(child(self)));
0241 " You have so much buzzing around in your head, though,
0242 that it's likely something may have been forgotten
0243 in the shuffle.";
0244 ],
0245 forget_spell
0246 [ sp;
0247 if (sp notin self || sp.number==100) rtrue;
0248 self.number_known--;
0249 sp.number--;
0250 if (sp.number==0) remove sp;
0251 rtrue;
0252 ];
0253
0254 Spell -> gnusto_spell
0255 with name "gnusto",
0256 purpose "copy a scroll into your spell book",
0257 number 100,
0258 magic
0259 [ i a_book;
0260 if (second ofclass SpellBook)
0261 "Unlike scrolls, spell books are magically guarded against
0262 the 'theft' of their lore.";
0263 if (second==0 || ~~(second ofclass Scroll))
0264 "Your spell fizzles vaguely out.";
0265 if (second notin player)
0266 "A gnusto spell would require close scrutiny of the scroll
0267 it is to copy: which you do not seem to be holding.";
0268 objectloop (i in player)
0269 if (i ofclass SpellBook) a_book=i;
0270 if (a_book==0)
0271 "Your spell fails, as you have no spell book.";
0272 i=child(second);
0273 if (i==0 || ~~(i ofclass Spell))
0274 { print_ret "Your spell fails, as ", (the) second,
0275 " is illegible.";
0276 }
0277 a_book.learn_spell(i); remove second;
0278 print_ret
0279 "Your spell book begins to glow softly. Slowly, ornately,
0280 the words of ", (the) i, " are inscribed,
0281 glowing even more brightly then the book itself.
0282 The book's brightness fades, but the spell remains!
0283 However, the scroll on which it was written vanishes as
0284 the last word is copied.";
0285 ];
0286
0287 Class SpellBook
0288 with array_of_spells 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,
0289 capacity 16,
0290 learn_spell
0291 [ sp p i;
0292 p = self.&array_of_spells;
0293 for (i=0:i<self.capacity && (p-->i)~=0:i++) ;
0294 if (i==self.capacity) rtrue;
0295 p-->i = sp;
0296 ],
0297 before
0298 [; Open, Close:
0299 print_ret
0300 (The) self, " is always open to the right place, but it
0301 is also always closed. This eliminates tedious leafing and
0302 hunting for spells. Many lives have been saved by this
0303 magical innovation.";
0304 Attack:
0305 print_ret "When you are done, ", (the) self, " remains unmarred.";
0306 ],
0307 after
0308 [ p i j; Examine:
0309 p = self.&array_of_spells;
0310 for (i=0:i<self.capacity && (p-->i)~=0:i++)
0311 { j=p-->i; <Examine j>;
0312 }
0313 rtrue;
0314 ];
0315
0316 Class Scroll
0317 with parse_name
0318 [ i j k; j=-1;
0319 if (self has general)
0320 { if (child(self)~=0 && child(self) ofclass Spell)
0321 j=(child(self).&name)-->0; else j='illegible';
0322 }
0323 for (::)
0324 { k=NextWord();
0325 if (k=='scrolls') parser_action=##PluralFound;
0326 if ((k=='scrolls' or 'scroll' or j) || k==(self.&name)-->0)
0327 i++;
0328 else return i;
0329 }
0330 ],
0331 before
0332 [ i; Examine:
0333 i=child(self);
0334 give self general;
0335 if (i==0 || ~~(i ofclass Spell))
0336 "The scroll has faded, and you cannot read it.";
0337 print "The scroll reads ~"; i.specification(); "~.";
0338 ],
0339 invent
0340 [; if (inventory_stage==2 && self has general)
0341 { if (child(self)==0 || ~~(child(self) ofclass Spell))
0342 print " (which is illegible)";
0343 else
0344 { print " (of ", (the) child(self), ")"; }
0345 }
0346 ];
0347
0348 [ ReadableSpell i j k;
0349 if (scope_stage==1)
0350 { if (action_to_be==##Examine) rfalse;
0351 rtrue;
0352 }
0353 if (scope_stage==2)
0354 { objectloop (i in player)
0355 if (i ofclass SpellBook)
0356 { for (k=0:k<i.capacity && (i.&array_of_spells)-->k~=0:k++)
0357 { j=(i.&array_of_spells)-->k; PlaceInScope(j);
0358 }
0359 }
0360 rtrue;
0361 }
0362 ! No need for scope_stage 3 (the error stage), because our
0363 ! ParserError routine handles that case instead
0364 ];
0365
0366 [ CopyableSpell i j k;
0367 if (scope_stage==1) return 1;
0368 if (scope_stage==2)
0369 { objectloop (i in player)
0370 if (i ofclass SpellBook)
0371 { for (k=0:k<i.capacity && (i.&array_of_spells)-->k~=0:k++)
0372 { j=(i.&array_of_spells)-->k; PlaceInScope(j);
0373 }
0374 }
0375 rfalse;
0376 }
0377 ! No need for scope_stage 3 (the error stage), because our
0378 ! ParserError routine handles that case instead
0379 ];
0380
0381 [ SpellsSub; memory.describe_contents(); ];
0382
0383 [ LearnSub; if (location==thedark)
0384 print "(The magic writing of the spells casts enough light
0385 that you can read them.)^";
0386 memory.learn_spell(noun);
0387 ];
0388
0389 Global the_spell_was = gnusto_spell;
0390
0391 [ CastOneSub; <Cast the_spell_was noun>; ];
0392
0393 [ CastSub;
0394 the_spell_was = noun; memory.forget_spell(noun);
0395
0396 if (noun has reversed)
0397 { give noun ~reversed;
0398 if (noun.unmagic() ~= 0) return;
0399 "Nothing happens.";
0400 }
0401
0402 if (second ~= 0)
0403 { ResetVagueWords(second); ! Set "it", "him", "her"
0404 if (second provides before
0405 && second.before() ~= 0) return; ! Run before routine(s)
0406 }
0407 if (noun.magic() ~= 0) return;
0408 "Nothing happens.";
0409 ];
0410
0411 [ InScope i;
0412 if (verb_word=='c,cast' or 'cast')
0413 objectloop (i in memory) PlaceInScope(i);
0414 rfalse;
0415 ];
0416
0417 [ ParserError x i flag vb;
0418 if (etype==VERB_PE or ASKSCOPE_PE)
0419 { if (etype==ASKSCOPE_PE)
0420 { if (verb_word=='cast') vb=1;
0421 if (verb_word=='learn' or 'memorise' or 'memorize') vb=2;
0422 if (verb_word=='copy') vb=3;
0423 if (vb==0) { etype=CANTSEE_PE; rfalse; }
0424 }
0425 wn=verb_wordnum; if (vb~=0) wn++;
0426 x=NextWordStopped();
0427 for (i=player+1:i<=top_object:i++)
0428 if (i ofclass Spell && Refers(i,x)==1
0429 && i has known_about) flag=1;
0430 if (flag==1)
0431 { if (vb==0 or 1)
0432 "You haven't got that spell committed to memory. [Type ~spells~
0433 to see what you do remember.]";
0434 if (vb==2)
0435 "Your training is such that you can only memorise such a spell
0436 with the aid of a spell book containing it.";
0437 if (vb==3)
0438 "You have no text of that spell to copy.";
0439 }
0440 if (vb==1)
0441 "You haven't learned that spell, if indeed it is a spell.";
0442 if (vb==2 or 3)
0443 "You haven't access to that spell, if indeed it is a spell.";
0444 }
0445 rfalse;
0446 ];
0447
0448 [ ChooseObjects obj code;
0449 if (code<2) rfalse;
0450 if (action_to_be==##WriteOn && obj in player) return 9;
0451 return 0;
0452 ];
0453
0454 [ UnknownVerb word i;
0455 objectloop (i in memory)
0456 if (word==(i.&name)-->0) { the_spell_was = i; return 'c,cast'; }
0457 rfalse;
0458 ];
0459
0460 [ PrintVerb v;
0461 if (v=='c,cast') { print "cast a spell at"; rtrue; }
0462 rfalse;
0463 ];
0464
Last updated 23 June 2004.
This site is no longer supported; information may be out of date.
Maintained as a historical archive by the Interactive Fiction Technology Foundation.
Copyright 1993-2018 IFTF, CC-BY-SA unless otherwise noted.
This page was originally managed by Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight.