Difference between revisions of "AddRequirement"
Shadlington (Talk | contribs) |
Shadlington (Talk | contribs) |
||
Line 20: | Line 20: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Example from Entities/Workshops/Scripts/ | + | Example from Entities/Workshops/Scripts/WAR_Workshops.as: |
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
− | + | Workshop @w = addWorkshop( this, "Bank", "$Bank$", "Entities/Workshops/Bank.cfg" ); | |
− | + | AddRequirement( w.requirements, "blob", "mat_wood", "Wood", 40 ); | |
− | + | AddRequirement( w.requirements, "blob", "mat_stone", "Stone", 40 ); | |
− | + | ||
− | + | ||
− | + | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | Example from Entities/ | + | Example from Entities/Characters/Scripts/BuilderInventory.as: |
<syntaxhighlight lang="cpp"> | <syntaxhighlight lang="cpp"> | ||
case Builder::make_workshop: | case Builder::make_workshop: |
Revision as of 18:58, 18 August 2012
Pushes the given requirements to a CBitStream, to be read by other requirement methods.
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.
The first parameter is the CBitStream you're adding the requirements to. 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 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 friendlyName string is what should be displayed to the player as text.
void AddRequirement( CBitStream@ bs, std::string &requirement, std::string &blobName, std::string &friendlyName, u16 &quantity)
Example from Entities/Workshops/Scripts/BankLogic.as:
WorkshopTask @wt = addWorkshopTask( this, "Deposit Money", "$stone_block_1x1$", 0, "genericblock", "Entities/Structures/Stone/Block1x1.cfg" ); AddRequirement( wt.requirements, "coin", "$coin$", "Money", 10 );
Example from Entities/Workshops/Scripts/WAR_Workshops.as:
Workshop @w = addWorkshop( this, "Bank", "$Bank$", "Entities/Workshops/Bank.cfg" ); AddRequirement( w.requirements, "blob", "mat_wood", "Wood", 40 ); AddRequirement( w.requirements, "blob", "mat_stone", "Stone", 40 );
Example from Entities/Characters/Scripts/BuilderInventory.as:
case Builder::make_workshop: { CBitStream reqs, missing; AddRequirement( reqs, "blob", "mat_stone", "Stones", 10 ); if (this.hasRequirements( reqs, missing )) { this.TakeRequirements( reqs ); CBlob @shopBlob = CreateBlob( "genericblock", "Entities/Workshops/Base/WorkshopWAR.cfg", 0, this.getBlob().getPosition() ); this.getBlob().Pickup( shopBlob, false ); } else { print("doesn't meet requirements"); } }