Tobias Zwick 2010-01-13 00:29:17 +01:00
parent ae8a62d8df
commit b381b54523
4 changed files with 64 additions and 21 deletions

View File

@ -1,5 +1,3 @@
#strict 2
/*
Object selector HUD
Author: Newton
@ -188,18 +186,18 @@ public func MouseDrop(int plr, obj)
{
var myoldobject = myobject;
// 1. exit my old object
myoldobject->Exit();
// 2. enter the other object in my slot (myobject is now nil)
crew->Collect(obj,hotkey-1);
// 3. enter my old object into other object
objcontainer->Collect(myoldobject);
if(crew->Collect(obj,hotkey-1))
objcontainer->Collect(myoldobject);
else
crew->Collect(myoldobject,hotkey-1);
}
// otherwise, just collect
else
{
obj->Collect(crew,hotkey-1);
crew->Collect(obj,hotkey-1);
}
return true;
}
else if(actiontype == ACTIONTYPE_VEHICLE)
{
@ -253,10 +251,7 @@ public func SetObject(object obj, int type, int pos)
SetName(Format("$TxtSlot$",hotkey));
this["MouseDragImage"] = nil;
if(subselector)
{
subselector->RemoveObject();
SetName("$TxtEmpty$");
}
}
else
{
@ -279,9 +274,13 @@ public func SetObject(object obj, int type, int pos)
// if object has extra slot, show it
if(myobject->~HasExtraSlot())
{
subselector = CreateObject(GetID(),0,0,GetOwner());
subselector->DoCon(-50);
SetObject(myobject->Contents(0), ACTIONTYPE_INVENTORY, -1);
subselector = CreateObject(ACB2,0,0,GetOwner());
subselector->SetPosition(GetX()+16,GetY()+16);
subselector->SetContainer(myobject);
}
else if(subselector)
{
subselector->RemoveObject();
}
}
}

View File

@ -4,5 +4,4 @@ TxtGrab=%s anfassen
TxtUnGrab=%s loslassen
TxtEnter=%s betreten
TxtExit=%s verlassen
TxtPushOut=%s hinausschieben
TxtEmpty=Leer
TxtPushOut=%s hinausschieben

View File

@ -4,5 +4,4 @@ TxtGrab=Grab %s
TxtUnGrab=Let go %s
TxtEnter=Enter %s
TxtExit=Exit %s
TxtPushOut=Push %s out
TxtEmpty=Empty
TxtPushOut=Push %s out

View File

@ -1,9 +1,52 @@
/*
Stackable
Author: Newton
Including this object means, the object is stackable. Other objects of
the same type will be added automatically to the object. This functionality
is similar to the Pack-functionality of the arrows in old clonk titles only
more general.
The count of how many objects are stacked together (into a single one, this
one) is shown in the picture of the object and can be queried and set via
GetStackCount()/SetStackCount().
To take one object of the stack, call TakeObject(). As long
as the object exists, one can always take an object, even if it is the last
one (self). This object is always outside.
On entrance (or to be more precise: on RejectEntrance), it will be checked
if the entering stackable object can be distributed over the other objects
of the same ID. If yes, this object is deleted and the other object(s) will
have a higher stack-count.
Example 1:
'15x Arrow' is about to enter a clonk which has '5x Arrow'. 15 will be added
to the stack-count of the clonks '5x Arrow'-object (making it '20x Arrow'),
the entering object will be deleted.
Example 2:
'17x Arrow' is about to enter a clonk which has '15x Arrow' and a bow with
'10x Arrow' in it's ammunition slot. 10 will be added to the stack-count
of the arrows in the bow, 5 to the stack-count of the arrows in the clonk
(assuming MaxStackCount() is 20) and the original arrows-object will have
2 arrows left. If there is an inventory slot left, the '2x Arrow" object
will enter the clonk.
Most objects which can be stacked might want to set different pictures
and ingame graphics for different counts of objects. This can be done
by overloading UpdatePicture(), but remember to write _inherited() then.
*/
local count;
public func IsStackable() { return true; }
public func GetStackCount() { return Max(1,count); }
public func MaxStackCount() { return 20; }
protected func Construction()
{
count = MaxStackCount();
}
public func Stack(object obj)
{
if(obj->GetID() != GetID()) return 0;
@ -31,7 +74,9 @@ public func TakeObject()
else if(count > 1)
{
SetStackCount(count-1);
return CreateObject(GetID(),0,0,GetOwner());
var take = CreateObject(GetID(),0,0,GetOwner());
take->SetStackCount(1);
return take;
}
}
@ -54,11 +99,12 @@ public func UpdatePicture()
SetGraphics(Format("%d",hun),NUMB,3,GFXOV_MODE_Picture);
SetObjDrawTransform(400,0,-5000,0,400,+10000, 3);
SetName(Format("%dx %s",GetStackCount(),GetID()->GetName()));
}
public func UpdateMass()
{
SetMass(GetID()->GetMass()*Max(GetStackCount(),1));
SetMass(GetID()->GetMass()*Max(GetStackCount(),1)/MaxStackCount());
}
protected func RejectEntrance(object into)
@ -71,7 +117,7 @@ protected func RejectEntrance(object into)
public func CalcValue(object pInBase, int iForPlayer)
{
// Je nach Anzahl
return(GetID()->GetValue()*Max(GetStackCount(),1));
return(GetID()->GetValue()*Max(GetStackCount(),1)/MaxStackCount());
}
private func TryPutInto( object into )