Difference between revisions of "ReadRequirement"
Shadlington (Talk | contribs) (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...") |
Shadlington (Talk | contribs) |
||
(One intermediate revision by the same user not shown) | |||
Line 1: | Line 1: | ||
<onlyinclude> | <onlyinclude> | ||
− | + | 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 | + | 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 | + | The first parameter is the [[CBitStream]] you're reading the requirements from. |
− | The | + | 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 - | + | 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 | + | void ReadRequirement( CBitStream@ bs, std::string &requirement, std::string &blobName, std::string &friendlyName, u16 &quantity) |
</syntaxhighlight> | </syntaxhighlight> | ||
− | Example from Entities/ | + | 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 ); }