Advertisement
asarium

Untitled

Oct 6th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 9.99 KB | None | 0 0
  1. Index: code/hud/hudets.cpp
  2. ===================================================================
  3. --- code/hud/hudets.cpp (revision 9879)
  4. +++ code/hud/hudets.cpp (working copy)
  5. @@ -138,23 +138,7 @@
  6.     // calculate the top speed of the ship based on the energy flow to engines
  7.     float y = Energy_levels[ship_p->engine_recharge_index];
  8.  
  9. -   // check for a shortcuts first before doing linear interpolation
  10. -   if ( y == Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
  11. -       ship_p->current_max_speed = sinfo_p->max_speed;
  12. -   } else if ( y == 0.0f ){
  13. -       ship_p->current_max_speed = 0.5f * sinfo_p->max_speed;
  14. -   } else if ( y == 1.0f ){
  15. -       ship_p->current_max_speed = sinfo_p->max_overclocked_speed;
  16. -   } else {
  17. -       // do a linear interpolation to find the current max speed, using points (0,1/2 default_max_speed) (.333,default_max_speed)
  18. -       // x = x1 + (y-y1) * (x2-x1) / (y2-y1);
  19. -       if ( y < Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
  20. -           ship_p->current_max_speed =  0.5f*sinfo_p->max_speed + (y  * (0.5f*sinfo_p->max_speed) ) / Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX];
  21. -       } else {
  22. -           // do a linear interpolation to find the current max speed, using points (.333,default_max_speed) (1,max_overclock_speed)
  23. -           ship_p->current_max_speed = sinfo_p->max_speed + (y - Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX]) * (sinfo_p->max_overclocked_speed - sinfo_p->max_speed) / (1.0f - Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX]);
  24. -       }
  25. -   }
  26. +   ship_p->current_max_speed = ets_get_max_speed(objp, y);
  27.  
  28.     // AL 11-15-97: Rules for engine strength affecting max speed:
  29.     //                      1. if strength >= 0.5 no affect
  30. @@ -184,7 +168,36 @@
  31.     }
  32.  }
  33.  
  34. +float ets_get_max_speed(object* objp, float engine_energy)
  35. +{
  36. +   Assertion(objp != NULL, "Invalid object pointer passed!");
  37. +   Assertion(objp->type == OBJ_SHIP, "Object needs to be a ship object!");
  38. +   Assertion(engine_energy >= 0.0f && engine_energy <= 1.0f, "Invalid float passed, needs to be in [0, 1], was %f!", engine_energy);
  39.  
  40. +   ship* shipp = &Ships[objp->instance];
  41. +
  42. +   ship_info* sip = &Ship_info[shipp->ship_info_index];
  43. +
  44. +   // check for a shortcuts first before doing linear interpolation
  45. +   if ( engine_energy == Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
  46. +       return sip->max_speed;
  47. +   } else if ( engine_energy == 0.0f ){
  48. +       return 0.5f * sip->max_speed;
  49. +   } else if ( engine_energy == 1.0f ){
  50. +       return sip->max_overclocked_speed;
  51. +   } else {
  52. +       // do a linear interpolation to find the current max speed, using points (0,1/2 default_max_speed) (.333,default_max_speed)
  53. +       // x = x1 + (y-y1) * (x2-x1) / (y2-y1);
  54. +       if ( engine_energy < Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
  55. +           return 0.5f*sip->max_speed + (engine_energy  * (0.5f*sip->max_speed) ) / Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX];
  56. +       } else {
  57. +           // do a linear interpolation to find the current max speed, using points (.333,default_max_speed) (1,max_overclock_speed)
  58. +           return sip->max_speed + (engine_energy - Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX]) * (sip->max_overclocked_speed - sip->max_speed) / (1.0f - Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX]);
  59. +       }
  60. +   }
  61. +}
  62. +
  63. +
  64.  // -------------------------------------------------------------------------------------------------
  65.  // ai_manage_ets() will determine if a ship should modify it's energy transfer percentages, or
  66.  // transfer energy from shields->weapons or from weapons->shields
  67. Index: code/hud/hudets.h
  68. ===================================================================
  69. --- code/hud/hudets.h   (revision 9879)
  70. +++ code/hud/hudets.h   (working copy)
  71. @@ -36,6 +36,8 @@
  72.  void transfer_energy_to_shields(object* obj);
  73.  void transfer_energy_to_weapons(object* obj);
  74.  
  75. +float ets_get_max_speed(object* objp, float engine_energy);
  76. +
  77.  class HudGaugeEts: public HudGauge // HUD_ETS_GAUGE
  78.  {
  79.  protected:
  80. Index: code/parse/lua.cpp
  81. ===================================================================
  82. --- code/parse/lua.cpp  (revision 9879)
  83. +++ code/parse/lua.cpp  (working copy)
  84. @@ -16,6 +16,7 @@
  85.  #include "hud/hudescort.h"
  86.  #include "hud/hudconfig.h"
  87.  #include "hud/hudgauges.h"
  88. +#include "hud/hudets.h"
  89.  #include "iff_defs/iff_defs.h"
  90.  #include "io/key.h"
  91.  #include "io/mouse.h"
  92. @@ -4371,6 +4372,33 @@
  93.         return ADE_RETURN_FALSE;
  94.  }
  95.  
  96. +ADE_VIRTVAR(CargoSize, l_Weaponclass, "number", "The cargo size of this weapon class", "number", "The new cargo size or -1 on error")
  97. +{
  98. +   int idx;
  99. +   float newVal = -1.0f;
  100. +   if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &newVal))
  101. +       return ade_set_args(L, "f", -1.0f);
  102. +
  103. +   if(idx < 0 || idx > Num_weapon_types)
  104. +       return ade_set_args(L, "f", -1.0f);
  105. +  
  106. +   weapon_info *info = &Weapon_info[idx];
  107. +
  108. +   if(ADE_SETTING_VAR)
  109. +   {
  110. +       if(newVal > 0)
  111. +       {
  112. +           info->cargo_size = newVal;
  113. +       }
  114. +       else
  115. +       {
  116. +           LuaError(L, "Cargo size must be bigger than zero, got %f!", newVal);
  117. +       }
  118. +   }
  119. +
  120. +   return ade_set_args(L, "f", info->cargo_size);
  121. +}
  122. +
  123.  ADE_FUNC(isValid, l_Weaponclass, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
  124.  {
  125.     int idx;
  126. @@ -6027,6 +6055,29 @@
  127.     return ade_set_args(L, "o", l_Shiptype.Set(Ship_info[idx].class_type));
  128.  }
  129.  
  130. +ADE_VIRTVAR(AltName, l_Shipclass, "string", "Alternate name for ship class", "string", "Alternate string or empty string if handle is invalid")
  131. +{
  132. +   char* newName = NULL;
  133. +   int idx;
  134. +   if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &newName))
  135. +       return ade_set_error(L, "s", "");
  136. +
  137. +   if(idx < 0 || idx > Num_ship_classes)
  138. +       return ade_set_error(L, "s", "");
  139. +
  140. +   if(ADE_SETTING_VAR && newName != NULL) {
  141. +       if (strlen(newName) > NAME_LENGTH)
  142. +       {
  143. +           LuaError(L, "Cannot set alternate name value to '%s' because it is too long, maximum length is %d!", newName, NAME_LENGTH);
  144. +           return ade_set_error(L, "s", "");
  145. +       }
  146. +
  147. +       strcpy_s(Ship_info[idx].alt_name, newName);
  148. +   }
  149. +
  150. +   return ade_set_args(L, "s", Ship_info[idx].alt_name);
  151. +}
  152. +
  153.  ADE_FUNC(isValid, l_Shipclass, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
  154.  {
  155.     int idx;
  156. @@ -6058,7 +6109,6 @@
  157.     return ade_set_args(L, "b", b);
  158.  }
  159.  
  160. -
  161.  ADE_FUNC(renderTechModel, l_Shipclass, "X1, Y1, X2, Y2, [Rotation %, Pitch %, Bank %, Zoom multiplier]", "Draws ship model as if in techroom", "boolean", "Whether ship was rendered")
  162.  {
  163.     int x1,y1,x2,y2;
  164. @@ -6639,6 +6689,38 @@
  165.     return ade_set_error(L, "b", false);
  166.  }
  167.  
  168. +ADE_VIRTVAR(Capacity, l_WeaponBank, "number", "The actual capacity of a weapon bank as specified in the table", "number", "The capacity or -1 if handle is invalid")
  169. +{
  170. +   ship_bank_h *bh = NULL;
  171. +   int newCapacity = -1;
  172. +   if(!ade_get_args(L, "o|i", l_WeaponBank.GetPtr(&bh), &newCapacity))
  173. +       return ade_set_error(L, "i", -1);
  174. +
  175. +   if(!bh->IsValid())
  176. +       return ade_set_error(L, "i", -1);
  177. +
  178. +   switch(bh->type)
  179. +   {
  180. +       case SWH_PRIMARY:
  181. +           if(ADE_SETTING_VAR && newCapacity > 0) {
  182. +               bh->sw->primary_bank_capacity[bh->bank] = newCapacity;
  183. +           }
  184. +           return ade_set_args(L, "i", bh->sw->primary_bank_capacity[bh->bank]);
  185. +       case SWH_SECONDARY:
  186. +           if(ADE_SETTING_VAR && newCapacity > 0) {
  187. +               bh->sw->secondary_bank_capacity[bh->bank] = newCapacity;
  188. +           }
  189. +           return ade_set_args(L, "i", bh->sw->secondary_bank_capacity[bh->bank]);
  190. +       case SWH_TERTIARY:
  191. +           if(ADE_SETTING_VAR && newCapacity > 0) {
  192. +               bh->sw->tertiary_bank_capacity = newCapacity;
  193. +           }
  194. +           return ade_set_args(L, "i", bh->sw->tertiary_bank_capacity);
  195. +   }
  196. +  
  197. +   return ade_set_error(L, "i", -1);
  198. +}
  199. +
  200.  ADE_FUNC(isValid, l_WeaponBank, NULL, "Detects whether handle is valid", "boolean", "true if valid, false if handle is invalid, nil if a syntax/type error occurs")
  201.  {
  202.     ship_bank_h *bh;
  203. @@ -8980,6 +9062,84 @@
  204.     return ade_set_args(L, "f", (i2fl(time_until) / 1000.0f));
  205.  }
  206.  
  207. +ADE_FUNC(getCallsign, l_Ship, NULL, "Gets the callsign of the ship in the current mission", "string", "The callsign or an empty string if the ship doesn't have a callsign or an error occurs")
  208. +{
  209. +   object_h *objh = NULL;
  210. +
  211. +   if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
  212. +       return ade_set_error(L, "s", "");
  213. +   }
  214. +
  215. +   if(!objh->IsValid())
  216. +       return ade_set_error(L, "s", "");
  217. +
  218. +   ship *shipp = &Ships[objh->objp->instance];
  219. +
  220. +   if (shipp->callsign_index < 0)
  221. +       return ade_set_args(L, "s", "");
  222. +  
  223. +   char temp_callsign[NAME_LENGTH];
  224. +  
  225. +   *temp_callsign = 0;
  226. +   mission_parse_lookup_callsign_index(shipp->callsign_index, temp_callsign);
  227. +
  228. +   if (*temp_callsign)
  229. +       return ade_set_args(L, "s", temp_callsign);
  230. +   else
  231. +       return ade_set_args(L, "s", "");
  232. +}
  233. +
  234. +ADE_FUNC(getAltClassName, l_Ship, NULL, "Gets the alternate class name of the ship", "string", "The alternate class name or an empty string if the ship doesn't have such a thing or an error occurs")
  235. +{
  236. +   object_h *objh = NULL;
  237. +
  238. +   if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
  239. +       return ade_set_error(L, "s", "");
  240. +   }
  241. +
  242. +   if(!objh->IsValid())
  243. +       return ade_set_error(L, "s", "");
  244. +
  245. +   ship *shipp = &Ships[objh->objp->instance];
  246. +
  247. +   if (shipp->alt_type_index < 0)
  248. +       return ade_set_args(L, "s", "");
  249. +  
  250. +   char temp[NAME_LENGTH];
  251. +  
  252. +   *temp = 0;
  253. +   mission_parse_lookup_alt_index(shipp->alt_type_index, temp);
  254. +
  255. +   if (*temp)
  256. +       return ade_set_args(L, "s", temp);
  257. +   else
  258. +       return ade_set_args(L, "s", "");
  259. +}
  260. +
  261. +ADE_FUNC(getMaximumSpeed, l_Ship, "[number energy = 0.333]", "Gets the maximum speed of the ship with the given energy on the engines", "number", "The maximum speed or -1 on error")
  262. +{
  263. +   object_h *objh = NULL;
  264. +   float energy = 0.333f;
  265. +
  266. +   if (!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &energy)) {
  267. +       return ade_set_error(L, "f", -1.0f);
  268. +   }
  269. +
  270. +   if(!objh->IsValid())
  271. +       return ade_set_error(L, "f", -1.0f);
  272. +
  273. +   if (energy < 0.0f || energy > 1.0f)
  274. +   {
  275. +       LuaError(L, "Invalid energy level %f! Needs to be in [0, 1].", energy);
  276. +
  277. +       return ade_set_args(L, "f", -1.0f);
  278. +   }
  279. +   else
  280. +   {
  281. +       return ade_set_args(L, "f", ets_get_max_speed(objh->objp, energy));
  282. +   }
  283. +}
  284. +
  285.  //**********HANDLE: Weapon
  286.  ade_obj<object_h> l_Weapon("weapon", "Weapon handle", &l_Object);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement