ActionPrimitive (lines 3629-3933)
Back to List
Browsing parserm.h
3629 ! End of the parser proper: the remaining routines are its front end.
3630 ! ----------------------------------------------------------------------------
3631
3632 Object InformLibrary "(Inform Library)"
3633 with play
3634 [ i j k l;
3635 standard_interpreter = $32-->0;
3636 transcript_mode = ((0-->8) & 1);
3637 ChangeDefault(cant_go, CANTGO__TX);
3638
3639 buffer->0 = 120;
3640 buffer2->0 = 120;
3641 buffer3->0 = 120;
3642 parse->0 = 64;
3643 parse2->0 = 64;
3644
3645 real_location = thedark;
3646 player = selfobj; actor = player;
3647
3648 top_object = #largest_object-255;
3649 selfobj.capacity = MAX_CARRIED;
3650 #ifdef LanguageInitialise;
3651 LanguageInitialise();
3652 #endif;
3653 new_line;
3654 j=Initialise();
3655 last_score = score;
3656 move player to location;
3657 while (parent(location)~=0) location=parent(location);
3658 real_location = location;
3659 objectloop (i in player) give i moved ~concealed;
3660
3661 if (j~=2) Banner();
3662
3663 MoveFloatingObjects();
3664 lightflag=OffersLight(parent(player));
3665 if (lightflag==0) { real_location=location; location=thedark; }
3666 <Look>;
3667
3668 for (i=1:i<=100:i++) j=random(i);
3669
3670 #ifdef EnglishNaturalLanguage;
3671 old_itobj = itobj; old_himobj = himobj; old_herobj = herobj;
3672 #endif;
3673
3674 while (~~deadflag)
3675 {
3676 #ifdef EnglishNaturalLanguage;
3677 PronounOldEnglish();
3678 old_itobj = PronounValue('it');
3679 old_himobj = PronounValue('him');
3680 old_herobj = PronounValue('her');
3681 #endif;
3682
3683 .very__late__error;
3684
3685 if (score ~= last_score)
3686 { if (notify_mode==1) NotifyTheScore(); last_score=score; }
3687
3688 .late__error;
3689
3690 inputobjs-->0 = 0; inputobjs-->1 = 0;
3691 inputobjs-->2 = 0; inputobjs-->3 = 0; meta=false;
3692
3693 ! The Parser writes its results into inputobjs and meta,
3694 ! a flag indicating a "meta-verb". This can only be set for
3695 ! commands by the player, not for orders to others.
3696
3697 InformParser.parse_input(inputobjs);
3698
3699 action=inputobjs-->0;
3700
3701 ! --------------------------------------------------------------
3702
3703 ! Reverse "give fred biscuit" into "give biscuit to fred"
3704
3705 if (action==##GiveR or ##ShowR)
3706 { i=inputobjs-->2; inputobjs-->2=inputobjs-->3; inputobjs-->3=i;
3707 if (action==##GiveR) action=##Give; else action=##Show;
3708 }
3709
3710 ! Convert "P, tell me about X" to "ask P about X"
3711
3712 if (action==##Tell && inputobjs-->2==player && actor~=player)
3713 { inputobjs-->2=actor; actor=player; action=##Ask;
3714 }
3715
3716 ! Convert "ask P for X" to "P, give X to me"
3717
3718 if (action==##AskFor && inputobjs-->2~=player && actor==player)
3719 { actor=inputobjs-->2; inputobjs-->2=inputobjs-->3;
3720 inputobjs-->3=player; action=##Give;
3721 }
3722
3723 ! For old, obsolete code: special_word contains the topic word
3724 ! in conversation
3725
3726 if (action==##Ask or ##Tell or ##Answer)
3727 special_word = special_number1;
3728
3729 ! --------------------------------------------------------------
3730
3731 multiflag=false; onotheld_mode=notheld_mode; notheld_mode=false;
3732 ! For implicit taking and multiple object detection
3733
3734 .begin__action;
3735 inp1 = 0; inp2 = 0; i=inputobjs-->1;
3736 if (i>=1) inp1=inputobjs-->2;
3737 if (i>=2) inp2=inputobjs-->3;
3738
3739 ! inp1 and inp2 hold: object numbers, or 0 for "multiple object",
3740 ! or 1 for "a number or dictionary address"
3741
3742 if (inp1 == 1) noun = special_number1; else noun = inp1;
3743 if (inp2 == 1)
3744 { if (inp1 == 1) second = special_number2;
3745 else second = special_number1;
3746 } else second = inp2;
3747
3748 ! --------------------------------------------------------------
3749
3750 if (actor~=player)
3751 {
3752 ! The player's "orders" property can refuse to allow conversation
3753 ! here, by returning true. If not, the order is sent to the
3754 ! other person's "orders" property. If that also returns false,
3755 ! then: if it was a misunderstood command anyway, it is converted
3756 ! to an Answer action (thus "floyd, grrr" ends up as
3757 ! "say grrr to floyd"). If it was a good command, it is finally
3758 ! offered to the Order: part of the other person's "life"
3759 ! property, the old-fashioned way of dealing with conversation.
3760
3761 j=RunRoutines(player,orders);
3762 if (j==0)
3763 { j=RunRoutines(actor,orders);
3764 if (j==0)
3765 { if (action==##NotUnderstood)
3766 { inputobjs-->3=actor; actor=player; action=##Answer;
3767 jump begin__action;
3768 }
3769 if (RunLife(actor,##Order)==0) L__M(##Order,1,actor);
3770 }
3771 }
3772 jump turn__end;
3773 }
3774
3775 ! --------------------------------------------------------------
3776 ! Generate the action...
3777
3778 if ((i==0)
3779 || (i==1 && inp1 ~= 0)
3780 || (i==2 && inp1 ~= 0 && inp2 ~= 0))
3781 { self.begin_action(action, noun, second, 0);
3782 jump turn__end;
3783 }
3784
3785 ! ...unless a multiple object must be substituted. First:
3786 ! (a) check the multiple list isn't empty;
3787 ! (b) warn the player if it has been cut short because too long;
3788 ! (c) generate a sequence of actions from the list
3789 ! (stopping in the event of death or movement away).
3790
3791 multiflag = true;
3792 j=multiple_object-->0;
3793 if (j==0) { L__M(##Miscellany,2); jump late__error; }
3794 if (toomany_flag)
3795 { toomany_flag = false; L__M(##Miscellany,1); }
3796 i=location;
3797 for (k=1:k<=j:k++)
3798 { if (deadflag) break;
3799 if (location ~= i)
3800 { L__M(##Miscellany, 51);
3801 break;
3802 }
3803 l = multiple_object-->k;
3804 PronounNotice(l);
3805 print (name) l, ": ";
3806 if (inp1 == 0)
3807 { inp1 = l; self.begin_action(action, l, second, 0); inp1 = 0;
3808 }
3809 else
3810 { inp2 = l; self.begin_action(action, noun, l, 0); inp2 = 0;
3811 }
3812 }
3813
3814 ! --------------------------------------------------------------
3815
3816 .turn__end;
3817
3818 ! No time passes if either (i) the verb was meta, or
3819 ! (ii) we've only had the implicit take before the "real"
3820 ! action to follow.
3821
3822 if (notheld_mode==1) { NoteObjectAcquisitions(); continue; }
3823 if (meta) continue;
3824 if (~~deadflag) self.end_turn_sequence();
3825 }
3826
3827 if (deadflag~=2) AfterLife();
3828 if (deadflag==0) jump very__late__error;
3829
3830 print "^^ ";
3831 #IFV5; style bold; #ENDIF;
3832 print "***";
3833 if (deadflag==1) L__M(##Miscellany,3);
3834 if (deadflag==2) L__M(##Miscellany,4);
3835 if (deadflag>2) { print " "; DeathMessage(); print " "; }
3836 print "***";
3837 #IFV5; style roman; #ENDIF;
3838 print "^^^";
3839 ScoreSub();
3840 DisplayStatus();
3841 AfterGameOver();
3842 ],
3843
3844 end_turn_sequence
3845 [ i j;
3846
3847 turns++;
3848 if (the_time~=NULL)
3849 { if (time_rate>=0) the_time=the_time+time_rate;
3850 else
3851 { time_step--;
3852 if (time_step==0)
3853 { the_time++;
3854 time_step = -time_rate;
3855 }
3856 }
3857 the_time=the_time % 1440;
3858 }
3859
3860 #IFDEF DEBUG;
3861 if (debug_flag & 4 ~= 0)
3862 { for (i=0: i<active_timers: i++)
3863 { j=the_timers-->i;
3864 if (j~=0)
3865 { print (name) (j&$7fff), ": ";
3866 if (j & $8000) print "daemon";
3867 else
3868 { print "timer with ",
3869 j.time_left, " turns to go"; }
3870 new_line;
3871 }
3872 }
3873 }
3874 #ENDIF;
3875
3876 for (i=0: i<active_timers: i++)
3877 { if (deadflag) return;
3878 j=the_timers-->i;
3879 if (j~=0)
3880 { if (j & $8000) RunRoutines(j&$7fff,daemon);
3881 else
3882 { if (j.time_left==0)
3883 { StopTimer(j);
3884 RunRoutines(j,time_out);
3885 }
3886 else
3887 j.time_left=j.time_left-1;
3888 }
3889 }
3890 }
3891 if (deadflag) return;
3892
3893 scope_reason=EACH_TURN_REASON; verb_word=0;
3894 DoScopeAction(location);
3895 SearchScope(ScopeCeiling(player), player, 0);
3896 scope_reason=PARSING_REASON;
3897
3898 if (deadflag) return;
3899
3900 TimePasses();
3901
3902 if (deadflag) return;
3903
3904 AdjustLight();
3905
3906 if (deadflag) return;
3907
3908 NoteObjectAcquisitions();
3909 ],
3910
3911 begin_action
3912 [ a n s source sa sn ss;
3913 sa = action; sn = noun; ss = second;
3914 action = a; noun = n; second = s;
3915 #IFDEF DEBUG;
3916 if (debug_flag & 2 ~= 0) TraceAction(source);
3917 #IFNOT;
3918 source = 0;
3919 #ENDIF;
3920 #IFTRUE Grammar__Version == 1;
3921 if ((meta || BeforeRoutines()==false) && action<256)
3922 ActionPrimitive();
3923 #IFNOT;
3924 if ((meta || BeforeRoutines()==false) && action<4096)
3925 ActionPrimitive();
3926 #ENDIF;
3927 action = sa; noun = sn; second = ss;
3928 ],
3929 has proper;
3930
3931 [ ActionPrimitive;
3932 indirect(#actions_table-->action);
3933 ];
Last updated 27 February 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.