Turn MaxContentsCount and HandObjects into properties instead of callbacks (Possibly fixes #1553)

shapetextures
Sven Eberhardt 2016-01-10 10:41:34 -05:00
parent c569036d1d
commit 3dad1c6d81
17 changed files with 42 additions and 76 deletions

View File

@ -202,9 +202,8 @@ func LaunchEnemy(proplist enemy, int xmin, int xrange, int y)
obj.JumpSpeed = obj.JumpSpeed * enemy.Speed / 100;
obj.FlySpeed = obj.FlySpeed * enemy.Speed / 100;
}
obj.MaxContentsCount = CustomAI.Clonk_MaxContentsCount;
obj.MaxContentsCount = 1;
obj->MakeInvincibleToFriendlyFire();
obj.MaxContentsCountVal = 1;
// Reward for killing enemy
obj.Bounty = enemy.Bounty;
// Vehicles
@ -267,6 +266,4 @@ func LaunchEnemy(proplist enemy, int xmin, int xrange, int y)
//
global func ForceVal2Array(v) { if (GetType(v) != C4V_Array) return [v]; else return v; }
// forward max contents count to property
func Clonk_MaxContentsCount() { return this.MaxContentsCountVal; }

View File

@ -103,8 +103,7 @@ func JoinPlayer(plr, prev_clonk)
clonk->DoEnergy(1000);
clonk->MakeInvincibleToFriendlyFire();
// contents
clonk.MaxContentsCount = CustomAI.Clonk_MaxContentsCount;
clonk.MaxContentsCountVal = 1;
clonk.MaxContentsCount = 1;
if (prev_clonk) TransferInventory(prev_clonk, clonk);
if (!clonk->ContentsCount())
{

View File

@ -479,9 +479,8 @@ func LaunchEnemy(proplist enemy, int xmin, int xrange, int ymin, yrange)
obj.JumpSpeed = obj.JumpSpeed * enemy.Speed / 100;
obj.FlySpeed = obj.FlySpeed * enemy.Speed / 100;
}
obj.MaxContentsCount = CustomAI.Clonk_MaxContentsCount;
obj.MaxContentsCount = 2;
obj->MakeInvincibleToFriendlyFire();
obj.MaxContentsCountVal = 2;
// Reward for killing enemy
obj.Bounty = enemy.Bounty;
// Vehicles
@ -552,6 +551,3 @@ func LaunchEnemy(proplist enemy, int xmin, int xrange, int ymin, yrange)
g_spawned_enemies[GetLength(g_spawned_enemies)] = obj;
return obj;
}
// forward max contents count to property
func Clonk_MaxContentsCount() { return this.MaxContentsCountVal; }

View File

