Skip to content

Commit

Permalink
fleet retreating crash
Browse files Browse the repository at this point in the history
  • Loading branch information
OH296 committed Dec 27, 2024
1 parent b08f6f8 commit 196b8e2
Show file tree
Hide file tree
Showing 4 changed files with 176 additions and 149 deletions.
2 changes: 1 addition & 1 deletion objects/obj_en_fleet/Alarm_1.gml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ if (navy && action=="") {

var bombard=0,deaths=0,hurss=0,onceh=0,wob=0,kill=0;

for (var o=1;o<=planets;o++){
for (var o=1;o<=orbiting.planets;o++){
if (orbiting.p_owner[o]==eFACTION.Player){
if (orbiting.p_population[o]+orbiting.p_pdf[o]>0) || (orbiting.p_player[o]>0){
bombard=o;
Expand Down
135 changes: 1 addition & 134 deletions objects/obj_popup/Mouse_51.gml
Original file line number Diff line number Diff line change
Expand Up @@ -7,140 +7,7 @@ if (battle_special>0){

if (instance_exists(obj_controller)){
if (obj_controller.force_scroll=1) and (type=99) and (instance_exists(obj_turn_end)){

var p_strength,en_strength,ratio,diceh,mfleet,rdice;
p_strength=0;en_strength=0;mfleet=obj_turn_end.battle_pobject[obj_turn_end.current_battle];
p_strength+=mfleet.escort_number;
p_strength+=mfleet.frigate_number*3;
p_strength+=mfleet.capital_number*8;
rdice=floor(random(100))+1;



with(obj_temp3){instance_destroy();}
obj_controller.temp[2000]=obj_turn_end.battle_location[obj_turn_end.current_battle];
with(obj_star){if (name=obj_controller.temp[2000]) then instance_create(x,y,obj_temp3);}
var that=instance_nearest(obj_temp3.x,obj_temp3.y,obj_star);

obj_controller.temp[2001]=real(that.id);
obj_controller.temp[2002]=real(obj_turn_end.battle_opponent[obj_turn_end.current_battle]);

var cap_total=0,frig_total=0,escort_total=0;
with(obj_en_fleet){
if (orbiting=obj_controller.temp[2001]) and (owner=obj_controller.temp[2002]){
cap_total += capital_number;
frig_total += frigate_number;
escort_total += escort_number;
}
}

en_strength+=cap_total*4;
en_strength+=frig_total*2;
en_strength+=escort_total;


ratio=9999;if (p_strength>0) and (en_strength>0){ratio=(en_strength/p_strength)*100;}

var esc_lost,frig_lost,cap_lost,which,sayd;
esc_lost=0;frig_lost=0;cap_lost=0;which=0;sayd=0;

ship_lost=0;i=-1;// var ship_lost,i;
repeat(50){i+=1;ship_lost[i]=0;}i=0;
if (scr_has_adv("Kings of Space")) then rdice-=10;
if (rdice<=80) and (p_strength<=2) then rdice=-5;

if (rdice!=-5){
repeat(50){
diceh=floor(random(100))+1;
if (diceh<=ratio){ratio-=100;
var onceh;onceh=0;

if (mfleet.escort_number>0) and (onceh=0){
esc_lost+=1;
which=floor(random(mfleet.escort_number))+1;
sayd=mfleet.escort_num[which];

obj_ini.ship_hp[sayd]=0;ship_lost[sayd]=1;
onceh=1;mfleet.escort_number-=1;
}
if (mfleet.frigate_number>0) and (onceh=0){
frig_lost+=1;
which=floor(random(mfleet.frigate_number))+1;
sayd=mfleet.frigate_num[which];

obj_ini.ship_hp[sayd]=0;ship_lost[sayd]=1;
onceh=1;mfleet.frigate_number-=1;
}
if (mfleet.capital_number>0) and (onceh=0){
cap_lost+=1;
which=floor(random(mfleet.capital_number))+1;
sayd=mfleet.capital_num[which];

obj_ini.ship_hp[sayd]=0;ship_lost[sayd]=1;
onceh=1;mfleet.capital_number-=1;
}

// show_message("Ship lost");
}

}
scr_ini_ship_cleanup();
}

obj_p_fleet.selected=0;
with (obj_p_fleet){
scr_ini_ship_cleanup();

if (player_fleet_ship_count() == 0) then instance_destroy();
}
with(obj_fleet_select){instance_destroy();}
obj_controller.popup=0;
if (obj_controller.zoomed=1){with(obj_controller){scr_zoom();}}

type=98;
title="Fleet Retreating";
cooldown=15;
obj_controller.menu=0;

// 139;
with(obj_temp_inq){instance_destroy();}
instance_create(obj_turn_end.battle_pobject[obj_turn_end.current_battle].x,obj_turn_end.battle_pobject[obj_turn_end.current_battle].y,obj_temp_inq);
with(obj_en_fleet){
if (navy=1) and (point_distance(x,y,obj_temp_inq.x,obj_temp_inq.y)<40) and (trade_goods="player_hold") then trade_goods="";
}
with(obj_temp_inq){instance_destroy();}

if (esc_lost+frig_lost+cap_lost>0) and (mfleet.escort_number+mfleet.frigate_number+mfleet.capital_number>0){
text="Your fleet is given the command to fall back. The vesels turn and prepare to enter the Warp, constantly under a hail of enemy fire. Some of your ships remain behind to draw off the attack and give the rest of your fleet a chance to escape. ";

if (cap_lost=1) then text+=string(cap_lost)+" Battle Barge is destroyed. ";
if (frig_lost=1) then text+=string(frig_lost)+" Strike Cruiser is destroyed. ";
if (esc_lost=1) then text+=string(esc_lost)+" Escort is destroyed. ";

if (cap_lost>1) then text+=string(cap_lost)+" Battle Barges were destroyed. ";
if (frig_lost>1) then text+=string(frig_lost)+" Strike Cruisers were destroyed. ";
if (esc_lost>1) then text+=string(esc_lost)+" Escorts were destroyed. ";
}

if (esc_lost+frig_lost+cap_lost=0){
text="Your fleet is given the command to fall back. The vesels turn and prepare to enter the Warp, constantly under a hail of enemy fire. The entire fleet manages to escape with minimal damage.";
}

if (mfleet.escort_number+mfleet.frigate_number+mfleet.capital_number=0){
text="Your fleet is given the command to fall back. The vessels turn and prepare to enter the Warp, constantly under a hail of enemy fire. All of your ships are destroyed attempting to flee.";
}
with (mfleet){
complex_route=[];
}

with(obj_fleet_select){instance_destroy();}
if (mfleet.escort_number+mfleet.frigate_number+mfleet.capital_number=0) and (instance_exists(mfleet)){with(mfleet){instance_destroy();}}

/*
with(obj_ini){scr_dead_marines(1);}
with(obj_ini){scr_ini_ship_cleanup();}
*/

player_retreat_from_fleet_combat();
}
}

Expand Down
29 changes: 15 additions & 14 deletions scripts/scr_ini_ship_cleanup/scr_ini_ship_cleanup.gml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,21 @@ function scr_kill_ship(index){
if (_ship_fleet!="none"){
delete_ship_from_fleet(index,_ship_fleet);
_available_ships = fleet_full_ship_array(_ship_fleet);
}
}
_units_on_ship = array_shuffle(_units_on_ship);
for (var i=0;i<array_length(_available_ships);i++){
if (_available_ships[i]==index) then continue;
var _cur_ship = _available_ships[i];
var f=0;
var _total_units = array_length(_units_on_ship);
while (ship_carrying[_cur_ship]<ship_capacity[_cur_ship] && f<_total_units && array_length(_units_on_ship)>0){
f++;
if (_units_on_ship[0].get_unit_size()+ship_carrying[_cur_ship]<=ship_capacity[_cur_ship]){
_units_on_ship[0].load_marine(_cur_ship);
array_delete(_units_on_ship, 0, 1);
}
}
}
array_delete(ship,index,1);
array_delete(ship_uid,index,1);
array_delete(ship_owner,index,1);
Expand Down Expand Up @@ -59,19 +73,6 @@ function scr_kill_ship(index){
array_delete(ship_contents,index,1);
array_delete(ship_turrets,index,1);

_units_on_ship = array_shuffle(_units_on_ship);
for (var i=0;i<array_length(_available_ships);i++){
var _cur_ship = _available_ships[i];
var f=0;
var _total_units = array_length(_units_on_ship);
while (ship_carrying[_cur_ship]<ship_capacity[_cur_ship] && f<_total_units && array_length(_units_on_ship)>0){
f++;
if (_units_on_ship[0].get_unit_size()+ship_carrying[_cur_ship]<=ship_capacity[_cur_ship]){
_units_on_ship[0].load_marine(_cur_ship);
array_delete(_units_on_ship, 0, 1);
}
}
}
if (!in_warp){
if (_nearest_star!="none"){
while(array_length(_units_on_ship)>0){
Expand Down
159 changes: 159 additions & 0 deletions scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,166 @@ function add_ship_to_fleet(index, fleet="none"){
}
}
}
function player_retreat_from_fleet_combat(){
try{
var p_strength,ratio,diceh,_roll_100;
var mfleet=obj_turn_end.battle_pobject[obj_turn_end.current_battle];;
var _fleet_ships = fleet_full_ship_array(mfleet);
var en_strength=0;

var p_strength=mfleet.escort_number;
p_strength+=mfleet.frigate_number*3;
p_strength+=mfleet.capital_number*8;

_roll_100=d100_roll();


var _loc_star = star_by_name(obj_turn_end.battle_location[obj_turn_end.current_battle]);

obj_controller.temp[2001]=real(_loc_star.id);
obj_controller.temp[2002]=real(obj_turn_end.battle_opponent[obj_turn_end.current_battle]);
var _battle_opponent = obj_turn_end.battle_opponent[obj_turn_end.current_battle];

var cap_total=0,frig_total=0,escort_total=0;
with(obj_en_fleet){
if (orbiting==_loc_star.id) and (owner==_battle_opponent){
cap_total += capital_number;
frig_total += frigate_number;
escort_total += escort_number;
}
}

en_strength+=cap_total*4;
en_strength+=frig_total*2;
en_strength+=escort_total;


ratio=9999;
if (p_strength>0) and (en_strength>0){
ratio=(en_strength/p_strength)*100;
}

var esc_lost=0,frig_lost=0,cap_lost=0,which=0,sayd=0;

i=-1;// var ship_lost,i;
var ship_lost = [];

if (scr_has_adv("Kings of Space")) then _roll_100-=10;
if (_roll_100<=80) and (p_strength<=2) then _roll_100=-5;

if (_roll_100!=-5){
repeat(50){
diceh=d100_roll();
if (diceh<=ratio){
ratio-=100;
var onceh=0;

if (mfleet.escort_number>0) {
which=array_random_index(mfleet.escort_num);
sayd=mfleet.escort_num[which];
if (!array_contains(ship_lost, sayd)){
esc_lost+=1;
obj_ini.ship_hp[sayd]=0;
ship_lost[sayd]=1;
mfleet.escort_number-=1;
array_push(ship_lost, sayd);
}
}
else if (mfleet.frigate_number>0) {
which=array_random_index(mfleet.frigate_num);
sayd=mfleet.frigate_num[which];
if (!array_contains(ship_lost, sayd)){
frig_lost+=1;
obj_ini.ship_hp[sayd]=0;
ship_lost[sayd]=1;
mfleet.frigate_number-=1;
array_push(ship_lost, sayd);
}
}
else if (mfleet.capital_number>0) {
which=array_random_index(mfleet.capital_num);
sayd=mfleet.capital_num[which];
if (!array_contains(ship_lost, sayd)){
cap_lost+=1;
obj_ini.ship_hp[sayd]=0;
ship_lost[sayd]=1;
mfleet.capital_number-=1;
array_push(ship_lost, sayd);
}
}
if (!(mfleet.capital_number+mfleet.frigate_number+mfleet.escort_number)){
break;
}
// show_message("Ship lost");
}

}
}

obj_p_fleet.selected=0;

with(obj_fleet_select){
instance_destroy();
}
obj_controller.popup=0;
if (obj_controller.zoomed=1){
with(obj_controller){
scr_zoom();
}
}

type=98;
title="Fleet Retreating";
cooldown=15;
obj_controller.menu=0;

// 139;
with(obj_temp_inq){instance_destroy();}
instance_create(obj_turn_end.battle_pobject[obj_turn_end.current_battle].x,obj_turn_end.battle_pobject[obj_turn_end.current_battle].y,obj_temp_inq);
with(obj_en_fleet){
if (navy=1) and (point_distance(x,y,obj_temp_inq.x,obj_temp_inq.y)<40) and (trade_goods="player_hold") then trade_goods="";
}
with(obj_temp_inq){instance_destroy();}

if (esc_lost+frig_lost+cap_lost>0) and (mfleet.escort_number+mfleet.frigate_number+mfleet.capital_number>0){
text="Your fleet is given the command to fall back. The vesels turn and prepare to enter the Warp, constantly under a hail of enemy fire. Some of your ships remain behind to draw off the attack and give the rest of your fleet a chance to escape. ";

if (cap_lost=1) then text+=string(cap_lost)+" Battle Barge is destroyed. ";
if (frig_lost=1) then text+=string(frig_lost)+" Strike Cruiser is destroyed. ";
if (esc_lost=1) then text+=string(esc_lost)+" Escort is destroyed. ";

if (cap_lost>1) then text+=string(cap_lost)+" Battle Barges were destroyed. ";
if (frig_lost>1) then text+=string(frig_lost)+" Strike Cruisers were destroyed. ";
if (esc_lost>1) then text+=string(esc_lost)+" Escorts were destroyed. ";
}
var text = "Your fleet is given the command to fall back. The vessels turn and prepare to enter the Warp, constantly under a hail of enemy fire. ";
if (esc_lost+frig_lost+cap_lost=0){
text+="The entire fleet manages to escape with minimal damage.";
}

if (mfleet.escort_number+mfleet.frigate_number+mfleet.capital_number=0){
text+="All of your ships are destroyed attempting to flee.";
}

with (obj_p_fleet){
scr_ini_ship_cleanup();

if (player_fleet_ship_count() == 0){
instance_destroy();
} else {
complex_route=[];
}
}
with(obj_fleet_select){instance_destroy();}

/*
with(obj_ini){scr_dead_marines(1);}
with(obj_ini){scr_ini_ship_cleanup();}
*/
} catch(_exception){
handle_exception(_exception)
}
}
function fleet_full_ship_array(fleet="none", exclude_capitals=false, exclude_frigates = false, exclude_escorts = false){
var all_ships = [];
var i;
Expand Down

0 comments on commit 196b8e2

Please sign in to comment.