updated controlUse-system, fixed (&simplified) musket & bow

stable-5.2
Tobias Zwick 2010-01-22 17:29:46 +01:00
parent 039e9b49b1
commit 995b20cad9
5 changed files with 147 additions and 152 deletions

View File

@ -35,15 +35,15 @@ public func Launch(int angle, int str, object shooter)
private func Stick() private func Stick()
{ {
SetXDir(0);
SetYDir(0);
SetRDir(0);
if(GetEffect("InFlight",this)) if(GetEffect("InFlight",this))
{ {
RemoveEffect("HitCheck",this); RemoveEffect("HitCheck",this);
RemoveEffect("InFlight",this); RemoveEffect("InFlight",this);
SetXDir(0);
SetYDir(0);
SetRDir(0);
var x=Sin(GetR(),+12); var x=Sin(GetR(),+12);
var y=Cos(GetR(),-12); var y=Cos(GetR(),-12);
var mat = GetMaterial(x,y); var mat = GetMaterial(x,y);
@ -69,7 +69,7 @@ public func HitObject(object obj)
obj->~OnArrowHit(this); obj->~OnArrowHit(this);
if(!this) return; if(!this) return;
// ouch! // ouch!
var dmg = ArrowStrength()*speed/50; var dmg = ArrowStrength()*speed/100;
if(obj->GetAlive()) if(obj->GetAlive())
{ {
obj->DoEnergy(-dmg); obj->DoEnergy(-dmg);

View File

@ -13,7 +13,7 @@ local aimtime;
public func HoldingEnabled() { return true; } public func HoldingEnabled() { return true; }
protected func ControlUse(object clonk, int x, int y) protected func ControlUseStart(object clonk, int x, int y)
{ {
// check for ammo // check for ammo
if(!Contents(0)) if(!Contents(0))
@ -27,7 +27,11 @@ protected func ControlUse(object clonk, int x, int y)
} }
aimtime = 30; aimtime = 30;
if(!Contents(0)) return true; if(!Contents(0))
{
// + sound or message that he doesnt have arrows anymore
clonk->CancelUse();
}
return true; return true;
} }
@ -35,7 +39,11 @@ protected func ControlUse(object clonk, int x, int y)
public func ControlUseHolding(object clonk, int x, int y) public func ControlUseHolding(object clonk, int x, int y)
{ {
// check procedure // check procedure
if(!ClonkCanAim(clonk)) return -1; if(!ClonkCanAim(clonk))
{
clonk->CancelUse();
return true;
}
// angle // angle
var angle = Angle(0,0,x,y); var angle = Angle(0,0,x,y);
@ -53,14 +61,16 @@ public func ControlUseHolding(object clonk, int x, int y)
Message("Cannot aim there",clonk); Message("Cannot aim there",clonk);
else else
Message("Aiming",clonk); Message("Aiming",clonk);
return true;
} }
protected func ControlUseStop(object clonk, int x, int y) protected func ControlUseStop(object clonk, int x, int y)
{ {
Message("",clonk); Message("",clonk);
// "canceled" // "canceled"
if(aimtime > 0) return true; if(aimtime > 0) return true;
if(!ClonkCanAim(clonk)) return true;
var angle = Angle(0,0,x,y); var angle = Angle(0,0,x,y);
if(!ClonkAimLimit(clonk,angle)) return true; if(!ClonkAimLimit(clonk,angle)) return true;

View File

@ -25,7 +25,7 @@ private func HitObject(object pVictim)
{ {
Message("Ouch!", pVictim); //Remove when sound works; for debug Message("Ouch!", pVictim); //Remove when sound works; for debug
Punch(pVictim,RandomX(20,30)); pVictim->DoEnergy(-RandomX(10,15));
RemoveObject(); RemoveObject();
} }

View File

@ -6,13 +6,15 @@
--*/ --*/
#strict 2
//Uses the extra slot library //Uses the extra slot library
#include L_ES #include L_ES
local ReloadTimer; func Definition(def) {
local Loaded; SetProperty("Name", "$Name$", def);
}
local loaded;
local reload;
local yOffset; local yOffset;
local iBarrel; local iBarrel;
@ -25,155 +27,113 @@ protected func Initialize()
protected func HoldingEnabled() { return true; } protected func HoldingEnabled() { return true; }
protected func ControlUse(object pClonk, ix, iy) func ControlUseStart(object clonk, int x, int y)
{ {
//Don't throw the musket away! // nothign in extraslot?
return 1; if(!Contents(0))
{
// put something inside
var obj;
if(obj = FindObject(Find_Container(clonk), Find_Func("IsMusketAmmo")))
{
obj->Enter(this);
}
}
// something in extraslot
if(Contents(0))
{
// reload weapon if not loaded yet
if(!loaded) reload = 50;
}
else clonk->CancelUse();
return true;
} }
public func ControlUseHolding(object pClonk, ix, iy) func ControlUseHolding(object pClonk, ix, iy)
{ {
//Angle Finder // loading...
var IX=Sin(180-Angle(0,0,ix,iy),iBarrel); if(!loaded)
var IY=Cos(180-Angle(0,0,ix,iy),iBarrel); {
//Create debug dot to show muzzle-point // If Clonk messes up during reload, he must restart. :(
CastParticles("DebugReticle",1,0,IX,IY,30,30,RGB(255,0,0),RGB(255,0,0)); if(Contained()->GetProcedure() != "WALK")
//DrawParticleLine("DebugReticle",0,0,IX,IY,2,20,RGB(30,30,30),RGB(100,100,100)); //Debug: Enable to see firing angle of musket pClonk->CancelUse();
// count
Message("%d",pClonk,reload);
reload--;
if(reload <= 0)
{
loaded = true;
reload = 0;
Message("Pashunk!", Contained());
pClonk->CancelUse();
}
}
// loaded
else
{
//Angle Finder
var IX=Sin(180-Angle(0,0,ix,iy),iBarrel);
var IY=Cos(180-Angle(0,0,ix,iy),iBarrel);
//Create debug dot to show muzzle-point
CastParticles("DebugReticle",1,0,IX,IY,30,30,RGB(255,0,0),RGB(255,0,0));
//DrawParticleLine("DebugReticle",0,0,IX,IY,2,20,RGB(30,30,30),RGB(100,100,100)); //Debug: Enable to see firing angle of musket
}
return true;
} }
protected func ControlUseStop(object pClonk, ix, iy) protected func ControlUseStop(object pClonk, ix, iy)
{ {
// Reload if empty if(!loaded) return true;
if(Contents(0)==nil && FindObject(Find_Container(pClonk), Find_Func("IsMusketAmmo"))==nil) return 1;
if(Contents(0)==nil && Loaded==1) Loaded=0; if(!ClonkCanAim(pClonk)) return true;
if(!GetEffect("Reloading",this) && IsReloading()==true) ResumeReloading();
if(CheckCanUse(pClonk)==true && IsReloading()==false && Loaded!=true)
{
if(Contents(0)==nil || Loaded==false)
{
ReloadWeapon(50);
return 1;
}
}
// Fire // Fire
var IX=Sin(180-Angle(0,0,ix,iy),iBarrel); if(Contents(0))
var IY=Cos(180-Angle(0,0,ix,iy),iBarrel);
if(Contents(0)!=nil && PathFree(pClonk->GetX(),pClonk->GetY(),GetX()+IX,GetY()+IY)) //Stops musket from firing into ground or through walls.
{ {
if(Contents(0)->IsMusketAmmo()==1 && Loaded==true && CheckCanUse(pClonk)==true) if(Contents(0)->IsMusketAmmo())
{ {
FireWeapon(pClonk, ix, iy); FireWeapon(pClonk, ix, iy);
return 1;
} }
} }
return 1; return true;
} }
private func FireWeapon(object pClonk,iX,iY) private func FireWeapon(object pClonk,iX,iY)
{ {
var shot=Contents(0)->TakeObject(); var shot = Contents(0)->TakeObject();
shot->LaunchProjectile(Angle(0,0,iX,iY)+RandomX(-2, 2), iBarrel, 300); shot->LaunchProjectile(Angle(0,0,iX,iY)+RandomX(-2, 2), iBarrel, 300);
var iAngle=Angle(0,0,iX,iY); var iAngle=Angle(0,0,iX,iY);
shot->AffectShot(pClonk,iY,iX,iAngle); shot->AffectShot(pClonk,iY,iX,iAngle);
Loaded=false;
loaded = false;
Sound("Blast3"); Sound("Blast3");
Message("Bang!", pClonk); //For debug. Message("Bang!", pClonk); //For debug.
//Muzzle Flash // Muzzle Flash
/*var flash = pClonk->CreateObject(FLSH); var iAngle=Angle(0,0,iX,iY);
flash->SetAction("Flash",pClonk);
flash->SetR(Angle(0,0,iX,iY));
*/
//Muzzle Flash
var iAngle=Angle(0,0,iX,iY);;
var IX=Sin(180-Angle(0,0,iX,iY),iBarrel); var IX=Sin(180-Angle(0,0,iX,iY),iBarrel);
var IY=Cos(180-Angle(0,0,iX,iY),iBarrel); var IY=Cos(180-Angle(0,0,iX,iY),iBarrel);
CreateParticle("MuzzleFlash",IX,IY,+Sin(iAngle,500),-Cos(iAngle,500),300,RGB(255,255,255),pClonk); CreateParticle("MuzzleFlash",IX,IY,+Sin(iAngle,500),-Cos(iAngle,500),300,RGB(255,255,255),pClonk);
//Gun Smoke //Gun Smoke
CastParticles("GunSmoke",10,3,IX,IY,20,50,RGBa(110,110,110,128),RGB(150,150,150,128)); CastParticles("GunSmoke",10,3,IX,IY,20,50,RGBa(110,110,110,128),RGB(150,150,150,128));
} }
private func ReloadWeapon(int iReloadTime) private func ClonkCanAim(object clonk)
{ {
//Put ammo into gun's extra slot var p = clonk->GetProcedure();
var Ammo; if(p != "WALK" && p != "ATTACH" && p != "FLIGHT") return false;
if(Ammo=FindObject(Find_Container(Contained()), Find_Func("IsMusketAmmo"))) return true;
{
if(Contents(0)==nil) Ammo->Enter(this()); //Only put new more ammo in gun if gun is empty
}
ReloadTimer=iReloadTime;
AddEffect("Reloading",this,300,1,this,this);
}
protected func FxReloadingTimer(pTarget,iEffectNumber,iEffectTime)
{
//If Clonk messes up reload, he must restart. :(
if(Contained()==nil || CheckCanUse(Contained())==false)
{
PauseReloading();
ReloadTimer=50;
}
if(ReloadTimer<=0)
{
Loaded=true;
return -1;
}
if(ReloadTimer>0) ReloadTimer=--ReloadTimer;
Message("%d", Contained(), ReloadTimer);
}
protected func FxReloadingStop(pTarget,iEffectNumber,iReason,fTemp)
{
Message("Pashunk!", Contained()); //This whole function is just for debug, unless there will be a sound for finishing a reload.
}
public func IsReloading()
{
if(ReloadTimer>0) return true;
return false;
}
public func PauseReloading()
{
if(GetEffect("Reloading",this))
{
RemoveEffect("Reloading",this,0,1);
return true;
}
return false;
}
public func ResumeReloading()
{
if(ReloadTimer>0 && !GetEffect("Reloading",this))
{
AddEffect("Reloading",this,300,1,this,this);
return true;
}
return false;
}
private func CheckCanUse(object pClonk)
{
if(pClonk->GetOCF() & OCF_NotContained)
{
if(pClonk->GetAction() == "Walk" || pClonk->GetAction() == "Jump") return true;
}
return false;
} }
func RejectCollect(id shotid, object shot) func RejectCollect(id shotid, object shot)
{ {
//Only collect musket-balls // Only collect musket-ammo
if(!(shot->~IsMusketBall())) return true; if(!(shot->~IsMusketAmmo())) return true;
} }
func Definition(def) {
SetProperty("Name", "$Name$", def);
}

View File

@ -152,6 +152,10 @@ public func Switch2Items(int one, int two)
inventory[one] = inventory[two]; inventory[one] = inventory[two];
inventory[two] = temp; inventory[two] = temp;
// callbacks
if(using == inventory[one] || using == inventory[two])
CancelUse();
if(one == selected) inventory[two]->~Deselection(this,false); if(one == selected) inventory[two]->~Deselection(this,false);
else if(one == selected2) inventory[two]->~Deselection(this,true); else if(one == selected2) inventory[two]->~Deselection(this,true);
if(two == selected) inventory[one]->~Deselection(this,false); if(two == selected) inventory[one]->~Deselection(this,false);
@ -253,12 +257,16 @@ protected func Collection2(object obj)
protected func Ejection(object obj) protected func Ejection(object obj)
{ {
var i; var i;
// find obj in array and delete // find obj in array and delete (cancel using too)
for(i = 0; i < MaxContentsCount(); ++i) for(i = 0; i < MaxContentsCount(); ++i)
{ {
if (inventory[i] == obj) if (inventory[i] == obj)
{ inventory[i] = nil; break; } {
inventory[i] = nil;
break;
}
} }
if(using == obj) CancelUse();
this->~OnSlotEmpty(i); this->~OnSlotEmpty(i);
@ -475,36 +483,55 @@ private func CancelUse()
if (Contained() == using) if (Contained() == using)
control = "Contained"; control = "Contained";
StopUseControl(control, mlastx, mlasty, using); CancelUseControl(control, mlastx, mlasty, using);
} }
private func StartUseControl(int ctrl, control, int x, int y, object obj) private func StartUseControl(int ctrl, control, int x, int y, object obj)
{ {
using = obj;
var hold_enabled = obj->Call("~HoldingEnabled");
if(hold_enabled)
SetPlayerControlEnabled(GetOwner(), CON_Aim, true);
if (ctrl == CON_Use) alt = false; if (ctrl == CON_Use) alt = false;
else alt = true; else alt = true;
var estr = ""; var estr = "";
if (alt && !(obj->Contained())) estr = "Alt"; if (alt && !(obj->Contained())) estr = "Alt";
var handled = obj->Call(Format("~%sUse%s",control,estr),this,x,y); // first call UseStart. If unhandled, call Use (mousecontrol)
if (!handled) return false; var handled = obj->Call(Format("~%sUseStart%s",control,estr),this,x,y);
if (!handled)
using = obj; handled = obj->Call(Format("~%sUse%s",control,estr),this,x,y);
if (!handled)
if(obj->Call("~HoldingEnabled")) {
SetPlayerControlEnabled(GetOwner(), CON_Aim, true); using = nil;
if(hold_enabled)
SetPlayerControlEnabled(GetOwner(), CON_Aim, false);
return false;
}
return handled; return handled;
} }
private func StopUseControl(control, int x, int y, object obj) private func CancelUseControl(control, int x, int y, object obj)
{
return StopUseControl(control, x, y, obj, true);
}
private func StopUseControl(control, int x, int y, object obj, bool cancel)
{ {
var estr = ""; var estr = "";
if (alt && !(obj->Contained())) estr = "Alt"; if (alt && !(obj->Contained())) estr = "Alt";
var holding_enabled = obj->Call("~HoldingEnabled"); var holding_enabled = obj->Call("~HoldingEnabled");
var handled = obj->Call(Format("~%sUse%sStop",control,estr),this,x,y); var stop = "Stop";
if(cancel) stop = "Cancel";
// ControlUseStop, ControlUseAltStop, ContainedUseAltStop, ContainedUseCancel, etc...
var handled = obj->Call(Format("~%sUse%s%s",control,estr,stop),this,x,y);
using = nil; using = nil;
alt = false; alt = false;
@ -518,11 +545,14 @@ private func StopUseControl(control, int x, int y, object obj)
private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, bool release, string control, object obj) private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, bool release, string control, object obj)
{ {
// do not use secondary when using primary and the other way round // click on secondary cancels primary and the other way round
if (using) if (using)
{ {
if (ctrl == CON_Use && alt) return true; if (ctrl == CON_Use && alt || ctrl == CON_UseAlt && !alt)
if (ctrl == CON_UseAlt && !alt) return true; {
CancelUseControl(control, x, y, using);
return true;
}
} }
// for the use command // for the use command
@ -539,7 +569,8 @@ private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, b
else if (release && using) else if (release && using)
{ {
// leftover use release // leftover use release
return CancelUse(); CancelUse();
return true;
} }
else if (repeat && using == obj) else if (repeat && using == obj)
{ {
@ -548,12 +579,6 @@ private func Control2Script(int ctrl, int x, int y, int strength, bool repeat, b
var handled = obj->Call(Format("~%sUse%sHolding",control,estr),this,x,y); var handled = obj->Call(Format("~%sUse%sHolding",control,estr),this,x,y);
// if that function returns -1, the control is stopped (*UseStop)
// and no more *UseHolding-calls are made.
if (handled == -1)
{
handled = StopUseControl(control, x, y, obj);
}
return handled; return handled;
} }
} }