Advertisement
Slowhand-VI

temp1

Aug 21st, 2015
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.05 KB | None | 0 0
  1. /**
  2.  *  Simple quest tutorial. (Kill a monster X times, then return for reward template.)
  3.  *  Author: Slowhand
  4.  *  Reviewer:
  5.  */
  6.  
  7. #include "math.fos"
  8. #include "_colors.fos"
  9.  
  10. #define LOCATION_TUT_KILLMOBS       (91)
  11.  
  12. /**< Spawn a location from a dialogue at random location withing the specified parameters. */
  13. void r_SpawnLoc(Critter& player, Critter@ npc, int locationGameVar, int locationId, int minCoordX, int minCoordY, int maxCoordX, int maxCoordY)
  14. {
  15.     /**< Get a randomized position on the map within limits */
  16.     uint worldCoordX = getRandomXCoordsBetween(minCoordX, maxCoordX);
  17.     uint worldCoordY = getRandomYCoordsBetween(minCoordY, maxCoordY);
  18.  
  19.     /**< Get the local game variable, which will be used to store the location Id, so it can be deleted later. */
  20.     GameVar@ locationVariable = GetLocalVar(locationGameVar, player.Id);
  21.  
  22.     /**< Spawns the quest location. Use the macro LOCATION_YOUR_QUEST_NAME to specify the unique location that you saved your map and location to, in world editor. */
  23.     spawnQuestLocationWithCoords(player, locationVariable, locationId, worldCoordX, worldCoordY, true);
  24. }
  25.  
  26. /**< Dialog function used in request to delete quest location (after player report finishing the quest) */
  27. void r_DeleteLoc(Critter& player, Critter@ npc, int locationGameVar)
  28. {
  29.     if (isQuestLocationIdValid(Critter& player, locationGameVar))
  30.     {
  31.         DeleteLocation(getQuestLocationId(Critter& player, locationGameVar));
  32.     }
  33. }
  34.  
  35.  
  36. /**< LOGIC */
  37.  
  38.  
  39. void spawnQuestLocationWithCoords(Critter& player, GameVar@ gameVariable, int locationId, int coordX, int coordY, bool turnBasedAvailable)
  40. {
  41.     if (locationId < 1)
  42.         return;
  43.  
  44.     /**< Create quest location with the specified Id */
  45.     Critter@[] critters = { player };
  46.     int loc = CreateLocation(locationId, coordX, coordY, critters);
  47.     if(loc == 0)
  48.         return;
  49.  
  50.     /**< Make the location visible to the player. */
  51.     player.SetKnownLoc(true, loc);
  52.  
  53.     /**< Set the location color on the map */
  54.     Location@ location = GetLocation(loc);
  55.     if (!valid(location))
  56.     {
  57.         /**< Log and return. This should never happen. */
  58.         return;
  59.     }
  60.     location.Color = COLOR_QUEST_LOC;
  61.  
  62.     /**< Allow Turned Based fights in location */
  63.     if (turnBasedAvailable)
  64.     {
  65.         SetTurnBasedAvailability(location);
  66.     }
  67.  
  68.     /**< Set location id to the quests local variable (used when you need to delete location) */
  69.     setQuestLocationId(loc);
  70.  
  71.     /**< Player can die and come back, but location has to be deleted later */
  72.     location.AutoGarbage = false;
  73.  
  74.     /**< Update the location */
  75.     location.Update();
  76. }
  77.  
  78. /**< END OF: Logic */
  79.  
  80.  
  81.  
  82. /**< AUX */
  83.  
  84. uint getRandomXCoordsBetween(uint minCoordX, uint maxCoordX)
  85. {
  86.     uint zoneCoordX = CLAMP(Random(minCoordX, maxCoordX), 0, __GlobalMapWidth - 1);
  87.     uint worldCoordX = zoneCoordX * __GlobalMapZoneLength;
  88.     return worldCoordX;
  89.  
  90. }
  91.  
  92. uint getRandomYCoordsBetween(uint minCoordY, uint maxCoordY)
  93. {
  94.     uint zoneCoordY = CLAMP(Random(minCoordY, maxCoordY), 0, __GlobalMapWidth - 1);
  95.     uint worldCoordY = zoneCoordY * __GlobalMapZoneLength;
  96.     return worldCoordY;
  97. }
  98.  
  99. /**< END OF: Aux */
  100.  
  101.  
  102. /**< Setters */
  103.  
  104. void setQuestLocationId(Critter& player, int locationId)
  105. {
  106.     GameVar@ locid = GetLocalVar(LVAR_q_tut_killmobs_loc, player.Id);
  107.     if (valid(locid))
  108.     {
  109.         locid = locationId;
  110.     }
  111. }
  112.  
  113. /**< Getters */
  114.  
  115. /**< This feels off, because the return value reports errors as well. */
  116. int getQuestLocationId(Critter& player, int locationGameVarId)
  117. {
  118.     GameVar@ locationId = GetLocalVar(locationGameVarId, player.Id);
  119.     if (valid(locationId))
  120.     {
  121.         return locationId.GetValue();
  122.     }
  123.     else
  124.     {
  125.         /**< Need to do some logging here. */
  126.         return -1;
  127.     }
  128. }
  129.  
  130. /**< Checkers */
  131.  
  132. /**< Check if the location is exists. */
  133. bool isQuestLocationIdValid(Critter& player, int locationGameVarId)
  134. {
  135.     GameVar@ locationId = GetLocalVar(locationGameVarId, player.Id);
  136.     if (valid(locationId))
  137.     {
  138.         if (locationId.GetValue() > 0)
  139.         {
  140.             return true;
  141.         }
  142.     }
  143.     return false;
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement