May 13, 2024, 01:58:16

Author Topic: EMP Machine crash  (Read 4755 times)

Offline Lord_Valarian

  • Specialist
  • *
  • Posts: 64
  • Karma: 0
    • View Profile
EMP Machine crash
« on: December 11, 2010, 03:19:38 »
When I use the EMP code, it crashes nexus on missions. On the beta stand alone mission, it works fine. I think it's adding a new ship class to the missions, but it could be a bug. Take a look at the code and see if there are any errors. I'v disabled the emp in the missions. This is the latest version.

Code: [Select]
//phaser mod by Lord Valarian
MACHINE "EMPtorpedo"

STATE Default

//disable continous fire
RULE event In
:action
  Debug("EMP setup");

EMP_Ships:= GetFreeSel();
SelectShips(EMP_Ships, 0);

EMP_Device_List:= GetFreeSel();
SelectShips(EMP_Device_List, 0);

SelectShips(EMP_Ships, 1);
If(AllNumOf(EMP_Ships)>0, //if list not blank, damage devices
ExecList(EMP_Ships,
SelectDevices(EMP_Device_List, S.this, S.this:devType = #weap_emp_torpedo);
ExecList(EMP_Device_List,
S.this:contFire:= 0;
);
);
);

:end
END

//check for any exploding EMP Torpedos
RULE event Exploded
:condition
// E:ship -> the missile
// E:ship:launcherWeapon -> the torpedo launcher having fired that missile
// E:ship:launcherWeapon:devType -> the launcher's devicetype
E:ship:launcherWeapon:devType = #weap_emp_torpedo;
:end

// Debug(S.this, " distance from target=  ", Distance_To_Target_Ship);

:action
Debug("EMP exploded");
Debug("Target is", E:ship:target);

EMP_Ships:= GetFreeSel();
SelectShips(EMP_Ships, 0);

EMP_Ships_ShieldsUp:= GetFreeSel();
SelectShips(EMP_Ships_ShieldsUp, 0);

EMP_Ships_Shieldsdown:= GetFreeSel();
SelectShips(EMP_Ships_Shieldsdown, 0);

EMP_Device_List:= GetFreeSel();
SelectShips(EMP_Device_List, 0);

EMP_Fighters_Missiles:= GetFreeSel();
SelectShips(EMP_Fighters_Missiles, 0);

//master list of ships
SelectShips(EMP_Ships, IsValid(s.this) & (Distance(E:ship:target, S.this) < 5000));
// & not(s.race = #race_Locust));
Debug("master list of ships");  Dump(EMP_Ships);  Debug("---------------------------------"); 

// CopyIf(to-list, from-list, condition);

//Ships hit by emp with shield up
CopyIf(EMP_Ships_ShieldsUp, EMP_Ships, S.this:IsShielded);
Debug("Ships Shields Up");  Dump(EMP_Ships_ShieldsUp);  Debug("---------------------------------"); 
If(AllNumOf(EMP_Ships_ShieldsUp)>0, //if list not blank, damage shields
ExecList(EMP_Ships_ShieldsUp, 
Shield_Energy_Level:= S.this:shieldIntegrity - 100;
if (Shield_Energy_Level < 0,
Shield_Energy_Level:= 0;
);
S.this:shieldIntegrity:= Shield_Energy_Level;
);
);
//end

//Ships hit by emp with shield down
CopyIf(EMP_Ships_Shieldsdown, EMP_Ships, S.this:IsShielded = 0  );
Debug("Ships Shields Down");  Dump(EMP_Ships_Shieldsdown);  Debug("---------------------------------");
If(AllNumOf(EMP_Ships_Shieldsdown)>0, //if list not blank, damage devices
ExecList(EMP_Ships_Shieldsdown,

//if not hit by a previous emp
if (S.this:empFlag = 0,
S.this:empFlag:= 1;
// Debug(S.this, " Devices Disabled:  emp flag=  ", S.this:empFlag);

//damage level based on range from emp blastwave center
Distance_To_Target_Ship:= Distance(E:ship:target, S.this);

if (Distance_To_Target_Ship = 0,
LowRange:= 50;
HighRange:= 100;
);

if ((Distance_To_Target_Ship > 0) & (Distance_To_Target_Ship <= 1000),
LowRange:= 35;
HighRange:= 100;
);

if ((Distance_To_Target_Ship > 1000) & (Distance_To_Target_Ship <= 3000),
LowRange:= 25;
HighRange:= 75;
);
if ((Distance_To_Target_Ship > 3000) & (Distance_To_Target_Ship < 5000),
LowRange:= 10;
HighRange:= 50;
);

//damage devices
SelectDevices(EMP_Device_List, S.this, 1);
ExecList(EMP_Device_List,  //damage devices
Device_HP := S.this:hpMax;
newDamage := S.this:damage + rnd(LowRange, HighRange);
if(newDamage>100, newDamage:=100);
S.this:damage:=newDamage;

//emp disables devices for a period of time
EnableDevice(S.this, 0);
);
Timer(EMP_Enable_Devices, 60 + round(rnd(0,60)), E.ship := S.this);

S.this:shieldIntegrity:= 0;
S.this:reserve:= 0;
);
  );
);

//destory fighters, bombers, missiles
SelectBoats(EMP_Fighters_Missiles, IsValid(s.this) & not(s.class = #cls_EMP_torpedo));
Debug("EMP_Fighters_Missiles");  Dump(EMP_Fighters_Missiles);  Debug("---------------------------------");
ExecList(EMP_Fighters_Missiles,
    // calculate new damage level after decreasing ship's HP by X points
    E:newDamage := s:damage + (100 / s:hpMax) * 100;
    // apply damage to the ship
    S:damage := E:newDamage;
    // calculate new hpCur using the current damage level
    s:hpCur := (100 - E:newDamage) / 100 * s:hpMax;
    Debug(S.this, " current HP:", s:hpCur, "/", S.this:hpMax, " (", 100-E:newDamage, "%)");
);


:end
END


RULE event EMP_Enable_Devices
:action
E.ship:empFlag:= 0;
// Debug(E.ship, " Devices Enabled:  emp flag=  ", E.ship:empFlag);
EMP_Device_List:=GetFreeSel();
SelectDevices(EMP_Device_List, E.ship, 1);
ExecList(EMP_Device_List,
EnableDevice(S.this, 1);
);
  :end
END

END

END
//end

Offline Lord_Valarian

  • Specialist
  • *
  • Posts: 64
  • Karma: 0
    • View Profile
EMP Machine bug
« Reply #1 on: December 24, 2010, 08:19:42 »
I'm encountering a strange bug.  A critical part of the code is disabling continuous fire. If not, you will fry yourself often. In the mod, it works fine, but in the missions it doesn't function. Can someone explain what is going on?