AddRequirement

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

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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