Advertisement
RyanCordell

InvAmount expression

Feb 2nd, 2016
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.24 KB | None | 0 0
  1. //==========================================================================
  2. //
  3. // Function: InvAmount
  4. //
  5. //==========================================================================
  6.  
  7. class FxGlobalFunctionCall_InvAmount : public FxGlobalFunctionCall
  8. {
  9. public:
  10.     GLOBALFUNCTION_DEFINE(InvAmount);
  11.  
  12.     FxExpression *Resolve(FCompileContext& ctx)
  13.     {
  14.         CHECKRESOLVED();
  15.  
  16.         if (!ResolveArgs(ctx, 1, 1, false))
  17.             return NULL;
  18.  
  19.         switch ((*ArgList)[0]->ValueType.Type)
  20.         {
  21.         case VAL_Class: case VAL_Name:break;
  22.         default:
  23.             ScriptPosition.Message(MSG_ERROR, "actor class expected for parameter");
  24.             delete this;
  25.             return NULL;
  26.         }
  27.  
  28.         ValueType = VAL_Float;
  29.         return this;
  30.     }
  31.  
  32.     ExpVal EvalExpression(AActor *self)
  33.     {
  34.         ExpVal ret;
  35.         ret.Type = VAL_Int;
  36.         ExpVal v = (*ArgList)[0]->EvalExpression(self);
  37.         const PClass  * invclass;
  38.         {
  39.             invclass = v.GetClass();
  40.             if (!invclass)
  41.             {
  42.                 invclass = PClass::FindClass(v.GetName());
  43.                 if (!invclass){ ret.Int = -1; return ret; }
  44.             }
  45.         }
  46.         AInventory *item = self->FindInventory(invclass);
  47.         int pick_pointer = AAPTR_DEFAULT;
  48.  
  49.         self = COPY_AAPTR(self, pick_pointer);
  50.         ret.Int = (item == NULL) ? -1 : item->Amount;
  51.         return ret;
  52.     }
  53. };
  54.  
  55. GLOBALFUNCTION_ADDER(InvAmount);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement