Difference between revisions of "ReadRequirement"

From King Arthur's Gold Wiki
Jump to: navigation, search
 
Line 16: Line 16:
  
 
Example from Entities/Workshops/Scripts/WorkshopCommon.as:
 
Example from Entities/Workshops/Scripts/WorkshopCommon.as:
<syntaxhighlight lang="cpp">
+
<syntaxhighlight lang="cpp" highlight="7">
 
void SetButtonRequirementsText( CGridButton @button, CBitStream@ bs, bool missing )
 
void SetButtonRequirementsText( CGridButton @button, CBitStream@ bs, bool missing )
 
{
 
{

Latest revision as of 20:40, 18 August 2012

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 );
}