Difference between revisions of "HasRequirements"

From King Arthur's Gold Wiki
Jump to: navigation, search
 
(3 intermediate revisions by the same user not shown)
Line 6: Line 6:
  
 
This is primarily for use in conjunction with other requirement-handling methods.
 
This is primarily for use in conjunction with other requirement-handling methods.
You'll likely more often use the HasRequirements method on a [[CInventory]] object, 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.
+
You'll likely more often use the [[CInventory]]::[[CInventory::hasRequirements|hasRequirements]] method instead, but this version of the function allows two inventories to be checked at once. However, if you pass a null reference into 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 inventory1 & inventory2 parameters are both [[CInventory]] objects that will be checked to see if they contain the given requirements.

Latest revision as of 21:07, 19 August 2012

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