/***************************************************************/ /* */ /* PBSHOOT.PKG */ /* */ /* plug-in PhotoPaintBall */ /* client - shoot and ammos animation management */ /* */ /* version 5 : Loïc Berthelot, CryoNetworks, dec 2000 */ /* */ /* nouvelle version 4.5 : Loïc Berthelot nov 2000 */ /* */ /* Photo3 Plugin - DMS - march 00 - by Sylvain HUET */ /* */ /* rev September 2001 - by Franck OHAYON & Sebastien DENEUX */ /***************************************************************/ /***************************************************************/ /* */ /* */ /* DATA STRUCTS : */ /* struct ShootedAmmo */ /* typeof shoot_fifo : [ShootedAmmo r1] */ /* typeof shoot_CbPostRender : fun [[ShootedAmmo r1]] I */ /* */ /* */ /* EXTERNAL BODY : */ /* shoot_shooted : fun [UserI S S] I */ /* shoot_shoot : fun [Pb Ob H3d I I I I H3d H3d] I */ /* shoot_render : fun [[ShootedAmmo r1]] I */ /* */ /* */ /***************************************************************/ /******************************************************************************/ /* */ /* D A T A S T R U C T S */ /* */ /******************************************************************************/ /* Ammo shooted by an avatar */ struct ShootedAmmo = [ /* ID of ammo in ammos library */ index_SA : I, /* shell */ shell_SA : H3d, /* object */ obj_SA : H3d, /* paintball ref of shooter */ p_SA : Pb, /* targeted instance */ o_SA : Ob, /* textures coordinates */ u_SA : I, v_SA : I, /* distance between you and the target */ z_SA : I, /* current distance of ammo */ curDistance_SA : I, /* 1 if the target is an avatar */ codeTouch_SA : I, /* 1 if the avatar is alive */ /* MODIF */ Avstate : I, lastTick_SA : I ] mkShootedAmmo;; /* all the shooted ammos are stored in fifo */ typeof shoot_fifo = [ShootedAmmo r1];; /* postrender callback ref when an ammo is shooted */ typeof shoot_CbPostRender = fun [[ShootedAmmo r1]] I;; /******************************************************************************/ /* */ /* E X T E R N A L B O D Y */ /* */ /******************************************************************************/ proto shoot_render = fun [[ShootedAmmo r1]] I;; /**********************************************/ /* shoot_shooted [UserI S S] I */ /* */ /* an avatar has shooted. create ammo and */ /* animate it. */ /**********************************************/ fun shoot_shooted (ui, action, param) = if pbData!=nil && (pbData.alive_PBDATA) && !pbControl.enable_PBCTRL then /* MODIF 29-11 *//* MODIF POUR PAS AVOIR LES BALLES MATRIX quand qq tire et qu'on est pas un mode paintball ou sur la page d'accueil ou dead*/ ( /* get shoot parameters */ let hd strextr param -> [indexStr [xStr [yStr [zStr [dalphaStr [dbetaStr [dgammaStr [distanceStr [State _]]]]]]]]] in let atoi indexStr -> index in let atoi xStr -> x in let atoi yStr -> y in let atoi zStr -> z in let atoi dalphaStr -> dalpha in let atoi dbetaStr -> dbeta in let atoi dgammaStr -> dgamma in let atoi distanceStr -> distance in let atoi State -> state in /* copy ammo object */ let M3copyObj session ammosLib.(index).obj_AEL -> newBall in let M3createShell session -> ballShell in ( M3link session newBall ballShell; M3link session ballShell shell; /* position of ammo, near avatar's gun */ M3setObjVec session ballShell [x y z]; /* orientation */ M3setObjAng session ballShell [dalpha dbeta dgamma]; let mkShootedAmmo [index ballShell newBall nil nil nil nil distance 0 0 state _tickcount] -> newPBball in ( /* add ammo to fifo */ set shoot_fifo = newPBball::shoot_fifo; /* and set the postrender callback */ if (shoot_CbPostRender == nil) then set shoot_CbPostRender = @shoot_render else nil; 1; ); ) ) else nil ;; /*************************************************/ /* shoot_shoot [Pb Ob H3d I I I I H3d H3d] I */ /* */ /* you shooted an ammo : create the ammo and */ /* animate it */ /*************************************************/ fun shoot_shoot (p, o, hdlr, u, v, z, codeTouch, Laststate, ammoShell, ammoAvShell) = let p.itemIndex_PB -> index in /* copy ammo object */ let M3copyObj session ammosLib.(index).obj_AEL -> newBall in let M3createShell session -> ballShell in /* position of target */ let M3calcPosRef session hdlr shell -> [[hx hy hz] _] in /* position of your ammo shell */ let M3calcPosRef session ammoShell shell -> [[gx gy gz] _] in ( M3link session newBall ballShell; M3link session ballShell shell; /* compute length of vector */ let ftoi sqrt (itof (((hx-gx)*(hx-gx)) + ((hy-gy)*(hy-gy)) + ((hz-gz)*(hz-gz)))) -> norme in /* position of this ammo for others clients */ let M3calcPosRef session ammoAvShell shell -> [[max may maz] _] in let M3getObjAng session (ObGetMain owner) -> [_ sbeta _] in let M3getObjAng session myavatar -> [salpha _ _] in let if (codeTouch) then /* if target is an avatar, orient the ammo in the direction of target */ let M3angularTarget [gx gy gz] [hx hy hz] -> cangle in let M3angularTarget [max may maz] [hx hy hz] -> eangle in [norme cangle eangle] /* else let ammo go away from you */ else [z [salpha sbeta 0] [salpha sbeta 0]] -> [distance cangle [ealpha ebeta egamma]] in let mkShootedAmmo [index ballShell newBall p o u v distance 0 codeTouch Laststate _tickcount] -> newPBball in ( M3setObjVec session newPBball.shell_SA [gx gy gz]; M3setObjAng session newPBball.shell_SA cangle; /* others clients will see this ammo */ UsendMessage ObUi owner "ammo" strbuild ((itoa newPBball.index_SA):: (itoa max)::(itoa may)::(itoa maz):: (itoa ealpha)::(itoa ebeta)::(itoa egamma):: (itoa newPBball.z_SA)::(itoa Laststate)::nil)::nil; /* MODIF */ /* add ammo to fifo */ set shoot_fifo = newPBball::shoot_fifo; /* and set the postrender callback */ if (shoot_CbPostRender == nil) then set shoot_CbPostRender = @shoot_render else nil; 1; ); ) ;; /*************************************************/ /* shoot_render [[ShootedAmmo r1]] I */ /* */ /* postrender callback for ammos animation */ /*************************************************/ fun shoot_render (fifo) = if (fifo == nil) then ( /* there is no more ammos in fifo, */ /* set the postrender callback ref to nil, */ /* in order to avoid useless boolean test */ if (shoot_fifo == nil) then ( M3freeMemory session; set shoot_CbPostRender = nil; ) else nil; 0; ) else let fifo -> [fst nxt] in ( /* if this ammo touchs the target */ if (fst.curDistance_SA >= fst.z_SA) then ( /* send message to paint the texture and update score if target is alive */ if (fst.codeTouch_SA && fst.Avstate) then /* MODIF */ ( UsendMessage ObUi fst.o_SA "shoot" strbuild ((itoa fst.index_SA):: (itoa fst.p_SA.spinachDamage_PB):: (itoa fst.u_SA):: (itoa fst.v_SA):: (itoa fst.z_SA):: (itoa fst.p_SA.col_PB)::nil)::nil; 0 ) else nil; /* delete ammos object and remove it from the fifo */ if ((M3objName session fst.obj_SA) != nil) then M3delObj session fst.obj_SA else nil; if ((M3objName session fst.shell_SA) != nil) then M3delObj session fst.shell_SA else nil; set shoot_fifo = remove_from_list shoot_fifo fst; 1; ) else /* the ammo is not arrived yet, continue to make it move */ let _tickcount -> newTick in let newTick - fst.lastTick_SA -> delay in let (delay * gunsLib.(fst.index_SA).ammoDelta_GEL) / pbParams.ammoFramerate_PBP -> delta in let fst.z_SA - fst.curDistance_SA -> rest in let if (rest > delta) then delta else rest -> delta in ( M3movObj session fst.shell_SA [0 0 delta]; set fst.curDistance_SA = fst.curDistance_SA + delta; 1; ); shoot_render nxt; ) ;;