From: terencehill Date: Sun, 12 Apr 2020 16:06:49 +0000 (+0200) Subject: Save a GetResource call in GiveResourceValue X-Git-Tag: xonotic-v0.8.5~1121^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=fc3a0c6b081e6f273dad91ef12ce47ab5712bb23;p=xonotic%2Fxonotic-data.pk3dir.git Save a GetResource call in GiveResourceValue --- diff --git a/qcsrc/common/t_items.qc b/qcsrc/common/t_items.qc index bd7885d41..a05f90f9e 100644 --- a/qcsrc/common/t_items.qc +++ b/qcsrc/common/t_items.qc @@ -1667,17 +1667,19 @@ void GiveRot(entity e, float v0, float v1, .float rotfield, float rottime, .floa bool GiveResourceValue(entity e, int res_type, int op, int val) { int v0 = GetResource(e, res_type); + float new_val = 0; switch (op) { // min 100 cells = at least 100 cells - case OP_SET: SetResource(e, res_type, val); break; - case OP_MIN: SetResource(e, res_type, max(v0, val)); break; - case OP_MAX: SetResource(e, res_type, min(v0, val)); break; - case OP_PLUS: SetResource(e, res_type, v0 + val); break; - case OP_MINUS: SetResource(e, res_type, v0 - val); break; - } - int v1 = GetResource(e, res_type); - return v0 != v1; + case OP_SET: new_val = val; break; + case OP_MIN: new_val = max(v0, val); break; + case OP_MAX: new_val = min(v0, val); break; + case OP_PLUS: new_val = v0 + val; break; + case OP_MINUS: new_val = v0 - val; break; + default: return false; + } + + return SetResourceExplicit(e, res_type, new_val); } float GiveItems(entity e, float beginarg, float endarg)