Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: code/hud/hudets.cpp
- ===================================================================
- --- code/hud/hudets.cpp (revision 9879)
- +++ code/hud/hudets.cpp (working copy)
- @@ -138,23 +138,7 @@
- // calculate the top speed of the ship based on the energy flow to engines
- float y = Energy_levels[ship_p->engine_recharge_index];
- - // check for a shortcuts first before doing linear interpolation
- - if ( y == Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
- - ship_p->current_max_speed = sinfo_p->max_speed;
- - } else if ( y == 0.0f ){
- - ship_p->current_max_speed = 0.5f * sinfo_p->max_speed;
- - } else if ( y == 1.0f ){
- - ship_p->current_max_speed = sinfo_p->max_overclocked_speed;
- - } else {
- - // do a linear interpolation to find the current max speed, using points (0,1/2 default_max_speed) (.333,default_max_speed)
- - // x = x1 + (y-y1) * (x2-x1) / (y2-y1);
- - if ( y < Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
- - ship_p->current_max_speed = 0.5f*sinfo_p->max_speed + (y * (0.5f*sinfo_p->max_speed) ) / Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX];
- - } else {
- - // do a linear interpolation to find the current max speed, using points (.333,default_max_speed) (1,max_overclock_speed)
- - 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]);
- - }
- - }
- + ship_p->current_max_speed = ets_get_max_speed(objp, y);
- // AL 11-15-97: Rules for engine strength affecting max speed:
- // 1. if strength >= 0.5 no affect
- @@ -184,7 +168,36 @@
- }
- }
- +float ets_get_max_speed(object* objp, float engine_energy)
- +{
- + Assertion(objp != NULL, "Invalid object pointer passed!");
- + Assertion(objp->type == OBJ_SHIP, "Object needs to be a ship object!");
- + Assertion(engine_energy >= 0.0f && engine_energy <= 1.0f, "Invalid float passed, needs to be in [0, 1], was %f!", engine_energy);
- + ship* shipp = &Ships[objp->instance];
- +
- + ship_info* sip = &Ship_info[shipp->ship_info_index];
- +
- + // check for a shortcuts first before doing linear interpolation
- + if ( engine_energy == Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
- + return sip->max_speed;
- + } else if ( engine_energy == 0.0f ){
- + return 0.5f * sip->max_speed;
- + } else if ( engine_energy == 1.0f ){
- + return sip->max_overclocked_speed;
- + } else {
- + // do a linear interpolation to find the current max speed, using points (0,1/2 default_max_speed) (.333,default_max_speed)
- + // x = x1 + (y-y1) * (x2-x1) / (y2-y1);
- + if ( engine_energy < Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX] ){
- + return 0.5f*sip->max_speed + (engine_energy * (0.5f*sip->max_speed) ) / Energy_levels[INTIAL_ENGINE_RECHARGE_INDEX];
- + } else {
- + // do a linear interpolation to find the current max speed, using points (.333,default_max_speed) (1,max_overclock_speed)
- + 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]);
- + }
- + }
- +}
- +
- +
- // -------------------------------------------------------------------------------------------------
- // ai_manage_ets() will determine if a ship should modify it's energy transfer percentages, or
- // transfer energy from shields->weapons or from weapons->shields
- Index: code/hud/hudets.h
- ===================================================================
- --- code/hud/hudets.h (revision 9879)
- +++ code/hud/hudets.h (working copy)
- @@ -36,6 +36,8 @@
- void transfer_energy_to_shields(object* obj);
- void transfer_energy_to_weapons(object* obj);
- +float ets_get_max_speed(object* objp, float engine_energy);
- +
- class HudGaugeEts: public HudGauge // HUD_ETS_GAUGE
- {
- protected:
- Index: code/parse/lua.cpp
- ===================================================================
- --- code/parse/lua.cpp (revision 9879)
- +++ code/parse/lua.cpp (working copy)
- @@ -16,6 +16,7 @@
- #include "hud/hudescort.h"
- #include "hud/hudconfig.h"
- #include "hud/hudgauges.h"
- +#include "hud/hudets.h"
- #include "iff_defs/iff_defs.h"
- #include "io/key.h"
- #include "io/mouse.h"
- @@ -4371,6 +4372,33 @@
- return ADE_RETURN_FALSE;
- }
- +ADE_VIRTVAR(CargoSize, l_Weaponclass, "number", "The cargo size of this weapon class", "number", "The new cargo size or -1 on error")
- +{
- + int idx;
- + float newVal = -1.0f;
- + if(!ade_get_args(L, "o|f", l_Weaponclass.Get(&idx), &newVal))
- + return ade_set_args(L, "f", -1.0f);
- +
- + if(idx < 0 || idx > Num_weapon_types)
- + return ade_set_args(L, "f", -1.0f);
- +
- + weapon_info *info = &Weapon_info[idx];
- +
- + if(ADE_SETTING_VAR)
- + {
- + if(newVal > 0)
- + {
- + info->cargo_size = newVal;
- + }
- + else
- + {
- + LuaError(L, "Cargo size must be bigger than zero, got %f!", newVal);
- + }
- + }
- +
- + return ade_set_args(L, "f", info->cargo_size);
- +}
- +
- 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")
- {
- int idx;
- @@ -6027,6 +6055,29 @@
- return ade_set_args(L, "o", l_Shiptype.Set(Ship_info[idx].class_type));
- }
- +ADE_VIRTVAR(AltName, l_Shipclass, "string", "Alternate name for ship class", "string", "Alternate string or empty string if handle is invalid")
- +{
- + char* newName = NULL;
- + int idx;
- + if(!ade_get_args(L, "o|s", l_Shipclass.Get(&idx), &newName))
- + return ade_set_error(L, "s", "");
- +
- + if(idx < 0 || idx > Num_ship_classes)
- + return ade_set_error(L, "s", "");
- +
- + if(ADE_SETTING_VAR && newName != NULL) {
- + if (strlen(newName) > NAME_LENGTH)
- + {
- + LuaError(L, "Cannot set alternate name value to '%s' because it is too long, maximum length is %d!", newName, NAME_LENGTH);
- + return ade_set_error(L, "s", "");
- + }
- +
- + strcpy_s(Ship_info[idx].alt_name, newName);
- + }
- +
- + return ade_set_args(L, "s", Ship_info[idx].alt_name);
- +}
- +
- 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")
- {
- int idx;
- @@ -6058,7 +6109,6 @@
- return ade_set_args(L, "b", b);
- }
- -
- 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")
- {
- int x1,y1,x2,y2;
- @@ -6639,6 +6689,38 @@
- return ade_set_error(L, "b", false);
- }
- +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")
- +{
- + ship_bank_h *bh = NULL;
- + int newCapacity = -1;
- + if(!ade_get_args(L, "o|i", l_WeaponBank.GetPtr(&bh), &newCapacity))
- + return ade_set_error(L, "i", -1);
- +
- + if(!bh->IsValid())
- + return ade_set_error(L, "i", -1);
- +
- + switch(bh->type)
- + {
- + case SWH_PRIMARY:
- + if(ADE_SETTING_VAR && newCapacity > 0) {
- + bh->sw->primary_bank_capacity[bh->bank] = newCapacity;
- + }
- + return ade_set_args(L, "i", bh->sw->primary_bank_capacity[bh->bank]);
- + case SWH_SECONDARY:
- + if(ADE_SETTING_VAR && newCapacity > 0) {
- + bh->sw->secondary_bank_capacity[bh->bank] = newCapacity;
- + }
- + return ade_set_args(L, "i", bh->sw->secondary_bank_capacity[bh->bank]);
- + case SWH_TERTIARY:
- + if(ADE_SETTING_VAR && newCapacity > 0) {
- + bh->sw->tertiary_bank_capacity = newCapacity;
- + }
- + return ade_set_args(L, "i", bh->sw->tertiary_bank_capacity);
- + }
- +
- + return ade_set_error(L, "i", -1);
- +}
- +
- 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")
- {
- ship_bank_h *bh;
- @@ -8980,6 +9062,84 @@
- return ade_set_args(L, "f", (i2fl(time_until) / 1000.0f));
- }
- +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")
- +{
- + object_h *objh = NULL;
- +
- + if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
- + return ade_set_error(L, "s", "");
- + }
- +
- + if(!objh->IsValid())
- + return ade_set_error(L, "s", "");
- +
- + ship *shipp = &Ships[objh->objp->instance];
- +
- + if (shipp->callsign_index < 0)
- + return ade_set_args(L, "s", "");
- +
- + char temp_callsign[NAME_LENGTH];
- +
- + *temp_callsign = 0;
- + mission_parse_lookup_callsign_index(shipp->callsign_index, temp_callsign);
- +
- + if (*temp_callsign)
- + return ade_set_args(L, "s", temp_callsign);
- + else
- + return ade_set_args(L, "s", "");
- +}
- +
- +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")
- +{
- + object_h *objh = NULL;
- +
- + if (!ade_get_args(L, "o", l_Ship.GetPtr(&objh))) {
- + return ade_set_error(L, "s", "");
- + }
- +
- + if(!objh->IsValid())
- + return ade_set_error(L, "s", "");
- +
- + ship *shipp = &Ships[objh->objp->instance];
- +
- + if (shipp->alt_type_index < 0)
- + return ade_set_args(L, "s", "");
- +
- + char temp[NAME_LENGTH];
- +
- + *temp = 0;
- + mission_parse_lookup_alt_index(shipp->alt_type_index, temp);
- +
- + if (*temp)
- + return ade_set_args(L, "s", temp);
- + else
- + return ade_set_args(L, "s", "");
- +}
- +
- +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")
- +{
- + object_h *objh = NULL;
- + float energy = 0.333f;
- +
- + if (!ade_get_args(L, "o|f", l_Ship.GetPtr(&objh), &energy)) {
- + return ade_set_error(L, "f", -1.0f);
- + }
- +
- + if(!objh->IsValid())
- + return ade_set_error(L, "f", -1.0f);
- +
- + if (energy < 0.0f || energy > 1.0f)
- + {
- + LuaError(L, "Invalid energy level %f! Needs to be in [0, 1].", energy);
- +
- + return ade_set_args(L, "f", -1.0f);
- + }
- + else
- + {
- + return ade_set_args(L, "f", ets_get_max_speed(objh->objp, energy));
- + }
- +}
- +
- //**********HANDLE: Weapon
- ade_obj<object_h> l_Weapon("weapon", "Weapon handle", &l_Object);
Advertisement
Add Comment
Please, Sign In to add comment