Difference between revisions of "ReadRequirement"

From King Arthur's Gold Wiki
Jump to: navigation, search
(Created page with "<onlyinclude> Pushes the given requirements to a CBitStream, to be read by other requirement methods. </onlyinclude> This is primarily for use in conjunction with other requ...")
 
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
 
<onlyinclude>
 
<onlyinclude>
Pushes the given requirements to a [[CBitStream]], to be read by other requirement methods.
+
Reads requirements from the given [[CBitStream]] into variables you provide.
 
</onlyinclude>
 
</onlyinclude>
  
This is primarily for use in conjunction with other requirement-handling methods. It will regularly be used with [[CInventory]] for checking whether a player has the required materials to do something. In addition, you will use it with things like workshops to set requirements for actions that can be performed at them.
+
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 adding the requirements to.
+
The first parameter is the [[CBitStream]] you're reading the requirements from.
The requirements string is the type of requirement - the standard ones are "blob", "tech", "coin", "shop" and "time", though you may be able to define your own.
+
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 - leave it blank ("") if it not a kind of blob, for example if it is time.
+
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.
 
The friendlyName string is what should be displayed to the player as text.
  
 
<syntaxhighlight lang="cpp">
 
<syntaxhighlight lang="cpp">
void AddRequirement( CBitStream@ bs, std::string &requirement, std::string &blobName, std::string &friendlyName, u16 &quantity)
+
void ReadRequirement( CBitStream@ bs, std::string &requirement, std::string &blobName, std::string &friendlyName, u16 &quantity)
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Example from Entities/Characters/Scripts/BuilderInventory.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 );
}