@ -101,8 +101,7 @@ func JoinPlayer(plr, prev_clonk)
clonk->DoEnergy(1000);
clonk->MakeInvincibleToFriendlyFire();
// contents
clonk.MaxContentsCount = CustomAI.Clonk_MaxContentsCount;
clonk.MaxContentsCountVal = 1;
clonk.MaxContentsCount = 1;
if (prev_clonk) TransferInventory(prev_clonk, clonk);
if (!clonk->ContentsCount())
{

View File

@ -51,14 +51,11 @@ protected func ContactRight()
/*-- Contents --*/
private func MaxContentsCount()
{
return 50;
}
local MaxContentsCount = 50;
protected func RejectCollect(id object_id, object obj)
{
if (ContentsCount() < this->MaxContentsCount())
if (ContentsCount() < MaxContentsCount)
{
Sound("Objects::Clonk");
return false;

View File

@ -238,7 +238,7 @@ private func UpdateInventory()
// Sets the inventory size to the currently selected clonk
private func UpdateInventoryButtons(object clonk)
{
var max_contents_count = clonk->~MaxContentsCount();
var max_contents_count = clonk.MaxContentsCount;
var old_count = GetLength(inventory_slots);

View File

@ -29,14 +29,11 @@ protected func Construction()
/*-- Contents --*/
private func MaxContentsCount()
{
return 5;
}
local MaxContentsCount = 5;
protected func RejectCollect(id def, object obj)
{
if (ContentsCount() >= MaxContentsCount())
if (ContentsCount() >= MaxContentsCount)
return true;
if (obj->~IsCarryHeavy())
return true;

View File

@ -30,7 +30,7 @@ protected func Construction()
effect.oldcount = count;
}
protected func MaxContentsCount() { return 12; }
local MaxContentsCount = 12;
public func GetPowderCount()
{

View File

@ -64,8 +64,8 @@ static const ELEVATOR_CALL_DISTANCE = 30;
/* Item limit */
public func MaxContentsCount() { return 5; } // Size of the clonks inventory
public func HandObjects() { return 1; } // Amount of hands to select items
local MaxContentsCount = 5; // Size of the clonks inventory
local HandObjects = 1; // Amount of hands to select items
public func NoStackedContentMenu() { return true; } // Contents-Menu shall display each object in a seperate slot

View File

@ -55,7 +55,7 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re
if (ctrl == CON_QuickSwitch)
{
// but ignore quickswitch if we have more than 1 hand-slot
if(this->HandObjects() > 1)
if(this.HandObjects > 1)
return inherited(plr, ctrl, x, y, strength, repeat, release, ...);;
// select last slot
@ -144,8 +144,8 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re
if (inventory_shift)
{
var current = (this->GetHandItemPos(0) + inventory_shift) % this->MaxContentsCount();
if (current < 0) current = this->MaxContentsCount() + current;
var current = (this->GetHandItemPos(0) + inventory_shift) % this.MaxContentsCount;
if (current < 0) current = this.MaxContentsCount + current;
this->SetHandItemPos(0, current);
return true;
}
@ -193,7 +193,7 @@ public func ObjectControl(int plr, int ctrl, int x, int y, int strength, bool re
// only the last-pressed key is taken into consideration.
// if 2 hotkeys are held, the earlier one is being treated as released
if (hot > 0 && hot <= this->MaxContentsCount())
if (hot > 0 && hot <= this.MaxContentsCount)
{
SetHandItemPos(0, hot-1);
return true;

View File

@ -7,10 +7,10 @@
The inventory management:
The objects in the inventory are saved (parallel to Contents()) in the
array 'inventory'. They are accessed via GetItem(i) and GetItemPos(obj).
Other functions are MaxContentsCount() (defines the maximum number of
Other properties are MaxContentsCount (defines the maximum number of
contents)
Furthermore the clonk has a defined amount of "hands", defined by HandObjects().
Furthermore the clonk has a defined amount of "hands", defined by local HandObjects.
The array 'use_objects' is a mapping of "hands" onto the inventory-slots.
The functions GetHandItem(i) returns the object in the "i"th hand.
@ -23,8 +23,8 @@
/* Item limit */
public func MaxContentsCount() { return 10; } // Size of the inventory
public func HandObjects() { return 1; } // Amount of hands to select items
local MaxContentsCount = 10; // Size of the inventory
local HandObjects = 1; // Amount of hands to select items
func Construction()
{
@ -35,7 +35,7 @@ func Construction()
this.inventory.hand_objects = [];
this.inventory.force_collection = false;
for(var i=0; i < HandObjects(); i++)
for(var i=0; i < HandObjects; i++)
this.inventory.hand_objects[i] = i;
return _inherited(...);
}
@ -85,7 +85,7 @@ public func GetHandItem(int i)
public func SetHandItemPos(int hand, int inv)
{
// indices are in range?
if(hand >= HandObjects() || inv >= MaxContentsCount())
if(hand >= HandObjects || inv >= MaxContentsCount)
return nil;
if(hand < 0 || inv < 0) return nil;
// no slot change?
@ -214,8 +214,8 @@ public func GetItemPos(object item)
public func Switch2Items(int one, int two)
{
// no valid inventory index: cancel
if (!Inside(one,0,MaxContentsCount()-1)) return;
if (!Inside(two,0,MaxContentsCount()-1)) return;
if (!Inside(one,0,MaxContentsCount-1)) return;
if (!Inside(two,0,MaxContentsCount-1)) return;
// switch them around
var temp = this.inventory.objects[one];
@ -279,7 +279,7 @@ public func Collect(object item, bool ignoreOCF, int pos, bool force)
return success;
}
// fail if the specified slot is full
if (GetItem(pos) == nil && pos >= 0 && pos < MaxContentsCount())
if (GetItem(pos) == nil && pos >= 0 && pos < MaxContentsCount)
{
if (item)
{
@ -319,7 +319,7 @@ protected func Collection2(object obj)
var i;
// sort into selected hands if empty
for(i = 0; i < HandObjects(); i++)
for(i = 0; i < HandObjects; i++)
if(!GetHandItem(i))
{
sel = GetHandItemPos(i);
@ -331,7 +331,7 @@ protected func Collection2(object obj)
// otherwise, first empty slot
if(!success)
{
for(var i = 0; i < MaxContentsCount(); ++i)
for(var i = 0; i < MaxContentsCount; ++i)
{
if (!GetItem(i))
{
@ -464,7 +464,7 @@ protected func RejectCollect(id objid, object obj)
// Can't carry bucket material with bare hands.
if (obj->~IsBucketMaterial()) return true;
// check max contents
if (ContentsCount() >= MaxContentsCount()) return true;
if (ContentsCount() >= MaxContentsCount) return true;
return _inherited(objid,obj,...);
}

View File

@ -23,14 +23,11 @@ protected func Construction()
public func IsContainer() { return true; }
private func MaxContentsCount()
{
return 50;
}
local MaxContentsCount = 50;
protected func RejectCollect()
{
if (ContentsCount() >= this->MaxContentsCount())
if (ContentsCount() >= MaxContentsCount)
return true;
return false;
}

View File

@ -136,10 +136,7 @@ public func FxBlockCollectionByLorryTimer() { return FX_Execute_Kill; }
/*-- Contents --*/
private func MaxContentsCount()
{
return 50;
}
local MaxContentsCount = 50;
protected func RejectCollect(id object_id, object obj)
{
@ -148,7 +145,7 @@ protected func RejectCollect(id object_id, object obj)
return true;
// Objects can still be collected.
if (ContentsCount() < this->MaxContentsCount())
if (ContentsCount() < MaxContentsCount)
{
Sound("Objects::Clonk");
return false;

View File

@ -9,10 +9,7 @@ protected func RejectCollect(id objid, object obj)
return _inherited(objid, obj);
}
public func MaxContentsCount()
{
return 0;
}
local MaxContentsCount = 0;
public func ObjectControl(int plr, int ctrl)
{

View File

@ -9,15 +9,8 @@ protected func RejectCollect(id objid, object obj)
}
// Only one inventory slot.
public func MaxContentsCount()
{
return 1;
}
public func HandObjects()
{
return 1;
}
local MaxContentsCount = 1;
local HandObjects = 1;
// Lose all items on death.
func StartDead()

View File

@ -5,7 +5,7 @@
// overload function for objects with Inventory.ocd
global func ShiftContents(bool shift_back, id target_id)
{
if (this && (this->~HandObjects() > 0))
if (this && (this.HandObjects > 0))
{
// special handling for only one hand: just move the hand to next item
// always move hand 0
@ -13,7 +13,7 @@ global func ShiftContents(bool shift_back, id target_id)
// move to target ID?
if(target_id)
{
for(var pos = 0; pos < this->MaxContentsCount(); ++pos)
for(var pos = 0; pos < this.MaxContentsCount; ++pos)
{
var obj = this.inventory.objects[pos];
if(!obj) continue;
@ -29,11 +29,11 @@ global func ShiftContents(bool shift_back, id target_id)
var move_dir = 1;
if(shift_back) move_dir = -1;
var current_pos = this->GetHandItemPos(0);
for(var i = this->MaxContentsCount(); i > 0; --i)
for(var i = this.MaxContentsCount; i > 0; --i)
{
current_pos += move_dir;
if(current_pos < 0) current_pos = this->MaxContentsCount() + current_pos;
else current_pos = current_pos % this->MaxContentsCount();
if(current_pos < 0) current_pos = this.MaxContentsCount + current_pos;
else current_pos = current_pos % this.MaxContentsCount;
// is there an object at the slot?
if(!this.inventory.objects[current_pos]) continue;

View File

@ -5,15 +5,12 @@
public func IsContainer() { return true; }
private func MaxContentsCount()
{
return 25;
}
local MaxContentsCount = 25;
protected func RejectCollect(id object_id, object obj)
{
// Objects can collected if gold bar and not above max contents count.
if (ContentsCount() < MaxContentsCount() && object_id == GoldBar)
if (ContentsCount() < MaxContentsCount && object_id == GoldBar)
return false;
return true;
}