home *** CD-ROM | disk | FTP | other *** search
/ UnrealScript Game Programming All in One / UnrealScriptGameProgrammingAllInOne.iso / UGPAIOListings / UGPAIOListingsCh20 / CH20LIST / Classes / Actor.uc next >
Encoding:
Text File  |  2006-02-27  |  4.6 KB  |  160 lines

  1.  // %PARAMETERS = "CH20LIST C:\UT2004"
  2.  //Identifies the package
  3.  //Actor.uc
  4.  
  5.  //Class preconditions:
  6.  //This class depends on the Element class.
  7.  //The test driver for this class is CH20_04LIST
  8.  
  9.  class Actor extends Commandlet;
  10.  
  11.  //#1 Class attributes
  12.  struct sInterpretation{
  13.     var string szDirection;
  14.     var string szActorReading;
  15.     var int iActorVersion;
  16.  };
  17.  
  18.  var private int iLen;
  19.  var private string szName;
  20.  var private Vector vPosition;
  21.  var private string szCurrentSpeech;
  22.  var private string szInterpretation;
  23.  var private string szAppearance;
  24.  var private string szPropUse;
  25.  var private Array<sInterpretation> rgInterpretations;
  26.  
  27.  //#2
  28.  //-------------------setCurrentSpeech----------------------
  29.  //Unchanged from Element or script
  30.  public function setCurrentSpeech(string speechFromEle){
  31.         szCurrentSpeech = speechFromEle;
  32.  }
  33.  
  34.  //#3
  35.  //---------------performCurrentSpeech-----------------------
  36.  public function performCurrentSpeech(){
  37.      Log("   " $ Caps(szName) $ ":  " );
  38.      Log("  [" $ szInterpretation $ "] ");
  39.      Log("  [" $ szPropUse $ "] ");
  40.      Log("   " $ szCurrentSpeech );
  41.  }
  42.  
  43.  //#4
  44.  //--------------------getName------------------------------
  45.  //Name of character
  46.  public function string getName(){
  47.      return szName;
  48.  }
  49.  
  50. //------------------setName--------------------------------
  51.  //Name of character
  52.  public function setName(string nameOfActor){
  53.      szName =  nameOfActor;
  54.  }
  55.  
  56.  //#5
  57.  //-------------------moveTo--------------------------------
  58.  //Move character to vector coordinates
  59.  public function moveTo(Vector posOfActor){
  60.      vPosition = posOfActor;
  61.  }
  62.  
  63.  //#6
  64.  //---------------setPropUse------------------------------
  65.  //Add instructions on how to use a prop, if it is
  66.  //something in hand
  67.  public function setPropUse(string actorUseOf){
  68.     szPropUse = actorUseOf;
  69.   }
  70.  
  71.  //---------------getPropUse------------------------------
  72.  public function string getPropUse(){
  73.     return szPropUse;
  74.  }
  75.  
  76.  //#7
  77.  //-------------------setAppearance------------------------
  78.  //Describe character's appearance
  79.  public function setAppearance(string appOfActor){
  80.       szAppearance = appOfActor;
  81.  }
  82.  
  83.  //-------------------getAppearance------------------------
  84.  //Character's appearance
  85.  public function string getAppearance(){
  86.     return szAppearance;
  87.  }
  88.  
  89.  //#8
  90.  //------------------addInterpretation-----------------------
  91.  //Given a direction from the Element (or director)
  92.  //create a corresponding interpretation for character (Actor)
  93.  //can use when delivering a speech
  94.  public function addInterpretation(string dirFromEle,
  95.                                    string interByActor,
  96.                                    optional int actVer ){
  97.      local sInterpretation locInterp;
  98.  
  99.      locInterp.szDirection = dirFromEle;
  100.      locInterp.szActorReading = interByActor;
  101.  
  102.      if(actVer <= 0){
  103.          actVer = 0;
  104.      }
  105.      locInterp.iActorVersion = actVer;
  106.      
  107.      //Test for the validity of data
  108.      if(Len(dirFromEle) != 0){
  109.        //insert at end of array
  110.        iLen = rgInterpretations.Length;
  111.        rgInterpretations.Insert(iLen, 1);
  112.  
  113.        //insert the new direction-interpretation element
  114.        iLen = rgInterpretations.Length;
  115.        rgInterpretations[iLen] = locInterp;
  116.  
  117.        }else{
  118.           Log("   Must provide text for direction.");
  119.        }
  120.  }
  121.  
  122.  //#9
  123.  //---------------------getInterpretation--------------------
  124.  //Given a direction from the Element (or director)
  125.  //get the Actor's interpretation of it, if it exists
  126.  //Otherwise, use the direction from the Element
  127.  //Precondition: You must first set the interpretation
  128.  
  129.  public function string getInterpretation(string dirFromEle, 
  130.                                           optional int actVer){
  131.     local int iCtr;
  132.     local bool fFlag;
  133.     fFlag = false;
  134.     iLen = rgInterpretations.Length;
  135.     iCtr = 0;
  136.     if(actVer <= 0){ 
  137.         actVer = 0;
  138.     }
  139.  
  140.     while(iCtr < iLen){
  141.        if(dirFromEle == rgInterpretations[iCtr].szDirection && 
  142.           actVer == rgInterpretations[iCtr].iActorVersion                                                      ){
  143.           fFlag = true;
  144.          //Assign the corresponding interpretation by the
  145.          //character to the current interpretation
  146.          szInterpretation = rgInterpretations[iCtr].szActorReading;
  147.          break;
  148.        }//end if
  149.        iCtr++;
  150.      }//end while
  151.  
  152.      //If no instance of the translation has been found
  153.      //Then use the director's instructions
  154.      if(fFlag == false){
  155.         szInterpretation =  "  Actor has no interpretation of " $ dirFromEle;
  156.      }
  157.      return szInterpretation;
  158.  }
  159.  
  160.