Inform - Support - Source

Back to List

Inventory
Complete

Backward
Forward

Plain
Coloured
Gaudy

This code
in plain text

Browsing parserm.h

AdvanceWorldClock (lines 4465-4784)

4465  !  End of the parser proper: the remaining routines are its front end.
4466  ! ----------------------------------------------------------------------------
4467   
4468  Object  InformLibrary "(Inform Library)"
4469    with  play [ i j k l;
4470   
4471              #Ifdef TARGET_ZCODE;
4472              standard_interpreter = HDR_TERPSTANDARD-->0;
4473              transcript_mode = ((HDR_GAMEFLAGS-->0) & 1);
4474              sys_statusline_flag = ( (HDR_TERPFLAGS->0) & 2 ) / 2;
4475              #Ifnot; ! TARGET_GLULX
4476              GGInitialise();
4477              #Endif; ! TARGET_
4478   
4479              ChangeDefault(cant_go, CANTGO__TX);
4480   
4481              #Ifdef TARGET_ZCODE;
4482              dict_start = HDR_DICTIONARY-->0;
4483              dict_entry_size = dict_start->(dict_start->0 + 1);
4484              dict_start = dict_start + dict_start->0 + 4;
4485              dict_end = dict_start + (dict_start - 2)-->0 * dict_entry_size;
4486              #Ifdef DEBUG;
4487              if (dict_start > 0 && dict_end < 0 &&
4488                ((-dict_start) - dict_end) % dict_entry_size == 0)
4489                  print "** Warning: grammar properties might not work correctly **^";
4490              #Endif; ! DEBUG
4491   
4492              buffer->0  = INPUT_BUFFER_LEN;
4493              buffer2->0 = INPUT_BUFFER_LEN;
4494              buffer3->0 = INPUT_BUFFER_LEN;
4495              parse->0   = 15;
4496              parse2->0  = 15;
4497              #Endif; ! TARGET_ZCODE
4498   
4499              real_location = thedark;
4500              player = selfobj; actor = player;
4501   
4502              #Ifdef TARGET_ZCODE;
4503              top_object = #largest_object-255;
4504              #Endif; ! TARGET_ZCODE
4505              selfobj.capacity = MAX_CARRIED; ! ### change?
4506   
4507              #Ifdef LanguageInitialise;
4508              LanguageInitialise();
4509              #Endif; ! LanguageInitialise
4510   
4511              new_line;
4512              LibraryExtensions.RunAll(ext_initialise);
4513              j = Initialise();
4514              last_score = score;
4515              move player to location;
4516   
4517              while (parent(location) ~= 0) location = parent(location);
4518              real_location = location;
4519   
4520              actor = player; ! resync, because player may have been changed in initialise()
4521              actors_location = location;
4522   
4523              objectloop (i in player) give i moved ~concealed;
4524   
4525              if (j ~= 2) Banner();
4526   
4527              MoveFloatingObjects();
4528              lightflag = OffersLight(parent(player));
4529              if (lightflag == 0) {
4530                  real_location = location;
4531                  location = thedark;
4532              }
4533              <Look>;
4534   
4535              for (i=1 : i<=100 : i++) j = random(i);
4536   
4537              #Ifdef EnglishNaturalLanguage;
4538              old_itobj = itobj; old_himobj = himobj; old_herobj = herobj;
4539              #Endif;! EnglishNaturalLanguage
4540   
4541              while (~~deadflag) {    ! everything happens in this loop
4542   
4543                  #Ifdef EnglishNaturalLanguage;
4544                  PronounOldEnglish();
4545                  old_itobj = PronounValue('it');
4546                  old_himobj = PronounValue('him');
4547                  old_herobj = PronounValue('her');
4548                  #Endif; ! EnglishNaturalLanguage
4549   
4550                .very__late__error;
4551   
4552                  if (score ~= last_score) {
4553                      if (notify_mode == 1) NotifyTheScore();
4554                      last_score = score;
4555                  }
4556   
4557                .late__error;
4558   
4559                  inputobjs-->0 = 0; inputobjs-->1 = 0;
4560                  inputobjs-->2 = 0; inputobjs-->3 = 0; meta=false;
4561   
4562                  ! The Parser writes its results into inputobjs and meta,
4563                  ! a flag indicating a "meta-verb".  This can only be set for
4564                  ! commands by the player, not for orders to others.
4565   
4566                  InformParser.parse_input(inputobjs);
4567   
4568                  action = inputobjs-->0;
4569   
4570                  ! --------------------------------------------------------------
4571   
4572                  ! Reverse "give fred biscuit" into "give biscuit to fred"
4573   
4574                  if (action == ##GiveR or ##ShowR) {
4575                      i = inputobjs-->2; inputobjs-->2 = inputobjs-->3; inputobjs-->3 = i;
4576                      if (action == ##GiveR) action = ##Give; else action = ##Show;
4577                  }
4578   
4579                  ! Convert "P, tell me about X" to "ask P about X"
4580   
4581                  if (action == ##Tell && inputobjs-->2 == player && actor ~= player) {
4582                      inputobjs-->2 = actor; actor = player; action = ##Ask;
4583                  }
4584   
4585                  ! Convert "ask P for X" to "P, give X to me"
4586   
4587                  if (action == ##AskFor && inputobjs-->2 ~= player && actor == player) {
4588                      actor = inputobjs-->2; inputobjs-->2 = inputobjs-->3;
4589                      inputobjs-->3 = player; action = ##Give;
4590                  }
4591   
4592                  ! For old, obsolete code: special_word contains the topic word
4593                  ! in conversation
4594   
4595                  if (action == ##Ask or ##Tell or ##Answer)
4596                      special_word = special_number1;
4597   
4598                  !  --------------------------------------------------------------
4599   
4600                  multiflag = false; onotheld_mode = notheld_mode; notheld_mode = false;
4601                  ! For implicit taking and multiple object detection
4602   
4603                .begin__action;
4604                  inp1 = 0; inp2 = 0; i = inputobjs-->1;
4605                  if (i >= 1) inp1 = inputobjs-->2;
4606                  if (i >= 2) inp2 = inputobjs-->3;
4607   
4608                  ! inp1 and inp2 hold: object numbers, or 0 for "multiple object",
4609                  ! or 1 for "a number or dictionary address"
4610   
4611                  if (inp1 == 1) noun = special_number1; else noun = inp1;
4612                  if (inp2 == 1) {
4613                      if (inp1 == 1) second = special_number2;
4614                      else           second = special_number1;
4615                  }
4616                  else second = inp2;
4617   
4618                  !  --------------------------------------------------------------
4619   
4620                  if (actor ~= player) {
4621   
4622                  ! The player's "orders" property can refuse to allow conversation
4623                  ! here, by returning true.  If not, the order is sent to the
4624                  ! other person's "orders" property.  If that also returns false,
4625                  ! then: if it was a misunderstood command anyway, it is converted
4626                  ! to an Answer action (thus "floyd, grrr" ends up as
4627                  ! "say grrr to floyd").  If it was a good command, it is finally
4628                  ! offered to the Order: part of the other person's "life"
4629                  ! property, the old-fashioned way of dealing with conversation.
4630   
4631                      j = RunRoutines(player, orders);
4632                      if (j == 0) {
4633                          j = RunRoutines(actor, orders);
4634                          if (j == 0) {
4635                              if (action == ##NotUnderstood) {
4636                                  inputobjs-->3 = actor; actor = player; action = ##Answer;
4637                                  jump begin__action;
4638                              }
4639                              if (RunLife(actor, ##Order) == 0) L__M(##Order, 1, actor);
4640                          }
4641                      }
4642                      jump turn__end;
4643                  }
4644   
4645                  ! --------------------------------------------------------------
4646                  ! Generate the action...
4647   
4648                  if ((i == 0) ||
4649                      (i == 1 && inp1 ~= 0) ||
4650                      (i == 2 && inp1 ~= 0 && inp2 ~= 0)) {
4651                      self.begin_action(action, noun, second, 0);
4652                      jump turn__end;
4653                  }
4654   
4655                  ! ...unless a multiple object must be substituted.  First:
4656                  ! (a) check the multiple list isn't empty;
4657                  ! (b) warn the player if it has been cut short because too long;
4658                  ! (c) generate a sequence of actions from the list
4659                  !     (stopping in the event of death or movement away).
4660   
4661                  multiflag = true;
4662                  j = multiple_object-->0;
4663                  if (j == 0) {
4664                      L__M(##Miscellany, 2);
4665                      jump late__error;
4666                  }
4667                  if (toomany_flag) {
4668                      toomany_flag = false;
4669                      L__M(##Miscellany, 1);
4670                  }
4671                  i = location;
4672                  for (k=1 : k<=j : k++) {
4673                      if (deadflag) break;
4674                      if (location ~= i) {
4675                          L__M(##Miscellany, 51);
4676                          break;
4677                      }
4678                      l = multiple_object-->k;
4679                      PronounNotice(l);
4680                      print (name) l, ": ";
4681                      if (inp1 == 0) {
4682                          inp1 = l; self.begin_action(action, l, second, 0); inp1 = 0;
4683                      }
4684                      else {
4685                          inp2 = l; self.begin_action(action, noun, l, 0); inp2 = 0;
4686                      }
4687                  }
4688   
4689                  ! --------------------------------------------------------------
4690   
4691                .turn__end;
4692   
4693                  ! No time passes if either (i) the verb was meta, or
4694                  ! (ii) we've only had the implicit take before the "real"
4695                  ! action to follow.
4696   
4697                  if (notheld_mode == 1) { NoteObjectAcquisitions(); continue; }
4698                  if (meta) continue;
4699                  if (~~deadflag) self.end_turn_sequence();
4700                  else if (START_MOVE ~= 1) turns++;
4701   
4702              } ! end of while()
4703   
4704              if (deadflag ~= 2) AfterLife();
4705              if (deadflag == 0) jump very__late__error;
4706   
4707              print "^^    ";
4708              #Ifdef TARGET_ZCODE;
4709              #IfV5; style bold; #Endif; ! V5
4710              #Ifnot; ! TARGET_GLULX
4711              glk($0086, 5); ! set alert style
4712              #Endif; ! TARGET_
4713              print "***";
4714              if (deadflag == 1) L__M(##Miscellany, 3);
4715              if (deadflag == 2) L__M(##Miscellany, 4);
4716              if (deadflag > 2)  {
4717                  print " ";
4718                  DeathMessage();
4719                  print " ";
4720              }
4721              print "***";
4722              #Ifdef TARGET_ZCODE;
4723              #IfV5; style roman; #Endif; ! V5
4724              #Ifnot; ! TARGET_GLULX
4725              glk($0086, 0); ! set normal style
4726              #Endif; ! TARGET_
4727              #Ifdef NO_SCORE;
4728              print "^^";
4729              #Ifnot;
4730              print "^^^";
4731              #Endif; ! NO_SCORE
4732              ScoreSub();
4733              DisplayStatus();
4734              AfterGameOver();
4735   
4736          ], ! end of 'play' property
4737   
4738          end_turn_sequence [;
4739              AdvanceWorldClock();
4740              if (deadflag) return;
4741              RunTimersAndDaemons();
4742              if (deadflag) return;
4743              RunEachTurnProperties();
4744              if (deadflag) return;
4745              TimePasses();
4746              if (deadflag) return;
4747              AdjustLight();
4748              if (deadflag) return;
4749              NoteObjectAcquisitions();
4750          ],
4751   
4752          begin_action [ a n s source   sa sn ss;
4753              sa = action; sn = noun; ss = second;
4754              action = a; noun = n; second = s;
4755              #Ifdef DEBUG;
4756              if (debug_flag & 2 ~= 0) TraceAction(source);
4757              #Ifnot;
4758              source = 0;
4759              #Endif; ! DEBUG
4760              #Iftrue (Grammar__Version == 1);
4761              if ((meta || BeforeRoutines() == false) && action < 256)
4762                  ActionPrimitive();
4763              #Ifnot;
4764              if ((meta || BeforeRoutines() == false) && action < 4096)
4765                  ActionPrimitive();
4766              #Endif; ! Grammar__Version
4767              action = sa; noun = sn; second = ss;
4768          ],
4769    has   proper;
4770   
4771  [ AdvanceWorldClock;
4772      turns++;
4773      if (the_time ~= NULL) {
4774          if (time_rate >= 0) the_time=the_time+time_rate;
4775          else {
4776              time_step--;
4777              if (time_step == 0) {
4778                  the_time++;
4779                  time_step = -time_rate;
4780              }
4781          }
4782          the_time = the_time % 1440;
4783      }
4784  ];


Last updated 27 February 2004. The librarian in charge of this page is Graham Nelson (graham@gnelson.demon.co.uk) assisted by C Knight. Please email any comments, suggestions or corrections to cedenqs@inform-fiction.org.