/***************************************************************/ /* */ /* PBAMMOS.PKG */ /* */ /* plug-in PaintBall */ /* client - ammos management */ /* */ /* version 5 : Loïc Berthelot, CryoNetworks, dec 2000 */ /* */ /* version 4.5 : Loïc Berthelot nov 2000 */ /* */ /* Photo3 Plugin - DMS - march 00 - by Sylvain HUET */ /* */ /***************************************************************/ /***************************************************************/ /* */ /* DATA STRUCTS : */ /* struct AmmoEl */ /* typeof ammosLib : I */ /* var ammosLibSize : I */ /* typeof ammosShell : H3d */ /* */ /* INTERNAL BODY : */ /* ammos_load : fun [] I */ /* ammos_start2 : fun [] I */ /* ammos_free : fun [] I */ /* */ /* EXTERNAL BODY : */ /* ammos_update : fun [I I] I */ /* ammos_reload : fun [I] I */ /* ammos_destroy : fun [] I */ /* ammos_start : fun [] I */ /* */ /***************************************************************/ /******************************************************************************/ /* */ /* D A T A S T R U C T S */ /* */ /******************************************************************************/ /**********************************************/ /* Struct for ammo element */ /**********************************************/ struct AmmoEl = [ /* m3d file name */ filename_AEL : S, /* if a texture is used, flag == 1 else 0 */ textureFlag_AEL : I, /* 3d object name */ /* (<=> paintBallAmmo1, 2...., 9, 0) */ objname_AEL : S, /* name of ammo */ name_AEL : S, /* 3d object handler, used with your avatar */ obj_AEL : H3d, /* 3d object handler, used with others avatars */ objAv_AEL : H3d, /* scale parameter */ scale_AEL : I, /* scale parameter for others avatars */ scaleAv_AEL : I, /* maximum ammos number */ nbMax_AEL : I, /* current ammos number */ nb_AEL : I, /* clip capacity */ clipCapacity_AEL : I, /* current ammos number in clip */ clipNb_AEL : I, /* power parameter of this ammo */ power_AEL : I ] mkAmmoEl;; /* ammos library */ typeof ammosLib = tab AmmoEl;; var ammosLibSize = 10;; /* shell for ammos library */ typeof ammosShell = H3d;; /******************************************************************************/ /* */ /* I N T E R N A L B O D Y */ /* */ /******************************************************************************/ /**************************************/ /* ammos_load [] I */ /* */ /* load ammos 3d objects */ /**************************************/ fun ammos_load () = let 0 -> i in /* for the whole library */ while (i < ammosLibSize) do ( M3load session ammosLib.(i).filename_AEL ammosShell; set ammosLib.(i).obj_AEL = M3getObj session ammosLib.(i).objname_AEL; if (!ammosLib.(i).textureFlag_AEL) then nil else M3recursFillMatObj session ammosLib.(i).obj_AEL; set ammosLib.(i).objAv_AEL = M3copyObj session ammosLib.(i).obj_AEL; M3setObjScale session ammosLib.(i).obj_AEL ammosLib.(i).scale_AEL; M3setObjScale session ammosLib.(i).objAv_AEL ammosLib.(i).scaleAv_AEL; set pbParams.nbLoadedRessources_PBP = pbParams.nbLoadedRessources_PBP + 1; set i = i+1; ) ;; /**************************************/ /* ammos_start2 */ /* */ /* load ammos library */ /**************************************/ fun ammos_start2 () = let 0 -> i in /* for the whole library */ while (i < ammosLibSize) do ( /* get the m3d ammo file */ let strcatn pbItemsPath::(itoa i)::"/"::pbDefault.ammoItemFln_PBD::nil -> filename in let _checkpack filename -> file in if (file == nil) then ( defines_fofError "photoAmmos.pkg ammos_start2() " filename; 0; ) else /* get ammos parameters in m3d file */ let strextr _getpack file -> content in let getInfo content "texture" -> texture in let if (texture == nil) then 0 else 1 -> textureFlag in let getInfo content pbParamsNames.objName_PBPN -> objname in let getInfo content pbParamsNames.name_PBPN -> name in let atoi getInfo content pbParamsNames.ammoScale_PBPN -> ammoScale in let atoi getInfo content pbParamsNames.ammoAvScale_PBPN -> ammoAvScale in let atoi getInfo content pbParamsNames.nbMaxAmmos_PBPN -> nbMax in let atoi getInfo content pbParamsNames.nbAmmos_PBPN -> nb in let atoi getInfo content pbParamsNames.clipCapacity_PBPN -> clipCapacity in let atoi getInfo content pbParamsNames.power_PBPN -> power in ( if (!textureFlag) then nil else let _checkpack texture -> textureFile in if (textureFile == nil) then ( defines_fofError "photoAmmos.pkg ammos_start2() " filename; 0; ) else nil; /* check parameters */ if (objname != nil) then nil else defines_loadError pbParamsNames.objName_PBPN filename; if (name != nil) then nil else defines_loadError pbParamsNames.name_PBPN filename; if (ammoScale != nil) then nil else defines_loadError pbParamsNames.ammoScale_PBPN filename; if (ammoAvScale != nil) then nil else defines_loadError pbParamsNames.ammoAvScale_PBPN filename; if (nbMax != nil) then nil else defines_loadError pbParamsNames.nbMaxAmmos_PBPN filename; if (nb != nil) then nil else defines_loadError pbParamsNames.nbAmmos_PBPN filename; if (clipCapacity != nil) then nil else defines_loadError pbParamsNames.clipCapacity_PBPN filename; if (power != nil) then nil else defines_loadError pbParamsNames.power_PBPN filename; /* create ammo element in library */ set ammosLib.(i) = mkAmmoEl [filename textureFlag objname name nil nil ammoScale ammoAvScale nbMax nb clipCapacity 0 power]; 1; ); set pbParams.nbLoadedRessources_PBP = pbParams.nbLoadedRessources_PBP + 1; set i = i+1; ); /* load 3d objects */ ammos_load; pbFlags_set "ammos"; 1 ;; /******************************************/ /* ammos_free [] I */ /* */ /* free 3d ressources from the ammos */ /******************************************/ fun ammos_free () = let 0 -> i in while (i < ammosLibSize) do ( if ((M3objName session ammosLib.(i).obj_AEL) != nil) then M3delObj session ammosLib.(i).obj_AEL else nil; set i = i+1; ); 1 ;; /******************************************************************************/ /* */ /* E X T E R N A L B O D Y */ /* */ /******************************************************************************/ /*******************************************/ /* ammos_update [I I] I */ /* */ /* the player has taken a gun or ammo item */ /* update the ammos values */ /*******************************************/ fun ammos_update (index, value) = set ammosLib.(index).nb_AEL = ammosLib.(index).nb_AEL + value; if (ammosLib.(index).nb_AEL > ammosLib.(index).nbMax_AEL) then set ammosLib.(index).nb_AEL = ammosLib.(index).nbMax_AEL else nil; 1 ;; /*******************************************/ /* ammos_reload [I] I */ /* */ /* the player has reload his gun */ /* update the ammos values */ /*******************************************/ fun ammos_reload (index) = let if (ammosLib.(index).nb_AEL < ammosLib.(index).clipCapacity_AEL) then ammosLib.(index).nb_AEL - ammosLib.(index).clipNb_AEL else ammosLib.(index).clipCapacity_AEL - ammosLib.(index).clipNb_AEL -> value in ( set ammosLib.(index).nb_AEL = ammosLib.(index).nb_AEL - value; set ammosLib.(index).clipNb_AEL = ammosLib.(index).clipNb_AEL + value; ); 1 ;; /******************************************/ /* ammos_destroy [] I */ /* */ /* destroy the ammos lib */ /******************************************/ fun ammos_destroy() = ammos_free; if ((M3objName session ammosShell) != nil) then M3delObj session ammosShell else nil; 1 ;; /******************************************/ /* ammos_start [] I */ /* */ /* construct the ammos library */ /******************************************/ fun ammos_start () = set ammosShell = M3createShell session; set ammosLib = mktab ammosLibSize nil; ammos_start2; 1 ;;