diff --git a/objects/obj_controller/Alarm_5.gml b/objects/obj_controller/Alarm_5.gml index f057d67769..c3953ee8e9 100644 --- a/objects/obj_controller/Alarm_5.gml +++ b/objects/obj_controller/Alarm_5.gml @@ -1,7 +1,7 @@ // TODO script description: This is the turn management in general // TODO refactor -try_and_report_loop("final end turn alarm 5", function() { +try { var recruit_count = 0; var random_marine, marine_position; var eq1 = 1, eq2 = 1, eq3 = 1, t = 0, r = 0; @@ -16,48 +16,46 @@ try_and_report_loop("final end turn alarm 5", function() { var novice_type = ""; var unit; - try_and_report_loop("chaos_spread", function() { - var times = max(1, round(turn / 150)); - if ((known[eFACTION.CHAOS] == 2) && (faction_defeated[eFACTION.CHAOS] == 0)) { - times += 1; - } - var xx3, yy3, plani, _star; - xx3 = irandom(room_width) + 1; - yy3 = irandom(room_height) + 1; - _star = instance_nearest(xx3, yy3, obj_star); - plani = floor(random(_star.planets)) + 1; - - // ** Chaos influence / corruption ** - if ((faction_gender[eFACTION.CHAOS] == 1) && (faction_defeated[eFACTION.CHAOS] == 0) && (turn >= chaos_turn)) { - repeat (times) { - if ((_star.p_type[plani] != "Dead") && (_star.planets > 0) && (turn >= 20)) { - var cathedral = 0; - if (planet_feature_bool(_star.p_feature[plani], eP_FEATURES.SORORITAS_CATHEDRAL) == 1) { - cathedral = choose(0, 1, 1); - } + var times = max(1, round(turn / 150)); + if ((known[eFACTION.CHAOS] == 2) && (faction_defeated[eFACTION.CHAOS] == 0)) { + times += 1; + } + var xx3, yy3, plani, _star; + xx3 = irandom(room_width) + 1; + yy3 = irandom(room_height) + 1; + _star = instance_nearest(xx3, yy3, obj_star); + plani = floor(random(_star.planets)) + 1; + + // ** Chaos influence / corruption ** + if ((faction_gender[eFACTION.CHAOS] == 1) && (faction_defeated[eFACTION.CHAOS] == 0) && (turn >= chaos_turn)) { + repeat (times) { + if ((_star.p_type[plani] != "Dead") && (_star.planets > 0) && (turn >= 20)) { + var cathedral = 0; + if (planet_feature_bool(_star.p_feature[plani], eP_FEATURES.SORORITAS_CATHEDRAL) == 1) { + cathedral = choose(0, 1, 1); + } - if (cathedral == 0) { - if ((_star.p_heresy[plani] >= 0) && (_star.p_heresy[plani] < 10)) { - _star.p_heresy[plani] += choose(0, 0, 0, 0, 0, 0, 0, 0, 5); - } else if ((_star.p_heresy[plani] >= 10) && (_star.p_heresy[plani] < 20)) { - _star.p_heresy[plani] += choose(-2, -2, -2, 5, 10, 15); - } else if ((_star.p_heresy[plani] >= 20) && (_star.p_heresy[plani] < 40)) { - _star.p_heresy[plani] += choose(-2, -1, 0, 0, 0, 0, 0, 0, 5, 10); - } else if ((_star.p_heresy[plani] >= 40) && (_star.p_heresy[plani] < 60)) { - _star.p_heresy[plani] += choose(-2, -1, 0, 0, 0, 0, 0, 0, 5, 10, 15); - } else if ((_star.p_heresy[plani] >= 60) && (_star.p_heresy[plani] < 100)) { - _star.p_heresy[plani] += choose(-1, 0, 0, 0, 0, 5, 10, 15); - } - } - if (_star.p_heresy[plani] < 0) { - _star.p_heresy[plani] = 0; + if (cathedral == 0) { + if ((_star.p_heresy[plani] >= 0) && (_star.p_heresy[plani] < 10)) { + _star.p_heresy[plani] += choose(0, 0, 0, 0, 0, 0, 0, 0, 5); + } else if ((_star.p_heresy[plani] >= 10) && (_star.p_heresy[plani] < 20)) { + _star.p_heresy[plani] += choose(-2, -2, -2, 5, 10, 15); + } else if ((_star.p_heresy[plani] >= 20) && (_star.p_heresy[plani] < 40)) { + _star.p_heresy[plani] += choose(-2, -1, 0, 0, 0, 0, 0, 0, 5, 10); + } else if ((_star.p_heresy[plani] >= 40) && (_star.p_heresy[plani] < 60)) { + _star.p_heresy[plani] += choose(-2, -1, 0, 0, 0, 0, 0, 0, 5, 10, 15); + } else if ((_star.p_heresy[plani] >= 60) && (_star.p_heresy[plani] < 100)) { + _star.p_heresy[plani] += choose(-1, 0, 0, 0, 0, 5, 10, 15); } } + if (_star.p_heresy[plani] < 0) { + _star.p_heresy[plani] = 0; + } } } + } - instance_activate_object(obj_star); - }); + instance_activate_object(obj_star); // ** Build new Imperial Ships ** build_planet_defence_fleets(); @@ -129,11 +127,11 @@ try_and_report_loop("final end turn alarm 5", function() { recruits = total_recruits; /* TODO implement Lamenters get Black Rage and story -if (turn=240) and (global.chapter_name="Lamenters"){ - obj_ini.strin2+="Black Rage"; - scr_popup("Geneseed Mutation","Your Chapter has begun to have visions and nightmares of Sanguinius' fall. The less mentally disciplined of your battle-brothers no longer are able to sleep soundly, waking from sleep in a screaming, frothing rage. It appears the Black Rage has returned.","black_rage",""); -} -*/ + if (turn=240) and (global.chapter_name="Lamenters"){ + obj_ini.strin2+="Black Rage"; + scr_popup("Geneseed Mutation","Your Chapter has begun to have visions and nightmares of Sanguinius' fall. The less mentally disciplined of your battle-brothers no longer are able to sleep soundly, waking from sleep in a screaming, frothing rage. It appears the Black Rage has returned.","black_rage",""); + } + */ // ** Battlefield Loot ** if (scr_has_adv("Tech-Scavengers")) { var lroll1, lroll2, loot = ""; @@ -334,45 +332,44 @@ if (turn=240) and (global.chapter_name="Lamenters"){ } } - try_and_report_loop("Secret Chaos Warlord spawn", function() { - if ((turn == 5) && (faction_gender[eFACTION.CHAOS] == 1)) { - // show_message("Turn 100"); + if ((turn == 5) && (faction_gender[eFACTION.CHAOS] == 1)) { + // show_message("Turn 100"); - var _star_found = false; - var _choice_star = noone; - var _stars = scr_get_stars(true); - for (var i = 0; i < array_length(_stars); i++) { - if (is_dead_star(_stars[i])) { - continue; - } - with (_stars[i]) { - if (owner == eFACTION.IMPERIUM && planets) { - if (scr_orbiting_fleet(eFACTION.IMPERIUM) != "none") { - _star_found = true; - _choice_star = self.id; - break; - } + var _star_found = false; + var _choice_star = noone; + var _stars = scr_get_stars(true); + for (var i = 0; i < array_length(_stars); i++) { + if (is_dead_star(_stars[i])) { + continue; + } + with (_stars[i]) { + if (owner == eFACTION.IMPERIUM && planets) { + if (scr_orbiting_fleet(eFACTION.IMPERIUM) != "none") { + _star_found = true; + _choice_star = self.id; + break; } } - if (_star_found) { - break; - } } if (_star_found) { - var _planet = array_random_element(planets_without_type("Dead", _choice_star)); + break; + } + } + if (_star_found) { + var _candidate_planets = planets_without_type("Dead", _choice_star); + if (array_length(_candidate_planets) > 0) { + var _planet = array_random_element(_candidate_planets); _choice_star.warlord[_planet] = 1; array_push(_choice_star.p_feature[_planet], new NewPlanetFeature(eP_FEATURES.WARLORD10)); - var _heresy_inc = _choice_star.p_type[_planet] == "Hive" ? 25 : 10; - _choice_star.p_heresy[_planet] += _heresy_inc; - if (_choice_star.p_heresy[_planet] < 50) { _choice_star.p_heresy_secret[_planet] = 10; } } } - }); + } + // * Blood debt end * if ((blood_debt == 1) && (penitent == 1)) { penitent_turn += 1; @@ -431,7 +428,7 @@ if (turn=240) and (global.chapter_name="Lamenters"){ } disposition[eFACTION.IMPERIUM] += 20; disposition[eFACTION.MECHANICUS] += 15; - disposition[eFACTION.IMPERIUM] += 20; + disposition[eFACTION.INQUISITION] += 20; disposition[eFACTION.ECCLESIARCHY] += 20; var o = 0; if (scr_has_adv("Reverent Guardians")) { @@ -721,7 +718,9 @@ if (turn=240) and (global.chapter_name="Lamenters"){ set_new_player_fleet_course(complex_route); } } -}); +} catch (_exception) { + handle_exception(_exception); +} if (helpful_places != false) { helpful_places = new HelpfulPlaces(); diff --git a/objects/obj_en_fleet/Alarm_1.gml b/objects/obj_en_fleet/Alarm_1.gml index 6c5fdf1c7d..8b2edd1abb 100644 --- a/objects/obj_en_fleet/Alarm_1.gml +++ b/objects/obj_en_fleet/Alarm_1.gml @@ -1,4 +1,4 @@ -try_and_report_loop("enemy fleet main end turn action", function() { +try { var orb = orbiting; if ((round(owner) != eFACTION.IMPERIUM) && (navy == 1)) { @@ -128,43 +128,43 @@ try_and_report_loop("enemy fleet main end turn action", function() { instance_activate_object(obj_en_fleet); /*if (action="") and (owner = eFACTION.IMPERIUM){// Defend nearby systems and return when done - - with(obj_star){ - // 137 ; might want for it to defend under other circumstances - if (present_fleet[8]>0) and (owner<=5) and (x>2) and (y>2) then instance_create(x,y,obj_temp3); - } - if (instance_number(obj_temp3)=0) then ret=1; - if (instance_number(obj_temp3)>0){ - var you,dis,mem; - you=instance_nearest(x,y,obj_temp3); - dis=point_distance(x,y,you.x,you.y); - if (dis<300) and (image_index>=3){ - action_x=you.x;action_y=you.y; - home_x=instance_nearest(x,y,obj_star).x; - home_y=instance_nearest(x,y,obj_star).y; - set_fleet_movement();with(obj_temp3){instance_destroy();} - exit; + with(obj_star){ + // 137 ; might want for it to defend under other circumstances + if (present_fleet[8]>0) and (owner<=5) and (x>2) and (y>2) then instance_create(x,y,obj_temp3); } - if (dis>=300) then ret=1; - } - - if (instance_exists(obj_crusade)){ - var cru;cru=instance_nearest(x,y,obj_crusade); - if (cru.owner=self.owner) and (point_distance(x,y,cru.x,cru.y)0){ - action_x=home_x; - action_y=home_y; - set_fleet_movement(); + if (instance_number(obj_temp3)=0) then ret=1; + if (instance_number(obj_temp3)>0){ + var you,dis,mem; + you=instance_nearest(x,y,obj_temp3); + dis=point_distance(x,y,you.x,you.y); + + if (dis<300) and (image_index>=3){ + action_x=you.x;action_y=you.y; + home_x=instance_nearest(x,y,obj_star).x; + home_y=instance_nearest(x,y,obj_star).y; + set_fleet_movement();with(obj_temp3){instance_destroy();} + exit; + } + if (dis>=300) then ret=1; } - } - - with(obj_temp3){instance_destroy();} - }*/ + + if (instance_exists(obj_crusade)){ + var cru;cru=instance_nearest(x,y,obj_crusade); + if (cru.owner=self.owner) and (point_distance(x,y,cru.x,cru.y)0){ + action_x=home_x; + action_y=home_y; + set_fleet_movement(); + } + } + + with(obj_temp3){instance_destroy();} + }*/ if (owner == eFACTION.INQUISITION) { var valid = true; @@ -243,7 +243,7 @@ try_and_report_loop("enemy fleet main end turn action", function() { } repeat (cur_star.planets) { t += 1; - inquisitor_contraband_take_popup(_cur_star, planet); + inquisitor_contraband_take_popup(cur_star, t); } } else if (string_count("investigate", trade_goods) == 0) { inquisition_inspection_logic(); @@ -291,21 +291,21 @@ try_and_report_loop("enemy fleet main end turn action", function() { } /*if (image_index>=4){ - with(obj_star){ - if (owner = eFACTION.TAU) and (present_fleets>0) and (tau_fleets=0){ - instance_create(x,y,obj_temp5); + with(obj_star){ + if (owner = eFACTION.TAU) and (present_fleets>0) and (tau_fleets=0){ + instance_create(x,y,obj_temp5); + } } - } - if (instance_exists(obj_temp5)){ - var wop;wop=instance_nearest(x,y,obj_temp5); - if (wop!=0) and (point_distance(x,y,wop.x,wop.y)<300) and (wop.x>5) and (wop.y>5){ - target_x=wop.x;target_y=wop.y; - home_x=x;home_y=y; - set_fleet_movement(); + if (instance_exists(obj_temp5)){ + var wop;wop=instance_nearest(x,y,obj_temp5); + if (wop!=0) and (point_distance(x,y,wop.x,wop.y)<300) and (wop.x>5) and (wop.y>5){ + target_x=wop.x;target_y=wop.y; + home_x=x;home_y=y; + set_fleet_movement(); + } } - } - with(obj_temp5){instance_destroy();} - }*/ + with(obj_temp5){instance_destroy();} + }*/ } if (owner == eFACTION.TYRANIDS) { @@ -326,7 +326,7 @@ try_and_report_loop("enemy fleet main end turn action", function() { if (capital_number > 0) { var capitals_engaged = 0; with (orbiting) { - for (var i = 1; i < planets; i++) { + for (var i = 1; i <= planets; i++) { if (capitals_engaged == capital_number) { break; } @@ -356,6 +356,7 @@ try_and_report_loop("enemy fleet main end turn action", function() { } instance_deactivate_object(orbiting); + var _abort_migration = false; repeat (100) { if (good != 5) { @@ -372,7 +373,8 @@ try_and_report_loop("enemy fleet main end turn action", function() { if ((good == 1) && (n == 5)) { if (!instance_exists(plin2)) { - exit; + _abort_migration = true; + break; } if (!array_contains(plin.p_type, "dead")) { good++; @@ -393,9 +395,9 @@ try_and_report_loop("enemy fleet main end turn action", function() { new_fleet.image_index = 1; /*with(new_fleet){ - var ii;ii=0;ii+=capital_number;ii+=round((frigate_number/2));ii+=round((escort_number/4)); - if (ii<=1) then ii=1;image_index=ii; - }*/ + var ii;ii=0;ii+=capital_number;ii+=round((frigate_number/2));ii+=round((escort_number/4)); + if (ii<=1) then ii=1;image_index=ii; + }*/ new_fleet.action_x = plin2.x; new_fleet.action_y = plin2.y; @@ -416,6 +418,9 @@ try_and_report_loop("enemy fleet main end turn action", function() { } } instance_activate_object(obj_star); + if (_abort_migration) { + exit; + } } } } @@ -423,13 +428,13 @@ try_and_report_loop("enemy fleet main end turn action", function() { if ((action == "move") && (action_eta > 5000)) { var woop = instance_nearest(x, y, obj_star); if (woop.storm == 0) { - action_eta -= 10000; + action_eta = max(1, action_eta - 10000); } else { if (!instance_nearest(target_x, target_y, obj_star).storm) { - action_eta -= 10000; + action_eta = max(1, action_eta - 10000); } } - } else if ((action == "move") && (action_eta < 5000)) { + } else if ((action == "move") && (action_eta <= 5000)) { if (instance_nearest(action_x, action_y, obj_star).storm > 0) { exit; } @@ -448,8 +453,8 @@ try_and_report_loop("enemy fleet main end turn action", function() { action_eta -= 1; /*if (owner>5){ - - }*/ + + }*/ if ((action_eta == 2) && (owner == eFACTION.INQUISITION) && (inquisitor > -1)) { inquisitor_ship_approaches(); @@ -472,7 +477,6 @@ try_and_report_loop("enemy fleet main end turn action", function() { } } } -}); - -/* */ -/* */ +} catch (_exception) { + handle_exception(_exception); +} diff --git a/objects/obj_en_fleet/Alarm_4.gml b/objects/obj_en_fleet/Alarm_4.gml index 16a1ff2fbf..8eb49317c5 100644 --- a/objects/obj_en_fleet/Alarm_4.gml +++ b/objects/obj_en_fleet/Alarm_4.gml @@ -1,11 +1,10 @@ -try_and_report_loop("fleet alarm 4", function() { +try { if (action != "") { - var sys, sys_dist, mine, connected, fleet, cont; + var sys, sys_dist, mine, connected, cont; sys_dist = 9999; connected = 0; cont = 0; - fleet = instance_id_get(0); sys = instance_nearest(action_x, action_y, obj_star); sys_dist = point_distance(action_x, action_y, sys.x, sys.y); act_dist = point_distance(x, y, sys.x, sys.y); @@ -20,9 +19,6 @@ try_and_report_loop("fleet alarm 4", function() { if (connected == 0) { eta = eta * 2; } - if (connected == 1) { - connected = 1; - } if ((owner == eFACTION.INQUISITION) && (action_eta < 2)) { action_eta = 2; @@ -40,13 +36,12 @@ try_and_report_loop("fleet alarm 4", function() { } if (action == "") { - var sys, sys_dist, mine, connected, fleet, cont, target_dist; + var sys, sys_dist, mine, connected, cont, target_dist; sys_dist = 9999; connected = 0; cont = 0; target_dist = 0; - fleet = id; sys = instance_nearest(action_x, action_y, obj_star); sys_dist = point_distance(action_x, action_y, sys.x, sys.y); if (scr_valid_fleet_target(target)) { @@ -92,9 +87,6 @@ try_and_report_loop("fleet alarm 4", function() { if (connected == 0) { eta = eta * 2; } - if (connected == 1) { - connected = 1; - } if ((action_eta <= 0) || (owner != eFACTION.INQUISITION)) { action_eta = eta; @@ -125,4 +117,6 @@ try_and_report_loop("fleet alarm 4", function() { } etah = 0; -}); +} catch (_exception) { + handle_exception(_exception); +} diff --git a/objects/obj_enunit/Alarm_1.gml b/objects/obj_enunit/Alarm_1.gml index 0eddccc0d7..5234565425 100644 --- a/objects/obj_enunit/Alarm_1.gml +++ b/objects/obj_enunit/Alarm_1.gml @@ -1685,7 +1685,7 @@ if (__b__) { } if (dudes[j] == "Flayed One") { - scr_en_weapon("Melee5", true, dudes_num[j], dudes[j], j); + scr_en_weapon("Melee Weapon", true, dudes_num[j], dudes[j], j); dudes_ac[j] = 10; dudes_hp[j] = 75; dudes_dr[j] = 0.9; @@ -1693,7 +1693,7 @@ if (__b__) { } if (dudes[j] == "Necron Warrior") { scr_en_weapon("Gauss Flayer", true, dudes_num[j], dudes[j], j); - scr_en_weapon("Melee3", true, dudes_num[j], dudes[j], j); + scr_en_weapon("Melee Weapon", true, dudes_num[j], dudes[j], j); dudes_ac[j] = 10; dudes_hp[j] = 75; dudes_dr[j] = 0.9; @@ -1701,7 +1701,7 @@ if (__b__) { } if (dudes[j] == "Necron Immortal") { scr_en_weapon("Gauss Blaster", true, dudes_num[j], dudes[j], j); - scr_en_weapon("Melee3", true, dudes_num[j], dudes[j], j); + scr_en_weapon("Melee Weapon", true, dudes_num[j], dudes[j], j); dudes_ac[j] = 15; dudes_hp[j] = 90; dudes_dr[j] = 0.85; @@ -1719,7 +1719,7 @@ if (__b__) { } if (dudes[j] == "Necron Destroyer") { scr_en_weapon("Gauss Cannon", true, dudes_num[j], dudes[j], j); - scr_en_weapon("Melee3", true, dudes_num[j], dudes[j], j); + scr_en_weapon("Melee Weapon", true, dudes_num[j], dudes[j], j); dudes_ac[j] = 25; dudes_hp[j] = 250; dudes_dr[j] = 0.75; @@ -1749,7 +1749,7 @@ if (__b__) { dudes_vehicle[j] = 1; } if (dudes[j] == "Canoptek Scarab") { - scr_en_weapon("Melee3", false, dudes_num[j] * 2, dudes[j], j); + scr_en_weapon("Melee Weapon", false, dudes_num[j] * 2, dudes[j], j); dudes_ac[j] = 5; dudes_hp[j] = 30; dudes_dr[j] = 0.75; diff --git a/objects/obj_p_fleet/Alarm_1.gml b/objects/obj_p_fleet/Alarm_1.gml index 17e9e8d78d..d3458cb138 100644 --- a/objects/obj_p_fleet/Alarm_1.gml +++ b/objects/obj_p_fleet/Alarm_1.gml @@ -1,4 +1,4 @@ -try_and_report_loop("player alarm 1", function() { +try { var spid, dir; spid = 0; dir = 0; @@ -19,7 +19,7 @@ try_and_report_loop("player alarm 1", function() { if ((orbiting != 0) && instance_exists(orbiting)) { if (orbiting.visited == 0) { - for (var planet_num = 1; planet_num < orbiting.planets; planet_num += 1) { + for (var planet_num = 1; planet_num <= orbiting.planets; planet_num += 1) { if (array_length(orbiting.p_feature[planet_num]) != 0) { with (orbiting) { scr_planetary_feature(planet_num); @@ -120,7 +120,7 @@ try_and_report_loop("player alarm 1", function() { var i; set_fleet_location(steh.name); if (steh.visited == 0) { - for (var plan_num = 1; plan_num < 5; plan_num++) { + for (var plan_num = 1; plan_num <= steh.planets; plan_num++) { if (array_length(steh.p_feature[plan_num]) != 0) { with (steh) { scr_planetary_feature(plan_num); @@ -171,4 +171,6 @@ try_and_report_loop("player alarm 1", function() { instance_activate_object(obj_star); } -}); +} catch (_exception) { + handle_exception(_exception); +} diff --git a/objects/obj_turn_end/Alarm_0.gml b/objects/obj_turn_end/Alarm_0.gml index b1678e8978..8bc27cfde5 100644 --- a/objects/obj_turn_end/Alarm_0.gml +++ b/objects/obj_turn_end/Alarm_0.gml @@ -1,5 +1,4 @@ -// show_message("biiiiiIIIng"); -try_and_report_loop("battle alarm 0 loop", function() { +try { instance_activate_object(obj_star); combating = 0; @@ -215,4 +214,6 @@ try_and_report_loop("battle alarm 0 loop", function() { /* */ /* */ -}); +} catch (_exception) { + handle_exception(_exception); +} diff --git a/scripts/scr_en_weapon/scr_en_weapon.gml b/scripts/scr_en_weapon/scr_en_weapon.gml index 19f1bfd61f..ca78237877 100644 --- a/scripts/scr_en_weapon/scr_en_weapon.gml +++ b/scripts/scr_en_weapon/scr_en_weapon.gml @@ -146,7 +146,6 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { spli = 3; break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } @@ -381,7 +380,6 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { spli = 3; break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } @@ -486,7 +484,6 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { spli = 3; break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } @@ -560,7 +557,6 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { rang = 20; break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } @@ -671,12 +667,11 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { amm = 1; break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } - if (obj_ncombat.enemy >= 10 || obj_ncombat.enemy == 2 || obj_ncombat.enemy == 5 || obj_ncombat.enemy == 1) { + if (obj_ncombat.enemy == eFACTION.CHAOS || obj_ncombat.enemy == eFACTION.HERETICS || obj_ncombat.enemy == eFACTION.IMPERIUM || obj_ncombat.enemy == eFACTION.ECCLESIARCHY || obj_ncombat.enemy == eFACTION.PLAYER) { switch (name) { case "Plasma Pistol": atta = 70; @@ -968,7 +963,6 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { spli = choose(0, 1); break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } @@ -1061,7 +1055,6 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { spli = 3; break; default: - LOGGER.debug($"Unknown weapon name: {name}; script: scr_en_weapon.gml"); break; } } @@ -1092,6 +1085,10 @@ function scr_en_weapon(name, is_man, man_number, man_type, group) { amm = -1; } + if (atta == 0) { + LOGGER.debug($"Weapon {name} has 0 attack!"); + } + var goody = 0; var first = -1; for (var b = 0; b < 30; b++) { diff --git a/scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml b/scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml index fe6ba3cf7b..bea9a3fded 100644 --- a/scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml +++ b/scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml @@ -280,7 +280,11 @@ function scr_enemy_ai_d() { } var garrison_mission = has_problem_planet_and_time(i, "provide_garrison", 0); if (garrison_mission > -1) { - try_and_report_loop("complete garrison mission", complete_garrison_mission, true, [i, garrison_mission]); + try { + complete_garrison_mission(i, garrison_mission); + } catch (_exception) { + handle_exception(_exception); + } } var _beast_hunt = has_problem_planet_and_time(i, "hunt_beast", 0); if (_beast_hunt > -1) { diff --git a/scripts/scr_inquisition_mission/scr_inquisition_mission.gml b/scripts/scr_inquisition_mission/scr_inquisition_mission.gml index 7bdfa4155b..bfcfa850bd 100644 --- a/scripts/scr_inquisition_mission/scr_inquisition_mission.gml +++ b/scripts/scr_inquisition_mission/scr_inquisition_mission.gml @@ -811,6 +811,7 @@ function necron_tomb_mission_sequence() { instance_deactivate_all(true); instance_activate_object(obj_controller); instance_activate_object(obj_ini); + instance_activate_object(obj_star); instance_create(0, 0, obj_ncombat); _roster = new Roster(); diff --git a/scripts/scr_kill_unit/scr_kill_unit.gml b/scripts/scr_kill_unit/scr_kill_unit.gml index cd8fc29ce9..d04ea2d92f 100644 --- a/scripts/scr_kill_unit/scr_kill_unit.gml +++ b/scripts/scr_kill_unit/scr_kill_unit.gml @@ -17,8 +17,7 @@ function scr_kill_unit(company, unit_slot) { } _unit.remove_from_squad(); scr_wipe_unit(company, unit_slot); - } - catch (ex) { + } catch (ex) { LOGGER.error($"company: {company}, unit_slot: {unit_slot}"); handle_exception(ex); } diff --git a/scripts/scr_logging_functions/scr_logging_functions.gml b/scripts/scr_logging_functions/scr_logging_functions.gml index ace8a2a03f..7ac740d52f 100644 --- a/scripts/scr_logging_functions/scr_logging_functions.gml +++ b/scripts/scr_logging_functions/scr_logging_functions.gml @@ -1,8 +1,9 @@ #macro STR_ERROR_MESSAGE_HEAD $"Your game just encountered and caught an error!" #macro STR_ERROR_MESSAGE_HEAD2 $"Your game just encountered a critical error! :(" #macro STR_ERROR_MESSAGE_HEAD3 "Your game just encountered and caught an error! ({0})" -#macro STR_ERROR_MESSAGE $"The error log is automatically copied into your clipboard and a copy is created at: \nC:>Users>(UserName)>AppData>Local>ChapterMaster>Logs\n\nPlease, follow these steps:\n1) Create a bug report on our 'Chapter Master Discord' server.\n2) Press CTRL+V to paste the error log.\n3) Title the report with the error log's first line.\n4) If the log isn't pasted, locate and attach the latest error log file.\n\nThank you!" #macro STR_ERROR_MESSAGE_PS $"P.S. You can ALT-TAB and try to continue playing, though it’s recommended to wait for a response in the bug-report forum." +#macro ERR_LOG_DIRECTORY "Logs/" +#macro ERR_PATH_LAST_MESSAGES "last_messages.log" enum eLOG_LEVEL { DEBUG, @@ -15,19 +16,48 @@ enum eLOG_LEVEL { /// @description Logs the _message into a file in the Logs folder. /// @param {string} _message - The message to log. function create_error_file(_message) { - if (string_length(_message) > 0) { - var _log_file = file_text_open_write($"Logs/{DATE_TIME_1}_error.log"); - file_text_write_string(_log_file, _message); - file_text_close(_log_file); + if (string_length(_message) == 0) { + return; } + + if (!directory_exists(ERR_LOG_DIRECTORY)) { + directory_create(ERR_LOG_DIRECTORY); + } + + var _log_file = file_text_open_write($"{ERR_LOG_DIRECTORY}{DATE_TIME_1}_error.log"); + file_text_write_string(_log_file, _message); + file_text_close(_log_file); + copy_last_messages_file(); } /// @description Creates a copy of the last_messages.log file, with the current date in the name, in the same folder. function copy_last_messages_file() { - if (file_exists(PATH_LAST_MESSAGES)) { - file_copy(PATH_LAST_MESSAGES, $"Logs/{DATE_TIME_1}_messages.log"); + if (!file_exists(ERR_PATH_LAST_MESSAGES)) { + return; + } + + if (!directory_exists(ERR_LOG_DIRECTORY)) { + directory_create(ERR_LOG_DIRECTORY); } + + file_copy(ERR_PATH_LAST_MESSAGES, $"{ERR_LOG_DIRECTORY}{DATE_TIME_1}_messages.log"); +} + +/// @desc Provides game-specific state data to the error handler without tight coupling. +/// @returns {Struct} +function error_get_context() { + var _context = { + chapter: global.chapter_name ?? "???", + seed: global.game_seed ?? "???", + turn: "???", + }; + + if (instance_exists(obj_controller)) { + _context.turn = obj_controller.turn; + } + + return _context; } /// @description Displays a popup, logs the error into file, and copies to clipboard. @@ -37,74 +67,53 @@ function copy_last_messages_file() { /// @param {string} _critical - Optional. /// @param {string} _report_title - Optional. Preset title for the bug report. function handle_error(_header, _message, _stacktrace = "", _critical = false, _report_title = "") { - var _full_message = ""; - var _header_section = ""; - var _info_section = ""; - var _save_section = ""; - var _error_section = ""; - var _footer_section = ""; - - _header_section += $"{LB_92}\n"; - _header_section += $"{_header}\n\n"; - _full_message += _header_section; - - // _info_section += $"Operating System: {os_type_format(os_type)}\n"; // Uncomment this when we start compiling for different platforms; - _info_section += $"Date-Time: {DATE_TIME_3}\n"; - _info_section += $"Game Version: {global.game_version}\n"; - _info_section += $"Build Date: {global.build_date}\n"; - _info_section += $"Commit Hash: {global.commit_hash}\n\n"; - _full_message += _info_section; - - if (global.chapter_name != "None") { - _save_section += $"Chapter Name: {global.chapter_name}\n"; + var _context = error_get_context(); + var _full_log = ""; + + var _sections = [ + LB_92, + _header, + "", + $"Date-Time: {DATE_TIME_3}", + $"Game Version: {global.game_version}", + $"Build Date: {global.build_date}", + $"Commit Hash: {global.commit_hash}", + "", + "Save Details:", + $"Chapter Name: {_context.chapter}", + $"Current Turn: {_context.turn}", + $"Game Seed: {_context.seed}", + "", + "Error Details:", + _message, + "", + "Stacktrace:", + _stacktrace, + LB_92 + ]; + + for (var i = 0, _len = array_length(_sections); i < _len; i++) { + _full_log += $"{_sections[i]}\n"; } - if (instance_exists(obj_controller)) { - _save_section += $"Current Turn: {obj_controller.turn}\n"; - } - if (global.game_seed != 0) { - _save_section += $"Game Seed: {global.game_seed}\n"; - } - if (_save_section != "") { - _full_message += "Save Details:\n"; - _full_message += $"{_save_section}\n"; - } - - _error_section += "Error Details:\n"; - _error_section += $"{_message}\n\n"; - _error_section += "Stacktrace:\n"; - _error_section += $"{_stacktrace}\n"; - _full_message += _error_section; - _footer_section += $"{LB_92}"; - _full_message += _footer_section; + var _error_file_text = (_report_title != "") ? $"{_report_title}\n{_full_log}" : _full_log; + create_error_file(_error_file_text); - if (_report_title != "") { - _report_title += "\n"; - } + var _clipboard = (_report_title != "") ? $"{_report_title}\n" : ""; + _clipboard += markdown_codeblock(_full_log, "log"); + clipboard_set_text(_clipboard); - var _error_file_text = $"{_report_title}{_full_message}"; - var _commit_history_link = ""; - if (global.commit_hash != "unknown hash") { - _commit_history_link = $"https://github.com/Adeptus-Dominus/ChapterMaster/commits/{global.commit_hash}"; - _error_file_text += $"\n{_commit_history_link}"; - } - - create_error_file(_error_file_text); - show_debug_message($"{_header_section}{_error_section}{_footer_section}"); + var _path_hint = string_replace(game_save_id, "/", "\\"); + var _player_msg = $"{_header}\n\n{_message}\n\n"; + _player_msg += $"The error log is in your clipboard and saved at:\n{_path_hint}Logs\\\n\n"; + _player_msg += "1) Create a bug report on Discord.\n2) Press CTRL+V to paste the log.\n\nThank you!"; - var _clipboard_message = ""; - _clipboard_message += $"{_report_title}"; - _clipboard_message += $"{markdown_codeblock(_full_message, "log")}\n"; - if (_commit_history_link != "") { - _clipboard_message += $"\n{_commit_history_link}"; + if (!_critical) { + _player_msg += $"\n\n{STR_ERROR_MESSAGE_PS}"; } - clipboard_set_text(_clipboard_message); - var _player_message = ""; - _player_message += $"{_header}\n\n"; - _player_message += $"{STR_ERROR_MESSAGE}"; - _player_message += _critical ? "" : $"\n\n{STR_ERROR_MESSAGE_PS}"; - show_message(_player_message); + show_debug_message(_full_log); + show_message(_player_msg); } /// @function handle_exception @@ -117,47 +126,27 @@ function handle_exception(_exception, custom_title = STR_ERROR_MESSAGE_HEAD, cri var _header = critical ? STR_ERROR_MESSAGE_HEAD2 : custom_title; var _message = _exception.longMessage; var _stacktrace = _exception.stacktrace; - - for (var i = 0; i < array_length(_stacktrace); i++) { - _stacktrace[i] = clean_stacktrace_line(_stacktrace[i]); - } - - _stacktrace = array_to_string_list(_stacktrace); + clean_stacktrace(_stacktrace); var _critical = critical ? "CRASH! " : ""; var _build_date = global.build_date == "unknown build" ? "" : $"/{global.build_date}"; - var _problem_line = clean_stacktrace_line(_exception.stacktrace[0]); + var _problem_line = (array_length(_stacktrace) > 0) ? _stacktrace[0] : "unknown"; var _report_title = $"{_critical}[{global.game_version}{_build_date}] {_problem_line}"; - handle_error(_header, _message, _stacktrace, critical, _report_title); -} + _stacktrace = array_to_string_list(_stacktrace); -/// @description Attempts to run a function and reports any errors caught. -/// @param {string} dev_marker - Developer marker for the error. -/// @param {function} func - The function to run. -/// @param {bool} turn_end - Whether to end the turn after an error. -/// @param {array} args - Arguments to pass to the function. -/// @param {function} catch_custom - Custom function to run on error. -/// @param {array} catch_args - Arguments to pass to the custom function. -function try_and_report_loop(dev_marker = "Generic Error", func, turn_end = true, args = [], catch_custom = 0, catch_args = []) { - try { - method_call(func, args); - } catch (_exception) { - handle_exception(_exception, string(STR_ERROR_MESSAGE_HEAD3, dev_marker), false, dev_marker); - if (is_method(catch_custom)) { - method_call(catch_custom, catch_args); - } - } + handle_error(_header, _message, _stacktrace, critical, _report_title); } /// @description Shows a popup for errors triggered by an unexpected condition(s). /// @param {string} _message - The message to display to the user. -/// @param {string} _header - Optional header for the popup (default: "Assertion Error"). -function assert_error_popup(_message, _header = "Assertion Error") { +/// @param {string} _header - Optional header for the popup (default: "Your game just encountered an error!"). +function assert_error_popup(_message, _header = "Your game just encountered an error!") { var _stacktrace_array = debug_get_callstack(); array_shift(_stacktrace_array); // throw away the first line, it's this function array_pop(_stacktrace_array); // and the last line, it's the `0` debug_get_callstack returns for the top of the stack + clean_stacktrace(_stacktrace_array); var _stacktrace = array_to_string_list(_stacktrace_array); @@ -183,10 +172,7 @@ function markdown_codeblock(_message, _language = "") { /// @param {real} _time - Usually hours, minutes or seconds. /// @returns {string} function format_time(_time) { - if (_time < 10) { - _time = $"0{_time}"; - } - return string(_time); + return (_time < 10) ? $"0{_time}" : string(_time); } function clean_callstack_prefixes(_string) { @@ -196,7 +182,15 @@ function clean_callstack_prefixes(_string) { return _string; } -/// @desc Reformats: "Location > L[Num] > Method > Code Snippet" +/// @desc Reformats: "Location:[LineNum] > Method > Code Snippet" +/// @param {array} _stacktrace_array The array from debug_get_callstack() +function clean_stacktrace(_stacktrace_array) { + for (var i = 0, l = array_length(_stacktrace_array); i < l; i++) { + _stacktrace_array[@ i] = clean_stacktrace_line(_stacktrace_array[i]); + } +} + +/// @desc Reformats: "Location:[LineNum] > Method > Code Snippet" /// @param {string} _line_string The raw string from debug_get_callstack() /// @returns {string} function clean_stacktrace_line(_line_string) { diff --git a/scripts/scr_mission_functions/scr_mission_functions.gml b/scripts/scr_mission_functions/scr_mission_functions.gml index b487a41fa0..45e5c4c91c 100644 --- a/scripts/scr_mission_functions/scr_mission_functions.gml +++ b/scripts/scr_mission_functions/scr_mission_functions.gml @@ -806,4 +806,3 @@ function locations_are_equal(_first_loc, _second_loc) { return (_first_loc[1] == _second_loc[1]) && (_first_loc[0] == _second_loc[0]); } - diff --git a/scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml b/scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml index de9e87d813..d29adc46ff 100644 --- a/scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml +++ b/scripts/scr_specialist_point_handler/scr_specialist_point_handler.gml @@ -141,7 +141,11 @@ function SpecialistPointHandler() constructor { static calculate_research_points = function(turn_end) { self.turn_end = turn_end; - try_and_report_loop("Specialist points logic", pre_error_wrapped_research_points); + try { + pre_error_wrapped_research_points(); + } catch (ex) { + handle_exception(ex); + } }; static new_tech_heretic_spawn = function() { diff --git a/scripts/scr_system_search_helpers/scr_system_search_helpers.gml b/scripts/scr_system_search_helpers/scr_system_search_helpers.gml index b88d99852b..c40a2fb052 100644 --- a/scripts/scr_system_search_helpers/scr_system_search_helpers.gml +++ b/scripts/scr_system_search_helpers/scr_system_search_helpers.gml @@ -216,11 +216,19 @@ function planet_imperium_ground_total(planet_check) { /// Returns the `obj_star` instance that matches `search_name`, /// or the string `"none"` if no matching star is found. function star_by_name(search_name) { + if (!instance_exists(obj_star)) { + assert_error_popup("Not a single instance of obj_star exists!"); + return "none"; + } + with (obj_star) { if (name == search_name) { return self; } } + + assert_error_popup($"Star {search_name} wasn't found!"); + return "none"; }