X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Fresources.qc;h=74a0c55788a71a2f19de6accaeaacba47f1c9c3b;hb=fc0889be210898f9a72b4e12ddf30e2ae5effa24;hp=0fb40cf6ec13dc52f098192cddb1d9a65651ee4f;hpb=20d1c69e0d40efffc5f53359c0fc78bee971c3a1;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/resources.qc b/qcsrc/server/resources.qc index 0fb40cf6e..74a0c5578 100644 --- a/qcsrc/server/resources.qc +++ b/qcsrc/server/resources.qc @@ -11,7 +11,7 @@ float GetResourceLimit(entity e, int resource_type) { if(!IS_PLAYER(e)) - return 0; // no limits on non-players + return RESOURCE_LIMIT_NONE; // no limits on non-players float limit; switch (resource_type) @@ -99,7 +99,7 @@ void SetResourceAmount(entity e, int resource_type, float amount) amount = M_ARGV(2, float); float max_amount = GetResourceLimit(e, resource_type); // TODO: should allow overriding these limits if cheats are enabled! float amount_wasted = 0; - if (amount > max_amount && max_amount) + if (amount > max_amount && max_amount != RESOURCE_LIMIT_NONE) { amount_wasted = amount - max_amount; amount = max_amount; @@ -182,7 +182,7 @@ void GiveResourceWithLimit(entity receiver, int resource_type, float amount, return; } float current_amount = GetResourceAmount(receiver, resource_type); - if (current_amount + amount > limit) + if (current_amount + amount > limit && limit != RESOURCE_LIMIT_NONE) { amount = limit - current_amount; } @@ -232,13 +232,38 @@ void TakeResourceWithLimit(entity receiver, int resource_type, float amount, return; } float current_amount = GetResourceAmount(receiver, resource_type); - if (current_amount - amount < limit) + if (current_amount - amount < -limit) { - amount = limit + current_amount; + amount = -limit + current_amount; } TakeResource(receiver, resource_type, amount); } +void GiveOrTakeResource(entity receiver, int resource_type, float amount) +{ + if(amount < 0) + { + TakeResource(receiver, resource_type, amount * -1); + } + else + { + GiveResource(receiver, resource_type, amount); + } +} + +void GiveOrTakeResourceWithLimit(entity receiver, int resource_type, float amount, + float limit) +{ + if(amount < 0) + { + TakeResourceWithLimit(receiver, resource_type, amount * -1, limit); + } + else + { + GiveResourceWithLimit(receiver, resource_type, amount, limit); + } +} + int GetResourceType(.float resource_field) { switch (resource_field)