ijontichy

level.c

Jun 12th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 19.67 KB | None | 0 0
  1. #include "zcommon.acs"
  2. #library "level"
  3.  
  4. #include "unlockNames.h"
  5. #include "unlockFuncs.h"
  6. #include "unlocks.h"
  7.  
  8.  
  9. global int 3:inGame[];
  10. global int 4:unlocksLeft[];
  11. global int 5:startStats[];
  12. global int 6:unlocksPerPlayer[];
  13.  
  14. int uMenuLock[32];
  15. int hasEntered[32];
  16. int nagForMenu[32];
  17.  
  18. function int getName(int num)
  19. {
  20.     return unlockNames[num];
  21. }
  22.  
  23. function int getMax(int num)
  24. {
  25.     return unlockables[num][8];
  26. }
  27.  
  28. function int getCost(int num)
  29. {
  30.     return unlockables[num][13];
  31. }
  32.  
  33. function void payForUnlock(int pln, int num)
  34. {
  35.     int subAmount = unlockables[num][13];
  36.  
  37.     unlocksLeft[pln] = max(unlocksLeft[pln] - subAmount, 0);
  38. }
  39.  
  40. function int getUnlock(int pln, int num)
  41. {
  42.     int i = (pln * UNLOCK_COUNT) + num;
  43.     return unlocksPerPlayer[i];
  44. }
  45.  
  46. function void setUnlock(int pln, int num, int value)
  47. {
  48.     int i = (pln * UNLOCK_COUNT) + num;
  49.     unlocksPerPlayer[i] = value;
  50. }
  51.  
  52. function void addUnlock(int pln, int num, int value)
  53. {
  54.     int i = (pln * UNLOCK_COUNT) + num;
  55.     unlocksPerPlayer[i] += value;
  56. }
  57.  
  58. function void applyUnlock(int pln, int num)
  59. {
  60.     int s  = unlockables[num][0];
  61.  
  62.     if (s == -1)
  63.     {
  64.         return;
  65.     }
  66.     else if (s < 0 || s > 999)
  67.     {
  68.         Log(s:"ERROR: Unlock \"", s:getName(num), s:"\" has apply script ", d:s, s:", which makes no sense");
  69.         return;
  70.     }
  71.  
  72.     int a1 = unlockables[num][1];
  73.     int a2 = unlockables[num][2];
  74.     int a3 = unlockables[num][3];
  75.  
  76.     ACS_ExecuteAlways(s, 0, a1,a2,a3);
  77. }
  78.  
  79. function void unlockUnlock(int pln, int num)
  80. {
  81.     if (!checkUnlock(pln, num, 0))
  82.     {
  83.         return;
  84.     }
  85.  
  86.     int s  = unlockables[num][4];
  87.  
  88.     if (s < 0 || s > 999)
  89.     {
  90.         Log(s:"ERROR: Unlock \"", s:getName(num), s:"\" has unlock script ", d:s, s:", which makes no sense");
  91.         return;
  92.     }
  93.  
  94.     int a1 = unlockables[num][5];
  95.     int a2 = unlockables[num][6];
  96.     int a3 = unlockables[num][7];
  97.  
  98.     addUnlock(pln, num, 1);
  99.  
  100.     ACS_ExecuteAlways(s, 0, a1,a2,a3);
  101. }
  102.  
  103. function int checkUnlock(int pln, int num, int quiet)
  104. {
  105.     // THIS IS WHY FUNCTIONS NEED SCOPE
  106.     SetHudSize(640, 480, 1);
  107.  
  108.     int s  = unlockables[num][9];
  109.     int ret; int diff; int addS = "";
  110.  
  111.     if (getMax(num) <= getUnlock(pln, num) && getMax(num) != -1 )
  112.     {
  113.         if (!quiet)
  114.         {
  115.                 HudMessage(s:"Already at max";
  116.                 HUDMSG_FADEOUT, UNLOCK_HBASE3, CR_BRICK, 220.4, 130.1 + (MENU_SIZE * MENU_SPACING),
  117.                     2.0, 1.0);
  118.         }
  119.         return false;
  120.     }
  121.  
  122.     if (s == -1)
  123.     {
  124.         ret = 1;
  125.     }
  126.     else if (s < 0 || s > 999)
  127.     {
  128.         Log(s:"ERROR: Unlock \"", s:getName(num), s:"\" has check script ", d:s, s:", which makes no sense");
  129.         return false;
  130.     }
  131.  
  132.     int a1 = unlockables[num][10];
  133.     int a2 = unlockables[num][11];
  134.     int a3 = unlockables[num][12];
  135.  
  136.     if (quiet)  // Assume negative a2 means 'quiet'
  137.     {
  138.         a2 = -a2;
  139.     }
  140.  
  141.     if (ret != 1)  // if there's an unlock script
  142.     {
  143.         ret = ACS_ExecuteWithResult(s, a1,a2,a3);
  144.     }
  145.  
  146.     if (ret == 1 && (getCost(num) > unlocksLeft[pln]))
  147.     {
  148.         diff = getCost(num) - unlocksLeft[pln];
  149.  
  150.         if (diff != 1)
  151.         {
  152.             addS = "s";
  153.         }
  154.  
  155.         if (!quiet)
  156.         {
  157.             HudMessage(s:"Need \cd", d:diff, s:"\c- more unlock", s:addS;
  158.                 HUDMSG_FADEOUT, UNLOCK_HBASE3, CR_BRICK, 220.4, 130.1 + (MENU_SIZE * MENU_SPACING),
  159.                     2.0, 1.0);
  160.         }
  161.         return false;
  162.     }
  163.  
  164.     return ret;
  165. }
  166.  
  167.  
  168. function void giveHealth(int amount)
  169. {
  170.     int curHP = GetActorProperty(0, APROP_Health);
  171.     int newHP = middle(curHP, curHP+amount, GetActorProperty(0, APROP_SpawnHealth));
  172.     SetActorProperty(0, APROP_Health, newHP);
  173. }
  174.  
  175.  
  176. function int getStat(int pln, int which)
  177. {
  178.     return startStats[(pln * STAT_COUNT) + which];
  179. }
  180.  
  181. function void setStat(int pln, int which, int value)
  182. {
  183.     startStats[(pln * STAT_COUNT) + which] = value;
  184. }
  185.  
  186. function void addStat(int pln, int which, int value)
  187. {
  188.     startStats[(pln * STAT_COUNT) + which] += value;
  189. }
  190.  
  191. function int getArmorIndex(void)
  192. {
  193.     int pln = PlayerNumber();
  194.     int i;
  195.  
  196.     for (i = 0; i < UNLOCK_ARMORCOUNT; i++)
  197.     {
  198.         if (GetArmorType(unlockArmors[i], pln) )
  199.         {
  200.             return i;
  201.         }
  202.     }
  203.  
  204.     return -1;
  205. }
  206.  
  207. function int oneUnlocked(int pln, int quiet)
  208. {
  209.     int i;
  210.  
  211.     for (i = 0; i < UNLOCK_COUNT; i++)
  212.     {
  213.         if (checkUnlock(pln, i, quiet))
  214.         {
  215.             return 1;
  216.         }
  217.     }
  218.  
  219.     return 0;
  220. }
  221.  
  222. function void printMenuItem(int pln, int pos, int which, int selected)
  223. {
  224.     int nameColor; int maxColor; int curColor; int costColor;
  225.  
  226.     int left    = unlocksLeft[pln];
  227.     int name    = getName(which);
  228.     int l_max   = getMax(which);
  229.     int cost    = getCost(which);
  230.     int current = getUnlock(pln, which);
  231.  
  232.     if (selected == which)
  233.     {
  234.         maxColor = CR_LIGHTBLUE;
  235.         costColor = CR_TAN;
  236.  
  237.         if (l_max == current) { curColor = CR_RED; }
  238.         else                  { curColor = CR_GREEN; }
  239.  
  240.         if (checkUnlock(pln, which, 1)) { nameColor = CR_GOLD; }
  241.         else                        { nameColor = CR_DARKGREY; }
  242.  
  243.     }
  244.     else
  245.     {
  246.         maxColor = CR_BLUE;
  247.         costColor = CR_BROWN;
  248.  
  249.         if (l_max == current) { curColor = CR_DARKRED; }
  250.         else                  { curColor = CR_DARKGREEN; }
  251.  
  252.         if (checkUnlock(pln, which, 1)) { nameColor = CR_YELLOW; }
  253.         else                        { nameColor = CR_BLACK; }
  254.     }
  255.  
  256.     // For convenience
  257.     int FIELDBASE   = UNLOCK_HBASE + (4 * pos);
  258.     int POS_Y       = (MENU_SPACING * pos) + 110.1;
  259.     int REFRESHRATE = ((MENU_REFRESH << 16) / 35) + 2.0;
  260.  
  261.     HudMessage(s:name; HUDMSG_FADEOUT, FIELDBASE, nameColor, 215.2, POS_Y, REFRESHRATE, 2.0);
  262.  
  263.     if (l_max == -1)
  264.     {
  265.         HudMessage(s:"---"; HUDMSG_FADEOUT, FIELDBASE + 1, maxColor, 245.4, POS_Y, REFRESHRATE, 2.0);
  266.     }
  267.     else
  268.     {
  269.         HudMessage(d:l_max; HUDMSG_FADEOUT, FIELDBASE + 1, maxColor, 245.4, POS_Y, REFRESHRATE, 2.0);
  270.     }
  271.  
  272.     if (l_max == current)
  273.     {
  274.         HudMessage(s:"MAX"; HUDMSG_FADEOUT, FIELDBASE + 2, curColor, 275.4, POS_Y, REFRESHRATE, 2.0);
  275.     }
  276.     else
  277.     {
  278.         HudMessage(d:current; HUDMSG_FADEOUT, FIELDBASE + 2, curColor, 275.4, POS_Y, REFRESHRATE, 2.0);
  279.     }
  280.  
  281.     HudMessage(d:cost; HUDMSG_FADEOUT, FIELDBASE + 3, costColor, 305.4, POS_Y, REFRESHRATE, 2.0);
  282. }
  283.  
  284.  
  285.  
  286.  
  287. script UNLOCK_ENTER enter
  288. {
  289.     int pln = PlayerNumber();
  290.     int i; int hp; int weps; int wepName;
  291.  
  292.     hasEntered[pln] = 1;
  293.     GiveInventory("EndSpawnProtection", 1);
  294.  
  295.     if (!inGame[pln])
  296.     {
  297.         inGame[pln] = 1;
  298.  
  299.         // I'm lazy
  300.         for (i = 0; i < STAT_COUNT; i++)
  301.         {
  302.             setStat(pln, i, 0);
  303.         }
  304.  
  305.         setStat(pln, STAT_LEVEL, 1);
  306.         setStat(pln, STAT_NEXTL, 250);
  307.         unlocksLeft[pln] = 1;
  308.  
  309.         hp = GetActorProperty(0, APROP_SpawnHealth);
  310.  
  311.         if (hp != 0)
  312.         {
  313.             setStat(pln, STAT_HP, hp);
  314.         }
  315.         else
  316.         {
  317.             setStat(pln, STAT_HP, 100);
  318.             SetActorProperty(0, APROP_SpawnHealth, 100);
  319.         }
  320.        
  321.         ACS_ExecuteAlways(UNLOCK_HOOK_ENTER, 0, 0,0,0);
  322.     }
  323.  
  324.     ACS_ExecuteAlways(UNLOCK_LEVELHUD, 0, 0,0,0);
  325.     ACS_ExecuteAlways(UNLOCK_HOOK_DAEMON, 0, 0,0,0);
  326. }
  327.  
  328. script UNLOCK_RESPAWN respawn
  329. {
  330.     int i;
  331.     int pln = PlayerNumber();
  332.  
  333.     if (!hasEntered[pln])   // wasn't in the game - do ENTER
  334.     {
  335.         ACS_ExecuteAlways(UNLOCK_ENTER, 0, 0,0,0);
  336.     }
  337.  
  338.     if (GetActorProperty(0, APROP_SpawnHealth) == 0)
  339.     {
  340.         SetActorProperty(0, APROP_SpawnHealth, 100);
  341.     }
  342.  
  343.     for (i = 0; i < UNLOCK_COUNT; i++)
  344.     {
  345.         applyUnlock(pln, i);
  346.     }
  347.  
  348.     ACS_ExecuteAlways(UNLOCK_HOOK_RESPAWN, 0, 0,0,0);
  349. }
  350.  
  351. script UNLOCK_DISCONNECT (int pln) disconnect
  352. {
  353.     int i;
  354.     for (i = 0; i < STAT_COUNT; i++)
  355.     {
  356.         setStat(pln, i, 0);
  357.     }
  358. }
  359.  
  360. script UNLOCK_MENU (int alwaysShow)
  361. {
  362.     int pln = PlayerNumber();
  363.  
  364.     int i; int j;
  365.     int refresh; int top;
  366.     int tic; int left; int oLeft;
  367.     int name; int current; int cost;
  368.     int msgColor;
  369.  
  370.     int selected;
  371.     int oSelected;
  372.  
  373.     int usekey; int upkey; int downkey;
  374.     int useScr = MENU_USESPEED;
  375.     int upScr = MENU_UPSPEED;
  376.     int downScr = MENU_DOWNSPEED;
  377.  
  378.     if (uMenuLock[pln] == 1)
  379.     {
  380.         uMenuLock[pln] = 2;
  381.         GiveInventory("EndSpawnProtection", 1);
  382.         terminate;
  383.     }
  384.  
  385.     SetHudSize(640, 480, 1);
  386.  
  387.     uMenuLock[pln] = 1;
  388.     nagForMenu[pln] = -1;
  389.  
  390.     if (!alwaysShow) { GiveInventory("SpawnProtection", 1); }
  391.  
  392.     // Mainloop
  393.     while (oneUnlocked(pln, 1) || alwaysShow)
  394.     {
  395.         left = unlocksLeft[pln];
  396.  
  397.         if ((!left && !alwaysShow) || uMenuLock[pln] == 2) { break; }
  398.  
  399.         GiveInventory("SpawnStop", 1);
  400.  
  401.         if (keyDown(BT_USE))
  402.         {
  403.             if (usekey == -1)
  404.             {
  405.                 usekey = useScr;
  406.                 useScr = max(1, useScr - 1);
  407.  
  408.                 if (selected == UNLOCK_COUNT)
  409.                 {
  410.                     break;
  411.                 }
  412.  
  413.                 if (checkUnlock(pln, selected, 0))
  414.                 {
  415.                     unlockUnlock(pln, selected);
  416.                     payForUnlock(pln, selected);
  417.                     refresh = 1;
  418.                 }
  419.             }
  420.         }
  421.         else
  422.         {
  423.             usekey = 0;
  424.             useScr = MENU_USESPEED;
  425.         }
  426.  
  427.         // Begin scrolling
  428.         if (keyDown(BT_FORWARD))
  429.         {
  430.             if (upkey == -1)
  431.             {
  432.                 upkey = upScr;
  433.                 upScr = max(1, upScr - 1);
  434.             }
  435.         }
  436.         else
  437.         {
  438.             upkey = 0;
  439.             upScr = MENU_UPSPEED;
  440.         }
  441.  
  442.         if (keyDown(BT_BACK))
  443.         {
  444.             if (downkey == -1)
  445.             {
  446.                 downkey = downScr;
  447.                 downScr = max(1, downScr - 1);
  448.             }
  449.         }
  450.         else
  451.         {
  452.             downkey = 0;
  453.             downScr = MENU_DOWNSPEED;
  454.         }
  455.  
  456.         if (upScr == 1) { selected -= (upkey / upScr); }
  457.         else { selected -= (upkey / (upScr + 1)); }
  458.  
  459.         if (downScr == 1) { selected += (downkey / downScr); }
  460.         else { selected += (downkey / (downScr + 1)); }
  461.         // End scrolling
  462.  
  463.         selected = mod(selected, UNLOCK_COUNT+1);
  464.  
  465.         if ((tic % MENU_REFRESH == 0) || (oSelected != selected) || (oLeft != left) || (refresh))
  466.         {
  467.             tic = 0;
  468.             refresh = 0;
  469.  
  470.             if (selected == UNLOCK_COUNT)
  471.             {
  472.                 top = adjustBottom(top, top+MENU_SIZE-1, 0);
  473.             }
  474.             else
  475.             {
  476.                 top = adjustBottom(top, top+MENU_SIZE-1, selected);
  477.             }
  478.  
  479.             SetFont("BIGFONT");
  480.  
  481.             HudMessage(s:"UNLOCK MENU";
  482.                 HUDMSG_FADEOUT, UNLOCK_HBASE - 1, CR_WHITE, 220.4, 34.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  483.  
  484.             SetFont("SMALLFONT");
  485.  
  486.             if (top > 0)
  487.             {
  488.                 HudMessage(s:"/\\";
  489.                         HUDMSG_FADEOUT, UNLOCK_HBASE - 5, CR_GOLD, 320.4, 100.1,
  490.                         ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  491.             }
  492.             else
  493.             {
  494.                 HudMessage(s:"";
  495.                         HUDMSG_FADEOUT, UNLOCK_HBASE - 5, CR_GOLD, 320.4, 100.1,
  496.                         ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  497.             }
  498.  
  499.             if (top < UNLOCK_COUNT-MENU_SIZE)
  500.             {
  501.                 HudMessage(s:"\\/";
  502.                         HUDMSG_FADEOUT, UNLOCK_HBASE - 6, CR_GOLD, 320.4, 110.1 + (MENU_SIZE * MENU_SPACING),
  503.                         ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  504.             }
  505.             else
  506.             {
  507.                 HudMessage(s:"";
  508.                         HUDMSG_FADEOUT, UNLOCK_HBASE - 6, CR_GOLD, 320.4, 110.1,
  509.                         ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  510.             }
  511.  
  512.  
  513.             // For convenience
  514.             int FIELDBASE   = UNLOCK_HBASE - 100;
  515.             int POS_Y       = 84.1;
  516.             int REFRESHRATE = ((MENU_REFRESH << 16) / 35) + 2.0;
  517.  
  518.             HudMessage(s:"Name";    HUDMSG_FADEOUT, FIELDBASE,     CR_GOLD,      155.4, POS_Y+10.0, REFRESHRATE, 2.0);
  519.             HudMessage(s:"Max";     HUDMSG_FADEOUT, FIELDBASE - 1, CR_LIGHTBLUE, 245.4, POS_Y,      REFRESHRATE, 2.0);
  520.             HudMessage(s:"Current"; HUDMSG_FADEOUT, FIELDBASE - 2, CR_GREEN,     275.4, POS_Y+10.0, REFRESHRATE, 2.0);
  521.             HudMessage(s:"Cost";    HUDMSG_FADEOUT, FIELDBASE - 3, CR_TAN,       305.4, POS_Y,      REFRESHRATE, 2.0);
  522.  
  523.  
  524.             HudMessage(s:"\cf", k:"+forward", s:"\c- scrolls up, \cf", k:"+back", s:"\c- down, \cf", k:"+use", s:"\c- selects, \cf", k:"unlockmenu", s:"\c- exits";
  525.                     HUDMSG_FADEOUT, UNLOCK_HBASE - 3, CR_GREEN, 220.4, 50.1,
  526.                     ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  527.  
  528.             // (x of y)
  529.             HudMessage(s:"\(\cd", d:mod(selected+1, UNLOCK_COUNT+1), s:"\c- of \cf", d:UNLOCK_COUNT, s:"\c-)";
  530.                     HUDMSG_FADEOUT, UNLOCK_HBASE - 4, CR_DARKGREY, 220.4, 110.1 + (MENU_SIZE * MENU_SPACING),
  531.                     ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  532.  
  533.  
  534.  
  535.             if (selected == UNLOCK_COUNT) { msgColor = CR_BRICK; }
  536.             else                          { msgColor = CR_WHITE; }
  537.  
  538.             HudMessage(s:"Exit unlock menu";
  539.                 HUDMSG_FADEOUT, UNLOCK_HBASE - 2, msgColor, 220.4, 70.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  540.  
  541.             if (selected == UNLOCK_COUNT)
  542.             {
  543.                 HudMessage(s:"";
  544.                     HUDMSG_FADEOUT, UNLOCK_HBASE - 8, CR_BRICK, 440.4, 240.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  545.  
  546.                 HudMessage(s:"";
  547.                     HUDMSG_FADEOUT, UNLOCK_HBASE - 9, CR_BRICK, 440.4, 240.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  548.             }
  549.             else
  550.             {
  551.                 if (unlockQuotes[selected] != "")
  552.                 {
  553.                     HudMessage(s:"\"", s:unlockQuotes[selected], s:"\"";
  554.                         HUDMSG_FADEOUT, UNLOCK_HBASE - 8, CR_GOLD, 440.4, 250.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  555.                 }
  556.                 else
  557.                 {
  558.                     HudMessage(s:"";
  559.                         HUDMSG_FADEOUT, UNLOCK_HBASE - 8, CR_GOLD, 440.4, 250.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  560.                 }
  561.  
  562.                 HudMessage(s:unlockDescriptions[selected];
  563.                     HUDMSG_FADEOUT, UNLOCK_HBASE - 9, CR_BRICK, 440.4, 265.1, ((MENU_REFRESH << 16) / 35) + 2.0, 2.0);
  564.             }
  565.  
  566.             for (i = 0; i < min(MENU_SIZE, UNLOCK_COUNT); i++)
  567.             {
  568.                 j = mod(i + top, UNLOCK_COUNT);
  569.                 printMenuItem(pln, i, j, selected);
  570.             }
  571.         }
  572.  
  573.         tic++;
  574.         oLeft     = left;
  575.         oSelected = selected;
  576.         usekey--; upkey--; downkey--;
  577.  
  578.         Delay(1);
  579.     }
  580.  
  581.     GiveInventory("EndSpawnProtection", 1);
  582.     nagForMenu[pln] = 0;
  583.     uMenuLock[pln] = 0;
  584. }
  585.  
  586.  
  587. script UNLOCK_LEVELHUD (void)
  588. {
  589.     int pln = PlayerNumber();
  590.     int tic;
  591.     int xp; int oXp;
  592.     int level; int oLevel;
  593.     int nextLevel; int oNextLevel;
  594.     int left; int oLeft;
  595.  
  596.     SetHudSize(640, 480, 1);
  597.     SetFont("BIGFONT");
  598.  
  599.     while (PlayerInGame(pln))
  600.     {
  601.         oXp = xp;
  602.         xp = getStat(pln, STAT_XP);
  603.  
  604.         oLevel = level;
  605.         level = getStat(pln, STAT_LEVEL);
  606.  
  607.         oNextLevel = nextLevel;
  608.         nextLevel = getStat(pln, STAT_NEXTL);
  609.  
  610.         oLeft = left;
  611.         left = unlocksLeft[pln];
  612.  
  613.         if ((tic % HUD_REFRESH) == 0 || (xp != oXp) || (level != oLevel) || (nextLevel != oNextLevel) || (left != oLeft))
  614.         {
  615.             SetFont("BIGFONT");
  616.             HudMessage(s:"Level \ck", d:level;
  617.                 HUDMSG_FADEOUT, UNLOCK_HBASE2 + 1, CR_GREY, 480.1, 110.2, ((HUD_REFRESH << 16) / 35) + 2.0, 2.0);
  618.  
  619.             HudMessage(s:"/";
  620.                 HUDMSG_FADEOUT, UNLOCK_HBASE2 + 4, CR_DARKRED, 554.4, 145.2, ((HUD_REFRESH << 16) / 35) + 2.0, 2.0);
  621.  
  622.             SetFont("SMALLFONT");
  623.             HudMessage(s:"XP: \cd", d:xp;
  624.                 HUDMSG_FADEOUT, UNLOCK_HBASE2 + 2, CR_WHITE, 510.1, 140.2, ((HUD_REFRESH << 16) / 35) + 2.0, 2.0);
  625.  
  626.             HudMessage(d:nextLevel;
  627.                 HUDMSG_FADEOUT, UNLOCK_HBASE2 + 3, CR_GREEN, 555.1, 151.2, ((HUD_REFRESH << 16) / 35) + 2.0, 2.0);
  628.  
  629.             HudMessage(s:"\cf", d:left, s:"\c- left";
  630.                 HUDMSG_FADEOUT, UNLOCK_HBASE2 + 5, CR_TAN,  555.2, 125.2, ((HUD_REFRESH << 16) / 35) + 2.0, 2.0);
  631.  
  632.             tic = 0;
  633.         }
  634.  
  635.         tic++;
  636.         Delay(1);
  637.     }
  638. }
  639.  
  640. script UNLOCK_NAG (void)
  641. {
  642.     int pln = PlayerNumber();
  643.  
  644.     if (PlayerIsBot(pln))
  645.     {
  646.         while (unlocksLeft[pln] != 0)
  647.         {
  648.             int selected = Random(0, UNLOCK_COUNT);
  649.  
  650.             while (!checkUnlock(pln, selected, 1))
  651.             {
  652.                 selected = Random(0, UNLOCK_COUNT);
  653.             }
  654.  
  655.             unlocksLeft[pln]--;
  656.             unlockUnlock(pln, selected);
  657.  
  658.             Delay(1);
  659.         }
  660.     }
  661.  
  662.     SetHudSize(640, 480, 1);
  663.  
  664.     if (nagForMenu[pln] == 1) { terminate; }
  665.  
  666.     if (nagForMenu[pln] == -1)
  667.     {
  668.         HudMessage(s:"You leveled up!";
  669.             HUDMSG_FADEOUT, UNLOCK_HBASE2 + 50, CR_GOLD, 320.4, 30.2, 0.5, 1.0);
  670.  
  671.         terminate;
  672.     }
  673.  
  674.     nagForMenu[pln] = 1;
  675.  
  676.     while (nagForMenu[pln] == 1)
  677.     {
  678.         HudMessage(s:"You leveled up! Press \ck\"", k:"unlockmenu", s:"\"\c- to use it";
  679.             HUDMSG_FADEOUT, UNLOCK_HBASE2 + 50, CR_GOLD, 320.4, 30.2, 0.2, 1.0);
  680.  
  681.         Delay(35);
  682.     }
  683. }
  684.  
  685. script LEVEL_ADDXP (int pln, int addXP)
  686. {
  687.     if (pln == -1)
  688.     {
  689.         pln = PlayerNumber();
  690.     }
  691.  
  692.     addStat(pln, STAT_XP, addXP);
  693.     addStat(pln, STAT_TOTALXP, addXP);
  694.     ACS_ExecuteAlways(LEVEL_RECALC, 0, pln, 0,0);
  695. }
  696.  
  697. script LEVEL_RECALC (int pln)
  698. {
  699.     int xp     = getStat(pln, STAT_XP);
  700.     int level  = getStat(pln, STAT_LEVEL);
  701.     int next   = getStat(pln, STAT_NEXTL);
  702.     int leveled;
  703.     int i; int j;
  704.  
  705.     while (xp >= next)
  706.     {
  707.         xp -= next;
  708.  
  709.         level++;
  710.         leveled++;
  711.         unlocksLeft[pln]++;
  712.  
  713.         next += (next >> 2);
  714.     }
  715.  
  716.     setStat(pln, STAT_XP, xp);
  717.     setStat(pln, STAT_LEVEL, level);
  718.     setStat(pln, STAT_NEXTL, next);
  719.  
  720.     if (leveled)
  721.     {
  722.         ACS_ExecuteAlways(UNLOCK_NAG, 0, 0,0,0);
  723.  
  724.         leveled = min(leveled, LEVELEFFECT_MAX);
  725.  
  726.         for (i = 0; i < 70; i++)
  727.         {
  728.             for (j = 0; j < leveled; j++)
  729.             {
  730.                 GiveInventory("LevelUpEffect", 1);
  731.             }
  732.             Delay(1);
  733.         }
  734.     }
  735. }
  736.  
  737. script LEVEL_ADDXP_ONKILL (int isMonster, int amount)
  738. {
  739.     ACS_ExecuteAlways(UNLOCK_HOOK_ONKILL, 0, isMonster,amount,0);
  740.  
  741.     int monOldHP;
  742.  
  743.     int killedHP = GetActorProperty(0, APROP_SpawnHealth);
  744.     int killedPln = PlayerNumber();
  745.     int killedTeam = GetPlayerInfo(killedPln, PLAYERINFO_TEAM);
  746.  
  747.     SetActivatorToTarget(0);
  748.  
  749.     int killerPln = PlayerNumber();
  750.     int killerTeam = GetPlayerInfo(killerPln, PLAYERINFO_TEAM);
  751.     int curStreak; int nowStreak;
  752.  
  753.     if (!amount)
  754.     {
  755.         amount = 5 + max((getStat(killedPln, STAT_TOTALXP) - getStat(killerPln, STAT_TOTALXP)) / 2, 0);
  756.     }
  757.  
  758.     if (killerPln == -1)  // m-m-m-m-m-monster kill
  759.     {
  760.         terminate;
  761.     }
  762.  
  763.     if (isMonster)
  764.     {
  765.         amount = killedHP / 5 ;
  766.        
  767.         // Difficulty hook
  768.         amount *= difficultyMults[GameSkill()];
  769.         amount >>= 16;
  770.  
  771.         ACS_ExecuteAlways(LEVEL_ADDXP, 0, killerPln, amount, 0);
  772.     }
  773.     else
  774.     {
  775.         amount *= getStat(killerPln, STAT_CURSTREAK) + 1;
  776.  
  777.         if (killedTeam == killerTeam)
  778.         {
  779.             if ((killedTeam == 4) && (killedPln != killerPln))
  780.             {
  781.                 ACS_ExecuteAlways(LEVEL_ADDXP, 0, killerPln, amount, 0);
  782.             }
  783.         }
  784.         else
  785.         {
  786.             ACS_ExecuteAlways(LEVEL_ADDXP, 0, killerPln, amount, 0);
  787.         }
  788.  
  789.         addStat(killerPln, STAT_CURSTREAK, 1);
  790.         addStat(killerPln, STAT_KILLCOUNT, 1);
  791.         curStreak = getStat(killerPln, STAT_KILLCOUNT);
  792.         Delay(105);
  793.         nowStreak = getStat(killerPln, STAT_KILLCOUNT);
  794.  
  795.         if (curStreak == nowStreak)
  796.         {
  797.             setStat(killerPln, STAT_CURSTREAK, 0);
  798.         }
  799.     }
  800. }
  801.  
  802. #include "level_unlocks.h"
Add Comment
Please, Sign In to add comment