/***************************************************************/ /* */ /* PBIMPACTS.PKG */ /* */ /* plug-in PhotoPaintBall */ /* client - impacts of ammos management */ /* */ /* version 5 : Loïc Berthelot, dec 2000 */ /* */ /* nouvelle version 4.5 : Loïc Berthelot nov 2000 */ /* avec l'aide de Olivier Lamotte */ /* */ /* Photo3 Plugin - DMS - march 00 - by Sylvain HUET */ /* */ /***************************************************************/ /***************************************************************/ /* */ /* */ /* DATA STRUCTS : */ /* struct SpotsLibEl */ /* struct SpotsEl */ /* struct AvImpacts */ /* struct ImpactLib */ /* typeof impactsLib : tab ImpactLib */ /* var impactsLibSize : I */ /* */ /* */ /* INTERNAL BODY : */ /* impacts_leftShift : fun [Pb] I */ /* impacts_load : fun [I] I */ /* impacts_start2 : fun [] I */ /* */ /* */ /* EXTERNAL BODY : */ /* impacts_emptySpot : fun [Pb] I */ /* impacts_removeSpot : fun [Pb] I */ /* impacts_insertSpot : fun [Pb SpotsEl] I */ /* impacts_free : fun [I] I */ /* impacts_destroy : fun [] I */ /* impacts_start : fun [] I */ /* */ /* */ /***************************************************************/ /******************************************************************************/ /* */ /* D A T A S T R U C T S */ /* */ /******************************************************************************/ /* SpotsLib Element */ /* */ /* instead of storing a spot */ /* in a bitmap, storing it with */ /* coordinates and parameters, and */ /* make it appear during the */ /* postrender action. */ struct SpotsLibEl = [ /* coord in bitmap */ x_SLel : I, /* width */ w_SLel : I, /* height */ h_SLel : I ] mkSpotsLibEl;; /* Spots Element */ /* */ /* a spot, with application */ /* parameters. */ struct SpotsEl = [ /* id in library */ index_Sel : I, /* spot itself */ spot_Sel : SpotsLibEl, /* x position on texture */ x_Sel : I, /* y position on texture */ y_Sel : I, /* decal texture */ decal : I ] mkSpotsEl;; /* avatar impacts tab */ /* */ /* tab of spots, each avatar has his */ struct AvImpacts = [ /* spots tab */ spots_AI : tab SpotsEl, /* constante max size of tab */ length_AI : I, /* current size of tab */ allocatedSize_AI : I ] mkAvImpacts;; /* Impacts Library */ /* */ /* set of all impacts tab, */ /* each one for a gun. */ /* id in the tab <=> id of the gun */ struct ImpactLib = [ /* alphabitmap filename */ fln_IL : S, /* objbitmap containing all spots */ bmp_IL : ObjBitmap, /* transparency color */ tc_IL : I, /* library tab for screen surface */ /* length == 5 */ /* <=> 5 different sizes */ screenlib_IL : tab SpotsLibEl, /* <=> 5 */ screenlibSize_IL : I, /* library tab for avatars textures */ /* length == 5 */ /* <=> 5 diffrent sizes */ avatarlib_IL : tab SpotsLibEl, /* <=> 5 */ avatarlibSize_IL : I ] mkImpactLib;; /* set of impact librarys */ /* size == 10 */ /* 10 different guns <=> 10 librarys */ typeof impactsLib = tab ImpactLib;; var impactsLibSize = 10;; /******************************************************************************/ /* */ /* I N T E R N A L B O D Y */ /* */ /******************************************************************************/ /******************************************/ /* impacts_leftShift [Pb] I */ /* */ /* do a left shift on the AvImpacts items */ /******************************************/ fun impacts_leftShift (p) = let 0 -> i in let p.ai_PB.allocatedSize_AI - 1 -> maxIndex in let p.ai_PB.spots_AI -> myTab in ( while (i < maxIndex) do ( set p.ai_PB.spots_AI.(i) = p.ai_PB.spots_AI.(i+1); set i = i+1; ); set p.ai_PB.spots_AI.(maxIndex) = nil; ) ;; /****************************************/ /* impacts_load [I] I */ /* */ /* load the library, identified by */ /* index. return 1 if ok, 0 if ko */ /****************************************/ fun impacts_load (index) = let _checkpack impactsLib.(index).fln_IL -> file in let _LDalphaBitmap _channel file -> aBmp in let _GETalphaBitmaps aBmp -> [bmp _] in let _GETbitmapSize bmp -> [w h] in let _GETpixel16 bmp 0 0 -> tc in let _CRbitmap _channel 1200 400 -> wholeBitmap in /* constr. screenSpotsLibrary */ let 0 -> x0 in let _SCPbitmap wholeBitmap x0 0 (400-1) (400-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 400 -> x1 in let _SCPbitmap wholeBitmap x1 0 (700-1) (300-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 700 -> x2 in let _SCPbitmap wholeBitmap x2 0 (900-1) (200-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 900 -> x3 in let _SCPbitmap wholeBitmap x3 0 (1000-1) (100-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 1000 -> x4 in let _SCPbitmap wholeBitmap x4 0 (1050-1) (50-1) bmp 0 0 (w-1) (h-1) nil -> tmp in /* constr avatarSpotsLibrary */ let 1050 -> x5 in let _SCPbitmap wholeBitmap x5 0 (1100-1) (50-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 1100 -> x6 in let _SCPbitmap wholeBitmap x6 0 (1140-1) (40-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 1140 -> x7 in let _SCPbitmap wholeBitmap x7 0 (1170-1) (30-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 1170 -> x8 in let _SCPbitmap wholeBitmap x8 0 (1190-1) (20-1) bmp 0 0 (w-1) (h-1) nil -> tmp in let 1190 -> x9 in let _SCPbitmap wholeBitmap x9 0 (1200-1) (10-1) bmp 0 0 (w-1) (h-1) nil -> tmp in ( _DSbitmap bmp; _DSalphaBitmap aBmp; set impactsLib.(index).bmp_IL = wholeBitmap; set impactsLib.(index).tc_IL = tc; set impactsLib.(index).screenlib_IL.(0) = mkSpotsLibEl [x0 400 400]; set impactsLib.(index).screenlib_IL.(1) = mkSpotsLibEl [x1 300 300]; set impactsLib.(index).screenlib_IL.(2) = mkSpotsLibEl [x2 200 200]; set impactsLib.(index).screenlib_IL.(3) = mkSpotsLibEl [x3 100 100]; set impactsLib.(index).screenlib_IL.(4) = mkSpotsLibEl [x4 50 50]; set impactsLib.(index).avatarlib_IL.(0) = mkSpotsLibEl [x5 50 50]; set impactsLib.(index).avatarlib_IL.(1) = mkSpotsLibEl [x6 40 40]; set impactsLib.(index).avatarlib_IL.(2) = mkSpotsLibEl [x7 30 30]; set impactsLib.(index).avatarlib_IL.(3) = mkSpotsLibEl [x8 20 20]; set impactsLib.(index).avatarlib_IL.(4) = mkSpotsLibEl [x9 10 10]; ); 1 ;; /********************************************/ /* impacts_start2 [] I */ /* */ /* start the library */ /********************************************/ fun impacts_start2 () = let 0 -> i in /* for all librarys */ while (i < impactsLibSize) do ( /* get alphabitmap impact filename */ let strcatn pbItemsPath::(itoa i)::"/"::pbDefault.impactBmpFln_PBD::nil -> filename in let _checkpack filename -> file in if (file == nil) then ( defines_fofError "photoImpacts.pkg impacts_start2() " filename; 0; ) else ( set impactsLib.(i) = mkImpactLib [filename nil nil (mktab 5 nil) 5 (mktab 5 nil) 5]; /* load this library */ impacts_load i; 1; ); set i = i+1; ); pbFlags_set "impacts"; 1 ;; /******************************************************************************/ /* */ /* E X T E R N A L B O D Y */ /* */ /******************************************************************************/ /********************************************/ /* impacts_emptySpot [Pb] I */ /* */ /* empty the avatar's spot tab */ /********************************************/ fun impacts_emptySpots (p) = if (p.ai_PB.allocatedSize_AI == 0) then nil else ( set p.ai_PB.allocatedSize_AI = 0; let 0 -> i in while (i < p.ai_PB.length_AI) do ( set p.ai_PB.spots_AI.(i) = nil; set i = i+1; ); 1; ) ;; /********************************************/ /* impacts_removeSpot [Pb] I */ /* */ /* remove the first item from spots tab */ /* of avImpacts and do a leftShift */ /********************************************/ fun impacts_removeSpot (p) = if (p.ai_PB.allocatedSize_AI == 0) then nil else ( let p.ai_PB.spots_AI.(0) -> item in ( set pbFlags.lock_PBF = 1; impacts_leftShift p; set p.ai_PB.allocatedSize_AI = p.ai_PB.allocatedSize_AI - 1; set pbFlags.lock_PBF = 0; 1; ); ) ;; /****************************************/ /* impacts_insertSpot[Pb SpotsEl] I */ /* */ /* insert a spot in a photoPB spots Tab */ /* return the id of inserted spot */ /****************************************/ fun impacts_insertSpot (p, spot) = if (p.ai_PB.allocatedSize_AI == p.ai_PB.length_AI) then /* the whole tab is full */ /* remove the older item */ /* and shift the tab */ impacts_removeSpot p else nil; if (!pbFlags.lock_PBF) then ( /* _DLGMessageBox _channel DMSwin "INSERT" "InsertSpot" 0;*/ let p.ai_PB.allocatedSize_AI -> index in ( /* insert the spot */ set p.ai_PB.spots_AI.(index) = spot; /* incr. the allocated size */ set p.ai_PB.allocatedSize_AI = p.ai_PB.allocatedSize_AI + 1; index; ); ) else nil ;; /****************************************/ /* impacts_free [I] I */ /* */ /* destroy the library, identified by */ /* index. */ /****************************************/ fun impacts_free (index) = _DSbitmap impactsLib.(index).bmp_IL; 1 ;; /****************************************/ /* impacts_destroy [] I */ /* */ /* destroy all librarys */ /****************************************/ fun impacts_destroy () = let 0 -> i in while (i < impactsLibSize) do ( impacts_free i; set i = i+1; ); set impactsLib = nil; 1 ;; /****************************************/ /* impacts_start [] I */ /* */ /* construct the library tab, check the */ /* librarys files. */ /****************************************/ fun impacts_start () = set impactsLib = mktab impactsLibSize nil; impacts_start2; 1 ;;