ReadRequirement

From King Arthur's Gold Wiki
Revision as of 19:11, 18 August 2012 by Shadlington (Talk | contribs)

Jump to: navigation, search

Reads requirements from the given CBitStream into variables you provide.


This is primarily for use in conjunction with other requirement-handling methods. It can be used to check the requirements set by AddRequirement.

The first parameter is the CBitStream you're reading the requirements from. The requirement string is the type of requirement - the standard ones are "blob", "tech", "coin", "shop" and "time", though you can define your own. The blobName string is the name of the blob that is required, if the requirement is for a kind of blob - it will be blank ("") if it is not a kind of blob, for example if it is time. The friendlyName string is what should be displayed to the player as text.

void ReadRequirement( CBitStream@ bs, std::string &requirement, std::string &blobName, std::string &friendlyName, u16 &quantity)

Example from Entities/Workshops/Scripts/WorkshopCommon.as:

void SetButtonRequirementsText( CGridButton @button, CBitStream@ bs, bool missing )
{
  string text, requiredType, name, friendlyName;
  u16 quantity = 0;					
  while (!bs.isBufferEnd())
  {
    ReadRequirement( bs, requiredType, name, friendlyName, quantity );
 
    string quantityColor;
    if (missing)
      quantityColor = "$RED$";
    else
      quantityColor = "$GREEN$";
 
    if (requiredType == "blob")
    {
      text += quantityColor;
      text += quantity;
      text += quantityColor;
      text += " $"; text += name; text += "$";
      text += " ";
      text += quantityColor;
      text += friendlyName;
      text += quantityColor;
      text += " required.\n\n";
    }
    else if (requiredType == "tech")
    {
      text += " $"; text += name; text += "$ ";
      text += quantityColor;
      text += friendlyName;
      text += quantityColor;
      text += " technology required.\n\n";									
    }
    else if (requiredType == "coin")
    {
      text += quantity;					
      text += " $coin$ required\n\n";
    }
    else if (requiredType == "shop")
    {
    }
    else
    if (requiredType == "time")
    {
      text += "$TIME$ ";
      text += friendlyName;
      text += " ";
      text += quantityColor;
      text += quantity;
      text += quantityColor;
      text += "\n\n";
    }
  }
button.SetHoverText( text );
}