CInventory::hasRequirements

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

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

Checks 1 or 2 inventories to see if they have the given requirements, and writes any missing requirements into a given CBitStream.

Returns true if the requirements are met, otherwise false.


This is primarily for use in conjunction with other requirement-handling methods. You'll likely more often use the CInventory::hasRequirements method instead, but this version of the function allows two inventories to be checked at once. However, if you pass a NULL reference for one of the inventory arguments it will only check one inventory.

The inventory1 & inventory2 parameters are both CInventory objects that will be checked to see if they contain the given requirements. The requirements parameter is the CBitStream you're reading the requirements from. The missing parameter is a CBitStream that any missing requirements will be written into.

bool hasRequirements( CInventory@ inventory1, CInventory@ inventory2, CBitStream@ requirements, CBitStream@ missing )

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

void AddWorkshopTasksButtons( CBlob@ this, CBlob@ caller, CGridMenu@ menu )
{
  int tasksCount = this.getProperties().getScriptObjectGroupSize( "tasks" );
  if (menu !is null)
  {
    for (int i = 0; i < tasksCount; i++)
    {
      WorkshopTask @wt = cast<WorkshopTask@>(this.getProperties().getScriptObject( "tasks", i));
 
      CBitStream bsMissing;
      CBitStream combinedReqs;
      if (hasRequirements( this.getInventory(), caller.getInventory(), wt.requirements, bsMissing ))      {
        CBitStream params;
        params.write_u16(caller.getNetworkID());
        CGridButton@ button = menu.AddButton( wt.iconName, wt.name, WshpTasks::make_task + i, params );						
        SetButtonRequirementsText( button, wt.requirements, false );	
      }		
      else
      {
        CGridButton@ button = menu.AddButton( "$NONE$", wt.name, WshpTasks::nil );
        SetButtonRequirementsText( button, bsMissing, true );	
      }
    }
  }
}


Object method of: CInventory