TakeRequirementsCombined

From King Arthur's Gold Wiki
Jump to: navigation, search

Removes the requirements in the given CBitStream from one of the CInventorys passed to it.


This is primarily for use in conjunction with other requirement-handling methods. You'll likely more often use the CInventory::TakeRequirements method instead, but this version of the function allows two inventories to be checked at once. It will only take the requirements from one of them, with preference given to the first inventory. However, it looks at each of the requirements individually, so its possible that some requirements will be taken from the first inventory and some from the second, depending on which inventory has each requirement. You can pass NULL instead of the second inventory parameter to only remove the requirements from one inventory.

The requirements will only be removed if they exist in the inventory to begin with.

If the requirement's type was a blob and the quantity was 0, then all blobs of that type will be removed from the inventory they are removed from.

The inventory1 & inventory2 parameters are both CInventory, one of which will have the requirements removed from it if they contain the given requirements. The requirements parameter is the CBitStream you're reading the requirements from.

void TakeRequirementsCombined( CInventory@ inventory1, CInventory@ inventory2, CBitStream@ requirements )

Example from Entities/Workshops/Scripts/WorkshopEmpty.as:

if (cmd > WorkshopCmd::convert && cmd <= WorkshopCmd::convert + workshopCount)
{
  CBlob@ caller = getBlobByNetworkId( params.read_u16() );
  string configFilename = params.read_string();
 
  // take requirements/resources
  Workshop @w = cast<Workshop@>(this.getProperties().getScriptObject( "workshops", cmd - WorkshopCmd::convert_workshop));
  if (w !is null)
  {
    TakeRequirementsCombined( this.getInventory(), caller.getInventory(), w.requirements );    CBlob @shopBlob = CreateBlob( "genericblock", configFilename, this.getTeamNum(), this.getPosition()+Vec2f(0,8) );
    this.health = -1.0f;
    this.Die();
  }
}