ijontichy

<stdin>

Mar 28th, 2014
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. function int Dakka_PickupArmor(int whichArmor, int count)
  2. {
  3. int armor = DakkaKnownArmors[whichArmor][0];
  4. int armorMode = DakkaArmorValues[whichArmor][ARM_COMPAREMODE];
  5. int armorType = DakkaArmorValues[whichArmor][ARM_TYPE];
  6. int armorGive = DakkaArmorValues[whichArmor][ARM_PICKUPPOINTS];
  7. int armorMax = DakkaArmorValues[whichArmor][ARM_MAXPOINTS];
  8. int armorRatio = DakkaArmorValues[whichArmor][ARM_PROTECTION];
  9.  
  10. if (armorGive == 0) { return 0; }
  11.  
  12. int fromIndex = getCurrentArmorIndex();
  13. int fromPoints = CheckInventory("Armor");
  14. int fromArmor, fromRatio, fromScore;
  15.  
  16. // If we don't know what armor he has, assume he has none since no other
  17. // assumption would be sensible.
  18.  
  19. if (fromIndex == -1)
  20. {
  21. fromArmor = "";
  22. fromRatio = 0;
  23. fromScore = 0;
  24. }
  25. else
  26. {
  27. fromArmor = DakkaKnownArmors[fromIndex][0];
  28. fromRatio = DakkaArmorValues[fromIndex][ARM_PROTECTION];
  29. fromScore = dak_armorscore(fromRatio, fromPoints, armorMode);
  30. }
  31.  
  32. int toPoints = min(fromPoints + (count * armorGive), armorMax);
  33. int toScore = dak_armorscore(toRatio, toPoints, armorMode);
  34.  
  35. // If we don't actually gain anything from picking up this armor, abort.
  36. if (fromScore >= toScore) { return 0; }
  37.  
  38. int endArmor;
  39.  
  40. /*
  41. * If the player has no known armor at this point, we assume he has no armor.
  42. * The armor he will end up with is the armor being given, without question.
  43. *
  44. * If the player has known armor, and this pickup is considered a bonus,
  45. * the ending armor type is the current armor.
  46. *
  47. * Otherwise, since we've determined that we're gaining something from this
  48. * new armor, the end armor is the armor we're giving.
  49. */
  50.  
  51. if (fromIndex == -1) { endArmor = armor; }
  52. else switch (armorType)
  53. {
  54. case ATYPE_BONUS: endArmor = fromArmor; break;
  55. default: endArmor = armor; break;
  56. }
  57.  
  58. // We now know what armor value we're ending at, and what armor type it is.
  59.  
  60. if (!strcmp(endArmor, fromArmor))
  61. {
  62. GiveInventory("Dakka_OneArmor", toPoints - fromPoints);
  63. }
  64. else
  65. {
  66. TakeInventory("BasicArmor", 0x7FFFFFFF);
  67. GiveInventory(endArmor, 1);
  68.  
  69. int curArmor = CheckInventory("Armor");
  70.  
  71. if (curArmor < endPoints)
  72. {
  73. GiveInventory("Dakka_OneArmor", endPoints - curArmor);
  74. }
  75. else
  76. {
  77. TakeInventory("BasicArmor", curArmor - endPoints);
  78. }
  79. }
  80.  
  81. return 1;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment