1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308
|
/**
CarryHeavyControl
Handles the control of carry-heavy-objects as inventory objects.
Depends on Clonk Control and Inventory
*/
local lib_carryheavy_obj; // object beeing carried with carryheavy
public func GetCarryHeavy() { return lib_carryheavy_obj; }
public func IsCarryingHeavy() { return lib_carryheavy_obj != nil; }
/* Overloads for Inventory */
// Check if we can carry a carry heavy object
protected func RejectCollect(id objid, object obj)
{
// Carry heavy only gets picked up if none held already
if(this.inventory.force_collection && obj->~IsCarryHeavy())
{
// Collection of that object magically disabled?
if(GetEffect("NoCollection", obj)) return true;
// Do callbacks to control effects to see if the effect blocks picking up a carry heavy object.
var block_carry_heavy = false;
var count = GetEffectCount("*Control*", this), control_effect;
while (count--)
{
control_effect = GetEffect("*Control*", this, count);
if (control_effect && EffectCall(this, control_effect, "RejectCarryHeavyPickUp", obj))
{
block_carry_heavy = true;
break;
}
}
// Don't pick up if already carrying a heavy object or if it is blocked.
if (IsCarryingHeavy() || block_carry_heavy)
{
CustomMessage("$TxtHandsFull$", this, this->GetController(), 0, 0, 0xff0000);
return true;
}
return false;
}
return _inherited(objid,obj,...);
}
// Start visual effect when picking up carry heavy objects
public func Collection2(object obj)
{
if(obj->~IsCarryHeavy()) // we can assume that we don't have a carryheavy object yet. If we do, Scripters are to blame.
{
CarryHeavy(obj);
DoLiftCarryHeavy(obj);
return true;
}
return _inherited(obj,...);
}
public func GetHandItem(int i)
{
// carrying a carry heavy item always returns said item. (he holds it in both hands, after all!)
if (IsCarryingHeavy())
return GetCarryHeavy();
return _inherited(i, ...);
}
public func SetHandItemPos(int hand, int inv)
{
// can't use anything except carryheavy if carrying heavy object.
if(IsCarryingHeavy())
return nil;
return _inherited(hand, inv, ...);
}
// Delete internal variables
public func Ejection(object obj)
{
// carry heavy special treatment
if(obj == GetCarryHeavy())
{
StopCarryHeavy();
return true;
}
return _inherited(obj,...);
}
// Delete internal variables
public func ContentsDestruction(object obj)
{
// check if it was carryheavy
if(obj == GetCarryHeavy())
{
StopCarryHeavy();
}
return _inherited(obj, ...);
}
/* Overloads for Clonk Control */
public func GetExtraInteractions()
{
var functions = _inherited(...);
// dropping carry heavy
if(IsCarryingHeavy() && GetAction() == "Walk")
{
var ch = GetCarryHeavy();
PushBack(functions, {Fn = "DropCarryHeavy", Description=ch->GetDropDescription(), Object=this, IconName="", IconID=Icon_LetGo, Priority=1});
}
return functions;
}
/* Carry heavy stuff */
/** Tells the clonk that he is carrying the given carry heavy object */
public func CarryHeavy(object target)
{
if(!target)
return;
// actually.. is it a carry heavy object?
if(!target->~IsCarryHeavy())
return;
// only if not carrying a heavy objcet already
if(IsCarryingHeavy())
return;
lib_carryheavy_obj = target;
if(target->Contained() != this)
target->Enter(this);
// Update attach stuff
this->~OnSlotFull();
// Do callbacks to control effects for this clonk that a carry heavy object has been picked up.
var count = GetEffectCount("*Control*", this), control_effect;
while (count--)
{
control_effect = GetEffect("*Control*", this, count);
if (control_effect)
EffectCall(this, control_effect, "OnCarryHeavyPickUp", target);
}
return true;
}
/** Drops the carried heavy object, if any */
public func DropCarryHeavy()
{
// only if actually possible
if(!IsCarryingHeavy())
return;
DoDropCarryHeavy(GetCarryHeavy());
StopCarryHeavy();
return true;
}
// Internal function to clear carryheavy-status
private func StopCarryHeavy()
{
if(!IsCarryingHeavy())
return;
lib_carryheavy_obj = nil;
this->~OnSlotEmpty();
}
/* Lifting / dropping effect */
local lib_carryheavy_lifttime = 45;
private func DoLiftCarryHeavy(object obj)
{
if (!obj || !obj->~IsCarryHeavy())
return;
if (obj->Contained() != this)
return;
// If inside something or not walking, skip the animation
if (Contained() || GetAction() != "Walk")
return;
AddEffect("IntLiftHeavy", this, 1, 1, this, nil, obj);
}
private func DoDropCarryHeavy(object obj)
{
if (!obj || !obj->~IsCarryHeavy())
return;
if (obj->Contained() != this)
return;
// If inside something or not walking, skip the animation
if (Contained() || GetAction() != "Walk")
return;
AddEffect("IntDropHeavy", this, 1, 1, this, nil, obj);
}
private func FxIntLiftHeavyStart(object me, proplist effect, bool tmp, object to_lift)
{
//Stop the clonk from moving, and tell the clonk's control library
//it now has a hand action
me->SetTurnForced(GetDir());
me->SetHandAction(1);
SetAction("Stand");
//Stop the clonk if he is moving
if(GetXDir() != 0) SetXDir();
//Attach the mesh of the object. It is not displayed normally because the
//hands are told they have an action in the next few lines
effect.mesh = AttachMesh(to_lift, "pos_tool1", to_lift->GetCarryBone(), to_lift->~GetCarryTransform(this));
//Play the animation of the clonk picking up the object
effect.anim = PlayAnimation("CarryArmsPickup", CLONK_ANIM_SLOT_Arms, Anim_Linear(0,0, GetAnimationLength("CarryArmsPickup"), lib_carryheavy_lifttime, ANIM_Remove), Anim_Const(1000));
effect.obj = to_lift;
}
private func FxIntLiftHeavyTimer(object me, proplist effect, int time)
{
//If the clonk moves, he'll stop lifting and drop the object
if(time < lib_carryheavy_lifttime)
{
// first 2/3 of time, clonk will drop the object
if(time < lib_carryheavy_lifttime * 2 / 3)
{
if(GetAction() != "Stand" || me->IsJumping() || Abs(GetXDir()) > 0)
{
effect.fail = true;
return FX_Execute_Kill;
}
}
else
{
if(GetAction() != "Stand")
return FX_Execute_Kill;
}
}
//When the clonk has finished lifting, remove movement-restrictions
if(time >= lib_carryheavy_lifttime)
return FX_Execute_Kill;
// Object got moved out during lifting
if(!effect.obj || effect.obj->Contained() != this)
return FX_Execute_Kill;
}
private func FxIntLiftHeavyStop(object me, proplist effect)
{
// If failed, drop the object
if(effect.fail && effect.obj && effect.obj->Contained() == this)
effect.obj->Exit(0,9);
DetachMesh(effect.mesh);
StopAnimation(effect.anim);
me->SetTurnForced(-1);
me->SetHandAction(0);
if(GetAction() == "Stand") SetAction("Walk");
}
private func FxIntDropHeavyStart(object me, proplist effect, bool tmp, object to_lift)
{
if(GetEffect("IntCarryHeavy"))
RemoveEffect("IntCarryHeavy", this, nil, true);
//Stop the clonk from moving, and tell the clonk's control library
//it now has a hand action
me->SetTurnForced(GetDir());
me->SetHandAction(1);
SetAction("Stand");
//Stop the clonk if he is moving
if(GetXDir() != 0) SetXDir();
//Attach the mesh of the object. It is not displayed normally because the
//hands are told they have an action in the next few lines
effect.mesh = AttachMesh(to_lift, "pos_tool1", to_lift->GetCarryBone(), to_lift->~GetCarryTransform(this));
//Play the animation of the clonk setting down the object
effect.anim = PlayAnimation("CarryArmsPickup", CLONK_ANIM_SLOT_Arms, Anim_Linear(GetAnimationLength("CarryArmsPickup"), GetAnimationLength("CarryArmsPickup"), 0, lib_carryheavy_lifttime, ANIM_Remove), Anim_Const(1000));
effect.obj = to_lift;
}
private func FxIntDropHeavyTimer(object me, proplist effect, int time)
{
if (time >= lib_carryheavy_lifttime)
return FX_Execute_Kill;
if (GetAction() != "Stand")
return FX_Execute_Kill;
if (!effect.obj)
return FX_Execute_Kill;
if (effect.obj->Contained() != this)
return FX_Execute_Kill;
}
private func FxIntDropHeavyStop(object me, proplist effect)
{
// Drop the object
if(effect.obj && effect.obj->Contained() == this)
effect.obj->Exit(0,9);
DetachMesh(effect.mesh);
StopAnimation(effect.anim);
me->SetTurnForced(-1);
me->SetHandAction(0);
if(GetAction() == "Stand") SetAction("Walk");
}
|