home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #7 / amigamamagazinepolishissue1998.iso / rozrywka / rpg / amigamud / src / extras / spells.m < prev   
Text File  |  1997-08-07  |  14KB  |  584 lines

  1. /*
  2.  * Amiga MUD
  3.  *
  4.  * Copyright (c) 1997 by Chris Gray
  5.  */
  6.  
  7. /*
  8.  * spells.m - some handy wizard spells for use with 'cast'.
  9.  */
  10.  
  11. use t_base
  12. use t_icons
  13. use t_graphics
  14. use t_util
  15. use t_fight
  16. use t_quests
  17.  
  18. /* Make sure the sourcer of this file has a spell table. */
  19. if LookupTable(PrivateTable(), "t_spells") = nil then
  20.     ignore DefineTable(PrivateTable(), "t_spells", CreateTable());
  21. fi$
  22.  
  23. private tp_spellStuff CreateTable()$
  24. use tp_spellStuff
  25.  
  26. /* a 'spells' spell which lists the spells we have here */
  27.  
  28. define t_spells proc spells()void:
  29.  
  30.     Print("Known spells:\n\n");
  31.     Print("find <who> - show what <who> sees\n");
  32.     Print("poofto <who> - teleport to same location as <who>\n");
  33.     Print("look <who> - look at <who>, even if not nearby\n");
  34.     Print("sendto <who> <stuff> - send <stuff> to <who> as mindsend\n");
  35.     Print("heal <who> - heal <who> upto max hitpoints\n");
  36.     Print("enrich <who> <amount> - give <amount> blutos to <who>\n");
  37.     Print("force <who> <what> - force <who> to do <what>\n");
  38.     Print("teleport <who> {here | <dir> | <roomname>} - teleport <who> ...\n");
  39.     Print("showmachines - show machines in entire system\n");
  40.     Print("Words in spell table:\n");
  41.     ShowTable(t_spells);
  42. corp;
  43.  
  44. define tp_spellStuff proc findMachine(string w1, w2)thing:
  45.     int index;
  46.  
  47.     index := 1;
  48.     if w2 ~= "" then
  49.     index := StringToInt(w2);
  50.     if index < 0 then
  51.         Print("Invalid index '" + w2 + "' - 1 assumed.\n");
  52.         index := 1;
  53.     fi;
  54.     fi;
  55.     FindMachineIndexed(w1, index)
  56. corp;
  57.  
  58. /* a 'find' spell which will print the location info for the given character */
  59.  
  60. define t_spells proc find()void:
  61.     string name;
  62.     character ch;
  63.     thing where, agent;
  64.     action a;
  65.     bool found;
  66.  
  67.     name := GetWord();
  68.     if name = "" then
  69.     Print("Find who?\n");
  70.     else
  71.     found := true;
  72.     ch := Character(name);
  73.     if ch = nil then
  74.         agent := findMachine(name, GetWord());
  75.         if agent = nil then
  76.         Print("There is no character or machine called '" +
  77.               name + "'.\n");
  78.         found := false;
  79.         else
  80.         where := AgentLocation(agent);
  81.         fi;
  82.     else
  83.         where := CharacterLocation(ch);
  84.     fi;
  85.     if found then
  86.         if where = nil then
  87.         Print(Capitalize(CharacterNameS(agent)) +
  88.             " is not currently anywhere.\n");
  89.         else
  90.         a := where@p_rNameAction;
  91.         if a = nil then
  92.             Print(name + " is " + where@p_rName + ".\n");
  93.         else
  94.             Print(name + ": " + call(a, string)() + ".\n");
  95.         fi;
  96.         a := where@p_rDescAction;
  97.         if a = nil then
  98.             if where@p_rDesc ~= "" then
  99.             Print(where@p_rDesc + "\n");
  100.             fi;
  101.             ShowExits(where);
  102.             ignore ShowList(where@p_rContents, "Nearby:\n");
  103.         else
  104.             Print(name + ": " + call(a, string)() + ".\n");
  105.         fi;
  106.         fi;
  107.     fi;
  108.     fi;
  109. corp;
  110.  
  111. /* a 'poofto' spell which will poof to where the given character is */
  112.  
  113. define t_spells proc poofto()void:
  114.     string name;
  115.     character ch;
  116.     thing who, where;
  117.  
  118.     name := GetWord();
  119.     if name = "" then
  120.     Print("Poofto who?\n");
  121.     else
  122.     ch := Character(name);
  123.     if ch = nil then
  124.         who := findMachine(name, GetWord());
  125.         if who = nil then
  126.         Print("There is no character or machine called '" +
  127.               name + "'.\n");
  128.         fi;
  129.     else
  130.         who := CharacterThing(ch);
  131.         if who = nil then
  132.         Print(name + " has no thing????\n");
  133.         fi;
  134.     fi;
  135.     if who ~= nil then
  136.         where := AgentLocation(who);
  137.         if where = nil then
  138.         Print(Capitalize(CharacterNameS(who)) +
  139.             " is not currently active or anywhere.\n");
  140.         else
  141.         LeaveRoomStuff(where, 0, MOVE_POOF);
  142.         EnterRoomStuff(where, 0, MOVE_POOF);
  143.         fi;
  144.     fi;
  145.     fi;
  146. corp;
  147.  
  148. /* a 'look' spell which will look at a given character */
  149.  
  150. define t_spells proc look()void:
  151.     string name, s;
  152.     character ch;
  153.     thing who;
  154.     action a;
  155.  
  156.     name := GetWord();
  157.     if name = "" then
  158.     Print("Look who?\n");
  159.     else
  160.     ch := Character(name);
  161.     if ch = nil then
  162.         who := findMachine(name, GetWord());
  163.         if who = nil then
  164.         Print("There is no character or machine called '" +
  165.               name + "'.\n");
  166.         fi;
  167.     else
  168.         who := CharacterThing(ch);
  169.         if who = nil then
  170.         Print(name + " has no thing????\n");
  171.         fi;
  172.     fi;
  173.     if who ~= nil then
  174.         if LookAtCharacter(who) then
  175.         if who@p_pMoney ~= 0 then
  176.             Print(Capitalize(CharacterNameS(who)) + " has " +
  177.             IntToString(who@p_pMoney) + " blutos.\n");
  178.         fi;
  179.         ignore ShowQuests(who, true);
  180.         fi;
  181.     fi;
  182.     fi;
  183. corp;
  184.  
  185. /* a 'sendto' spell which will say something to the given character */
  186.  
  187. define t_spells proc sendto()void:
  188.     string name;
  189.     character ch;
  190.     thing who;
  191.  
  192.     name := GetWord();
  193.     if name = "" then
  194.     Print("Sendto who?\n");
  195.     else
  196.     ch := Character(name);
  197.     if ch = nil then
  198.         if findMachine(name, GetWord()) = nil then
  199.         Print("There is no character or machine called '" +
  200.               name + "'.\n");
  201.         fi;
  202.     else
  203.         who := CharacterThing(ch);
  204.         if who = nil then
  205.         Print(name + " has no thing????\n");
  206.         else
  207.         SPrint(who, Me()@p_pName + " mindsends: " + GetTail());
  208.         fi;
  209.     fi;
  210.     fi;
  211. corp;
  212.  
  213. /* a 'heal' spell to heal someone up */
  214.  
  215. define t_spells proc heal()void:
  216.     string name;
  217.     character ch;
  218.     thing who;
  219.     int max;
  220.  
  221.     name := GetWord();
  222.     if name = "" then
  223.     Print("Heal who?\n");
  224.     else
  225.     ch := Character(name);
  226.     if ch = nil then
  227.         who := findMachine(name, GetWord());
  228.         if who = nil then
  229.         Print("There is no character or machine called '" +
  230.               name + "'.\n");
  231.         fi;
  232.     else
  233.         who := CharacterThing(ch);
  234.         if who = nil then
  235.         Print(name + " has no thing????\n");
  236.         fi;
  237.     fi;
  238.     if who ~= nil then
  239.         max := who@p_pHitMax;
  240.         if max = 0 then
  241.         Print(name + " has no maximum hitpoints.\n");
  242.         elif who@p_pHitNow = max then
  243.         Print(name + " needs no healing.\n");
  244.         else
  245.         who@p_pHitNow := max;
  246.         Print(name + " healed.\n");
  247.         SPrint(who, "You suddenly feel better!\n");
  248.         fi;
  249.     fi;
  250.     fi;
  251. corp;
  252.  
  253. /* an 'enrich' spell to give someone some blutos */
  254.  
  255. define t_spells proc enrich()void:
  256.     string name, s;
  257.     character ch;
  258.     thing who;
  259.     int amount;
  260.  
  261.     name := GetWord();
  262.     if name = "" then
  263.     Print("Enrich who?\n");
  264.     else
  265.     ch := Character(name);
  266.     if ch = nil then
  267.         who := findMachine(name, GetWord());
  268.         if who = nil then
  269.         Print("There is no character or machine called '" +
  270.               name + "'.\n");
  271.         fi;
  272.     else
  273.         who := CharacterThing(ch);
  274.         if who = nil then
  275.         Print(name + " has no thing????\n");
  276.         fi;
  277.     fi;
  278.     if who ~= nil then
  279.         s := GetWord();
  280.         if s = "" then
  281.         Print("You must specify an amount to enrich by.\n");
  282.         else
  283.         amount := StringToInt(s);
  284.         if amount <= 0 then
  285.             Print("Invalid amount - must be positive integer.\n");
  286.         else
  287.             who@p_pMoney := who@p_pMoney + amount;
  288.             Print(name + " enriched - now has " +
  289.               IntToString(who@p_pMoney) + " blutos.\n");
  290.             SPrint(who, "You suddenly feel richer!\n");
  291.         fi;
  292.         fi;
  293.     fi;
  294.     fi;
  295. corp;
  296.  
  297. /* a 'force' spell which will make someone do something */
  298.  
  299. define tp_spellStuff p_pForceAction CreateStringProp()$
  300.  
  301. define tp_spellStuff proc doForceAction()void:
  302.     string s;
  303.  
  304.     s := Me()@p_pForceAction;
  305.     if s ~= "" then
  306.     Me() -- p_pForceAction;
  307.     ignore Parse(G, s);
  308.     fi;
  309. corp;
  310.  
  311. define tp_spellStuff proc forceAnAction()status:
  312.     After(0.0, doForceAction);
  313.     continue
  314. corp;
  315.  
  316. define tp_spellStuff proc forceCharacter(thing who; string what)void:
  317.     who@p_pForceAction := what;
  318.     ignore ForceAction(who, forceAnAction);
  319. corp;
  320.  
  321. define t_spells proc force()void:
  322.     string name, w, what;
  323.     character ch;
  324.     thing who;
  325.     int n;
  326.  
  327.     name := GetWord();
  328.     if name = "" then
  329.     Print("Force who?\n");
  330.     else
  331.     w := GetWord();
  332.     what := GetTail();
  333.     ch := Character(name);
  334.     if ch = nil then
  335.         n := StringToInt(w);
  336.         if n < 0 then
  337.         what := w + " " + what;
  338.         w := "";
  339.         fi;
  340.         who := findMachine(name, w);
  341.         if who = nil then
  342.         Print("There is no character or machine called '" +
  343.               name + "'.\n");
  344.         fi;
  345.     else
  346.         what := w + " " + what;
  347.         who := CharacterThing(ch);
  348.         if who = nil then
  349.         Print(name + " has no thing????\n");
  350.         fi;
  351.     fi;
  352.     if who ~= nil then
  353.         if what = "" then
  354.         Print("You must say what you want " + name + " to do.\n");
  355.         else
  356.         SPrint(who, "***\n" + Me()@p_pName + " forces you: " +
  357.             what + "\n***\n");
  358.         forceCharacter(who, what);
  359.         fi;
  360.     fi;
  361.     fi;
  362. corp;
  363.  
  364. /* a 'teleport' spell which will send a character to a given location */
  365.  
  366. define tp_spellStuff p_pForceMove CreateThingProp()$
  367.  
  368. define tp_spellStuff proc doForceMove()status:
  369.     thing me, dest;
  370.     string name;
  371.     action a;
  372.  
  373.     me := Me();
  374.     dest := me@p_pForceMove;
  375.     if dest ~= nil then
  376.     me -- p_pForceMove;
  377.     LeaveRoomStuff(dest, 0, MOVE_POOF);
  378.     EnterRoomStuff(dest, 0, MOVE_POOF);
  379.     fi;
  380.     continue
  381. corp;
  382.  
  383. define t_spells proc teleport()void:
  384.     string name, w, location;
  385.     character ch;
  386.     thing me, here, who, where, there;
  387.     action a;
  388.     int dir, n;
  389.     property thing dirProp;
  390.  
  391.     name := GetWord();
  392.     w := GetWord();
  393.     location := GetWord();
  394.     n := StringToInt(w);
  395.     if n < 0 then
  396.     location := w;
  397.     w := "";
  398.     fi;
  399.     if location = "" then
  400.     Print("Teleport who where?\n");
  401.     else
  402.     me := Me();
  403.     here := Here();
  404.     if name == "me" then
  405.         ch := ThingCharacter(me);
  406.     else
  407.         ch := Character(name);
  408.     fi;
  409.     if ch = nil then
  410.         who := findMachine(name, w);
  411.         if who = nil then
  412.         Print("There is no character or machine called '" +
  413.               name + "'.\n");
  414.         fi;
  415.     else
  416.         who := CharacterThing(ch);
  417.         if who = nil then
  418.         Print(name + " has no thing????\n");
  419.         fi;
  420.     fi;
  421.     if who ~= nil then
  422.         where := AgentLocation(who);
  423.         if where = nil then
  424.         Print(Capitalize(CharacterNameS(who)) +
  425.             " is not currently active or anywhere.\n");
  426.         else
  427.         dir := DirMatch(location);
  428.         if dir ~= -1 then
  429.             there := here@DirProp(dir);
  430.             if there = nil then
  431.             Print("That direction does not go anywhere.\n");
  432.             fi;
  433.         else
  434.             if location == "here" then
  435.             there := here;
  436.             else
  437.             there := LookupThing(nil, location);
  438.             if there ~= nil then
  439.                 if there@p_rName = "" and
  440.                 there@p_rNameAction = nil
  441.                 then
  442.                 Print(location + " is not a location.\n");
  443.                 there := nil;
  444.                 fi;
  445.             else
  446.                 Print(location + " is not defined.\n");
  447.             fi;
  448.             fi;
  449.         fi;
  450.         if there ~= nil then
  451.             if who = me then
  452.             LeaveRoomStuff(there, 0, MOVE_POOF);
  453.             EnterRoomStuff(there, 0, MOVE_POOF);
  454.             else
  455.             SPrint(who, "***\n" +
  456.                 me@p_pName + " teleports you! \n***\n");
  457.             who@p_pForceMove := there;
  458.             ignore ForceAction(who, doForceMove);
  459.             fi;
  460.         fi;
  461.         fi;
  462.     fi;
  463.     fi;
  464. corp;
  465.  
  466. /* A 'tick' spell that just ticks every minute. */
  467.  
  468. define tp_spellStuff p_pTicking CreateBoolProp()$
  469. define tp_spellStuff TICK_ID NextEffectId()$
  470.  
  471. define tp_spellStuff proc doTick()void:
  472.  
  473.     if Me()@p_pTicking then
  474.     VSpeak(nil, "Beep", TICK_ID);
  475.     After(60.0, doTick);
  476.     fi;
  477. corp;
  478.  
  479. define t_spells proc tick()void:
  480.  
  481.     if Me()@p_pTicking then
  482.     Me() -- p_pTicking;
  483.     Print("Ticking stopped.\n");
  484.     else
  485.     Me()@p_pTicking := true;
  486.     After(60.0, doTick);
  487.     Print("Ticking started.\n");
  488.     fi;
  489. corp;
  490.  
  491. /* A 'showmachines' spell that shows you all the machines currently active. */
  492.  
  493. define tp_spellStuff p_mThing CreateThingProp()$
  494. define tp_spellStuff p_mCount CreateIntProp()$
  495. define tp_spellStuff p_pMachineList CreateThingListProp()$
  496.  
  497. define tp_spellStuff proc visitAgent(thing theAgent)void:
  498.     list thing lt;
  499.     int count, i;
  500.     thing entry, parent;
  501.  
  502.     if ThingCharacter(theAgent) = nil then
  503.     /* ignore player characters */
  504.     parent := Parent(theAgent);
  505.     if parent ~= nil and parent@p_pName ~= "" and
  506.         (parent@p_pName = theAgent@p_pName or parent@p_pName = "WANDERER")
  507.     then
  508.         /* Handle generic monsters and wanderers. */
  509.         theAgent := parent;
  510.     fi;
  511.     lt := Me()@p_pMachineList;
  512.     count := Count(lt);
  513.     i := 0;
  514.     while i ~= count and lt[i]@p_mThing ~= theAgent do
  515.         i := i + 1;
  516.     od;
  517.     if i ~= count then
  518.         lt[i]@p_mCount := lt[i]@p_mCount + 1;
  519.     else
  520.         entry := CreateThing(nil);
  521.         entry@p_mThing := theAgent;
  522.         entry@p_mCount := 1;
  523.         AddTail(lt, entry);
  524.     fi;
  525.     fi;
  526. corp;
  527.  
  528. define t_spells proc showmachines()void:
  529.     list thing lt;
  530.     int count, i, total;
  531.     thing entry;
  532.  
  533.     lt := CreateThingList();
  534.     Me()@p_pMachineList := lt;
  535.     ForEachAgent(nil, visitAgent);
  536.     total := 0;
  537.     count := Count(lt);
  538.     for i from 0 upto count - 1 do
  539.     entry := lt[i];
  540.     Print("  " + FormatName(entry@p_mThing@p_pName) + ": " +
  541.         IntToString(entry@p_mCount) + "\n");
  542.     total := total + entry@p_mCount;
  543.     od;
  544.     /* This should throw the whole thing away. */
  545.     Me() -- p_pMachineList;
  546.     Print("Total: " + IntToString(total) + ".\n");
  547. corp;
  548.  
  549. /* An 'edit' routine to allow use of the builtin editor for editing strings.
  550.    Note that this isn't a spell. There isn't any way outside of wizard mode
  551.    to get a value into your p_pEditString property, so it may as well just
  552.    be a wizard-mode callable routine. It's not just 'edit' since that
  553.    conflicts with the 'edit' wizard-mode command. */
  554.  
  555. define tp_spellStuff p_pEditString CreateStringProp()$
  556.  
  557. define tp_spellStuff proc editHandler(string s; bool ok)void:
  558.  
  559.     if ok then
  560.     Me()@p_pEditString := s;
  561.     fi;
  562. corp;
  563.  
  564. define tp_spellStuff proc editstring()void:
  565.  
  566.     if CanEdit() then
  567.     if Editing() then
  568.         Print("You are already editing something.\n");
  569.     else
  570.         EditString(Me()@p_pEditString, editHandler, EDIT_CODE, "String");
  571.     fi;
  572.     else
  573.     Print("You do not have access to a remote editor.\n");
  574.     fi;
  575. corp;
  576.  
  577. unuse tp_spellStuff
  578. unuse t_quests
  579. unuse t_fight
  580. unuse t_util
  581. unuse t_graphics
  582. unuse t_icons
  583. unuse t_base
  584.