Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: zookeeper on November 18, 2011, 03:20:01 am

Title: Patch [committed]: fix initial velocity getting lost when changing ship
Post by: zookeeper on November 18, 2011, 03:20:01 am
If you change your ship in the loadout screen, then any initial velocity set in FRED will be lost. This fixes that.

Code: [Select]
Index: ship.cpp
===================================================================
--- ship.cpp (revision 8006)
+++ ship.cpp (working copy)
@@ -8742,6 +8742,7 @@
  swp = &sp->weapons;
  sip_orig = &Ship_info[sp->ship_info_index];
  objp = &Objects[sp->objnum];
+ p_objp = mission_parse_get_parse_object(sp->ship_name);
  ph_inf = objp->phys_info;
 
 
@@ -8808,7 +8809,6 @@
 
  // make sure that shields are disabled/enabled if they need to be - Chief1983
  if (!Fred_running) {
- p_objp = mission_parse_get_parse_object(sp->ship_name);
  if ((p_objp->flags2 & P2_OF_FORCE_SHIELDS_ON) && (sp->ship_max_shield_strength > 0.0f)) {
  objp->flags &= ~OF_NO_SHIELDS;
  } else if ((p_objp->flags & P_OF_NO_SHIELDS) || (sp->ship_max_shield_strength == 0.0f)) {
@@ -9042,6 +9042,14 @@
  sp->shield_recharge_index = sp_orig.shield_recharge_index;
  sp->engine_recharge_index = sp_orig.engine_recharge_index;
  }
+
+ // zookeeper - If we're switching in the loadout screen, make sure we retain initial velocity set in FRED
+ if (!(Game_mode & GM_IN_MISSION) && !(Fred_running)) {
+ Objects[sp->objnum].phys_info.speed = (float) p_objp->initial_velocity * sip->max_speed / 100.0f;
+ Objects[sp->objnum].phys_info.vel.xyz.z = Objects[sp->objnum].phys_info.speed;
+ Objects[sp->objnum].phys_info.prev_ramp_vel = Objects[sp->objnum].phys_info.vel;
+ Objects[sp->objnum].phys_info.desired_vel = Objects[sp->objnum].phys_info.vel;
+ }
 }
 
 #ifndef NDEBUG
Title: Re: Patch: fix initial velocity getting lost when changing ship
Post by: Goober5000 on November 20, 2011, 01:47:15 pm
I checked it over; it looks good.  Committed in 8028.