Advertisement
Guest User

Weapon Base Placer Pickups Manager

a guest
Feb 18th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. class WeaponBasePlacerPickupsManager extends Info
  2. placeable;
  3.  
  4. struct PickupsRotationStruct
  5. {
  6. var() class<Weapon> WeaponClass;
  7. var() int Requirement;
  8. var() int StoredResources;
  9. };
  10.  
  11. var() array< PickupsRotationStruct > PickupsRotation;
  12. var() array< int > Max_ISetupUses;
  13. var() bool bRandom;
  14.  
  15. var array< int > SetupUsedCount;
  16. var int iCurrent;
  17. var PickupsRotationStruct NullRotationStruct;
  18.  
  19.  
  20. function PickupsRotationStruct GetRotationStruct()
  21. {
  22. local int i,j,CT,R,F,CS,MaxC; // CT = Chance Total; F = Final Random Value; CS = Current Sum;
  23.  
  24. if (PickupsRotation.length <= 0)
  25. {
  26. log (self $ " Empty");
  27. return NullRotationStruct;
  28. }
  29.  
  30. if (SetupUsedCount.length < PickupsRotation.length)
  31. SetupUsedCount.length = PickupsRotation.length;
  32.  
  33. if (!bRandom)
  34. {
  35. i = iCurrent;
  36. for( j=0; j < PickupsRotation.length; i++ )
  37. {
  38. if (i >= PickupsRotation.length)
  39. i = 0;
  40. if (Max_ISetupUses.length <= i || Max_ISetupUses[i] <= 0 || Max_ISetupUses[i] > SetupUsedCount[i])
  41. {
  42. iCurrent = i + 1;
  43. (SetupUsedCount[i]) ++ ;
  44. return PickupsRotation[i];
  45. }
  46. j++;
  47. }
  48. return NullRotationStruct;
  49. }
  50.  
  51. for( i=0; i < Max_ISetupUses.length; i++ )
  52. if (MaxC < Max_ISetupUses[i])
  53. MaxC = Max_ISetupUses[i];
  54. if (MaxC <= 0)
  55. MaxC = 1;
  56.  
  57. for( i=0; i < PickupsRotation.length; i++ )
  58. if (Max_ISetupUses.length <= i || Max_ISetupUses[i] <= 0)
  59. CT += MaxC;
  60. else
  61. CT += (Max_ISetupUses[i] - SetupUsedCount[i]);
  62.  
  63. if( CT <= 0 )
  64. {
  65. log (self $ " Chance total <= 0 ");
  66. return NullRotationStruct;
  67. }
  68. R = Rand(CT);
  69. F = CT - R;
  70. //log (self $ " Chance Total= " $ CT $ " Final Value= " $ F);
  71. for( i=0; i < PickupsRotation.length; i++ )
  72. {
  73. if (Max_ISetupUses.length <= i || Max_ISetupUses[i] <= 0)
  74. CS += MaxC;
  75. else
  76. CS += (Max_ISetupUses[i] - SetupUsedCount[i]);
  77. if(F <= CS)
  78. {
  79. (SetupUsedCount[i]) ++ ;
  80. return PickupsRotation[i];
  81. }
  82. }
  83. return NullRotationStruct;
  84.  
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement