diff --git a/ChapterMaster.yyp b/ChapterMaster.yyp index 683ee7deca..d429ee622e 100644 --- a/ChapterMaster.yyp +++ b/ChapterMaster.yyp @@ -709,7 +709,6 @@ {"id":{"name":"obj_temp3","path":"objects/obj_temp3/obj_temp3.yy",},}, {"id":{"name":"obj_temp5","path":"objects/obj_temp5/obj_temp5.yy",},}, {"id":{"name":"obj_temp6","path":"objects/obj_temp6/obj_temp6.yy",},}, - {"id":{"name":"obj_temp7","path":"objects/obj_temp7/obj_temp7.yy",},}, {"id":{"name":"obj_temp8","path":"objects/obj_temp8/obj_temp8.yy",},}, {"id":{"name":"obj_timer","path":"objects/obj_timer/obj_timer.yy",},}, {"id":{"name":"obj_tooltip","path":"objects/obj_tooltip/obj_tooltip.yy",},}, @@ -754,6 +753,7 @@ {"id":{"name":"ErrorHandler","path":"scripts/ErrorHandler/ErrorHandler.yy",},}, {"id":{"name":"exp_and_exp_growth","path":"scripts/exp_and_exp_growth/exp_and_exp_growth.yy",},}, {"id":{"name":"explode_script","path":"scripts/explode_script/explode_script.yy",},}, + {"id":{"name":"FleetProblem","path":"scripts/FleetProblem/FleetProblem.yy",},}, {"id":{"name":"GitHub","path":"scripts/GitHub/GitHub.yy",},}, {"id":{"name":"GitHubBugReporter","path":"scripts/GitHubBugReporter/GitHubBugReporter.yy",},}, {"id":{"name":"GitHubContent","path":"scripts/GitHubContent/GitHubContent.yy",},}, @@ -774,6 +774,7 @@ {"id":{"name":"NameGenerator","path":"scripts/NameGenerator/NameGenerator.yy",},}, {"id":{"name":"NotificationAlert","path":"scripts/NotificationAlert/NotificationAlert.yy",},}, {"id":{"name":"object_get_depth","path":"scripts/object_get_depth/object_get_depth.yy",},}, + {"id":{"name":"PlanetProblem","path":"scripts/PlanetProblem/PlanetProblem.yy",},}, {"id":{"name":"scr_add_corruption","path":"scripts/scr_add_corruption/scr_add_corruption.yy",},}, {"id":{"name":"scr_add_item","path":"scripts/scr_add_item/scr_add_item.yy",},}, {"id":{"name":"scr_add_man","path":"scripts/scr_add_man/scr_add_man.yy",},}, @@ -993,6 +994,7 @@ {"id":{"name":"SectorHandler","path":"scripts/SectorHandler/SectorHandler.yy",},}, {"id":{"name":"Set","path":"scripts/Set/Set.yy",},}, {"id":{"name":"SettingsManager","path":"scripts/SettingsManager/SettingsManager.yy",},}, + {"id":{"name":"SystemProblem","path":"scripts/SystemProblem/SystemProblem.yy",},}, {"id":{"name":"TooltipBuilder","path":"scripts/TooltipBuilder/TooltipBuilder.yy",},}, {"id":{"name":"turn_towards_point","path":"scripts/turn_towards_point/turn_towards_point.yy",},}, {"id":{"name":"UIComponents","path":"scripts/UIComponents/UIComponents.yy",},}, diff --git a/docs/CHEATCODES.md b/docs/CHEATCODES.md index fc333cdd6e..7f33aa9817 100644 --- a/docs/CHEATCODES.md +++ b/docs/CHEATCODES.md @@ -71,7 +71,6 @@ Arguments with stars `(argument*)` can be omitted. - `mechmission (mission*)` - triggers a mechaniicus mission, can be run as is or with an optional missiono parameter to specify a particular mission - `mech_mars` - `mech_raider` - - `mech_bionics` ### Disposition: diff --git a/objects/obj_bomb_select/Alarm_1.gml b/objects/obj_bomb_select/Alarm_1.gml index fa56abb0a9..e88a1be40b 100644 --- a/objects/obj_bomb_select/Alarm_1.gml +++ b/objects/obj_bomb_select/Alarm_1.gml @@ -5,7 +5,7 @@ ship_use = []; ship_max = []; ship_ide = []; -var _ships = fleet_full_ship_array(sh_target); +var _ships = sh_target.full_ship_array(); max_ships = array_length(_ships); bomb_a = calculate_fleet_bombard_score(_ships); var _total_fleet_loaded = calculate_fleet_content_size(_ships); diff --git a/objects/obj_drop_select/Create_0.gml b/objects/obj_drop_select/Create_0.gml index 4bf9159e25..54c153de0d 100644 --- a/objects/obj_drop_select/Create_0.gml +++ b/objects/obj_drop_select/Create_0.gml @@ -155,6 +155,7 @@ btn_back.button_color = CM_GREEN_COLOR; btn_back.width = 90; if (purge == 0) { + var _p_data = p_target.get_planet_data(planet_number); sisters = p_target.p_sisters[planet_number]; eldar = p_target.p_eldar[planet_number]; ork = p_target.p_orks[planet_number]; @@ -211,11 +212,11 @@ if (purge == 0) { } var spesh = false; - if ((planet_feature_bool(p_target.p_feature[planet_number], eP_FEATURES.WARLORD10) == 1) && (obj_controller.faction_defeated[10] == 0) && (obj_controller.faction_gender[10] == 1) && (obj_controller.known[eFACTION.CHAOS] > 0) && (obj_controller.turn >= obj_controller.chaos_turn)) { + if ((_p_data.has_feature(eP_FEATURES.WARLORD10)) && (obj_controller.faction_defeated[10] == 0) && (obj_controller.faction_gender[10] == 1) && (obj_controller.known[eFACTION.CHAOS] > 0) && (obj_controller.turn >= obj_controller.chaos_turn)) { spesh = true; } - if (has_problem_planet(planet_number, "tyranid_org", p_target)) { + if (_p_data.has_problem("inquisition_tyranid_org")) { tyranids = 2; attacking = 9; } diff --git a/objects/obj_en_fleet/Alarm_1.gml b/objects/obj_en_fleet/Alarm_1.gml index f663259b03..94beda6cc4 100644 --- a/objects/obj_en_fleet/Alarm_1.gml +++ b/objects/obj_en_fleet/Alarm_1.gml @@ -1,6 +1,4 @@ try { - var orb = orbiting; - if ((round(owner) != eFACTION.IMPERIUM) && (navy == 1)) { owner = 0; } @@ -205,15 +203,6 @@ try { } } - if (owner == eFACTION.TAU) { - if (instance_exists(obj_p_fleet) && (obj_controller.known[eFACTION.TAU] == 0)) { - var p_ship = instance_nearest(x, y, obj_p_fleet); - if ((p_ship.action == "") && (point_distance(x, y, p_ship.x, p_ship.y) <= 80)) { - obj_controller.known[eFACTION.TAU] = 1; - } - } - } - if (owner == eFACTION.TYRANIDS) { // Juggle bio-resources if (capital_number * 2 > frigate_number) { diff --git a/objects/obj_en_fleet/Create_0.gml b/objects/obj_en_fleet/Create_0.gml index 0b40e29fcc..aa4d9c7dee 100644 --- a/objects/obj_en_fleet/Create_0.gml +++ b/objects/obj_en_fleet/Create_0.gml @@ -81,9 +81,9 @@ escort_health = 100; /// Called from save function to take all object variables and convert them to a json savable format and return it serialize = function() { - var object_fleet = self; + var _object_fleet = self; - var save_data = { + var _save_data = { obj: object_get_name(object_index), x, y, @@ -98,11 +98,11 @@ serialize = function() { "in_view", ]; - copy_serializable_fields(object_fleet, save_data, excluded_from_save); + copy_serializable_fields(_object_fleet, _save_data, excluded_from_save); - return save_data; + return _save_data; }; -deserialize = function(save_data) { +deserialize = function(_save_data) { var exclusions = [ "id", "cargo_data", @@ -110,22 +110,22 @@ deserialize = function(save_data) { ]; // skip automatic setting of certain vars, handle explicitly later // Automatic var setting - var all_names = struct_get_names(save_data); - var _len = array_length(all_names); + var _all_names = struct_get_names(_save_data); + var _len = array_length(_all_names); for (var i = 0; i < _len; i++) { - var var_name = all_names[i]; - if (array_contains(exclusions, var_name)) { + var _var_name = _all_names[i]; + if (array_contains(exclusions, _var_name)) { continue; } - var loaded_value = struct_get(save_data, var_name); + var _loaded_value = struct_get(_save_data, _var_name); try { - variable_instance_set(self, var_name, loaded_value); + variable_instance_set(self, _var_name, _loaded_value); } catch (e) { LOGGER.exception("Deserialization failed", e); } } - if (struct_exists(save_data, "cargo_data")) { - variable_instance_set(self, "cargo_data", save_data.cargo_data); + if (struct_exists(_save_data, "cargo_data")) { + variable_instance_set(self, "cargo_data", _save_data.cargo_data); if (fleet_has_cargo("ork_warboss")) { var _boss = new NewPlanetFeature(eP_FEATURES.ORKWARBOSS); _boss.load_json_data(cargo_data.ork_warboss); diff --git a/objects/obj_en_fleet/Step_0.gml b/objects/obj_en_fleet/Step_0.gml index 03eda8829f..00182c8f7e 100644 --- a/objects/obj_en_fleet/Step_0.gml +++ b/objects/obj_en_fleet/Step_0.gml @@ -67,15 +67,9 @@ if (ii_check == 0) { } } -if (owner == eFACTION.TYRANIDS) { +if (owner == eFACTION.TYRANIDS && orbiting != noone) { image_alpha = 0; - if (instance_exists(obj_p_fleet)) { - var bundy = instance_nearest(x, y, obj_p_fleet); - if ((bundy.action == "") && (self.action == "") && (point_distance(bundy.x, bundy.y, x, y) < 90) && (bundy.x > x) && (bundy.y < y)) { - image_alpha = 1; - } - } - if ((instance_nearest(x, y - 32, obj_star).vision == 1) && (action == "")) { + if (orbiting.has_orbiting_player_fleet() || orbiting.vision == 1){ image_alpha = 1; } } @@ -146,30 +140,7 @@ if ((owner == eFACTION.TYRANIDS) && (trade_goods == "")) { } if (global.load >= 0) { - if (owner == eFACTION.IMPERIUM) { - sprite_index = spr_fleet_imperial; - } - if (owner == eFACTION.MECHANICUS) { - sprite_index = spr_fleet_mechanicus; - } - if (owner == eFACTION.INQUISITION) { - sprite_index = spr_fleet_inquisition; - } - if (owner == eFACTION.ELDAR) { - sprite_index = spr_fleet_eldar; - } - if (owner == eFACTION.ORK) { - sprite_index = spr_fleet_ork; - } - if (owner == eFACTION.TAU) { - sprite_index = spr_fleet_tau; - } - if (owner == eFACTION.TYRANIDS) { - sprite_index = spr_fleet_tyranid; - } - if (owner == eFACTION.CHAOS) { - sprite_index = spr_fleet_chaos; - } + choose_fleet_sprite_image(); } if (image_index == 0) { image_index = 1; diff --git a/objects/obj_enunit/Create_0.gml b/objects/obj_enunit/Create_0.gml index 8746fb2f92..eebd60e8e9 100644 --- a/objects/obj_enunit/Create_0.gml +++ b/objects/obj_enunit/Create_0.gml @@ -9,7 +9,7 @@ hostile_splash = 0; flank = 0; flyer = 0; // Works same as flank, but does not get denoted as such neww = 0; - +enemy_dudes = 0; column_size = 0; unit_count = 0; @@ -75,6 +75,26 @@ dudes_wep2 = array_create(_array_size, ""); dudes_gear = array_create(_array_size, ""); dudges_mobi = array_create(_array_size, ""); +add_enemies = function(enemy_data){ + var _start_index = 1; + for (var i = 1; i < _array_size; i++) + if (dudes[i] == ""){ + _start_index = i; + } + { + + } + for (var i = 0; i < array_length(enemy_data); i++){ + var _data = enemy_data[i]; + dudes[_start_index] = _data.name; + dudes_num[_start_index] = _data.number; + if (struct_exists(_data, "special")){ + dudes_special[_start_index] = _data.special; + } + _start_index++; + enemy_dudes += _data.number; + } +} alarm[1] = 5; hit = function() { diff --git a/objects/obj_fleet_select/Create_0.gml b/objects/obj_fleet_select/Create_0.gml index be7f34968d..9531fd28fe 100644 --- a/objects/obj_fleet_select/Create_0.gml +++ b/objects/obj_fleet_select/Create_0.gml @@ -76,7 +76,7 @@ selection_window.inside_method = function() { var math_string = (string_width("Manage Units") / 2) + 6; if (point_and_click(draw_unit_buttons([center_draw - math_string, yy + height - 50], "Manage Units", [1, 1], c_blue))) { - var _fleet_array = fleet_full_ship_array(current_fleet); + var _fleet_array = current_fleet.full_ship_array(); var _fleet_marines = collect_role_group("all", ["", 0, _fleet_array]); group_selection(_fleet_marines, {purpose: "Ship Management", purpose_code: "manage", number: 0, system: 0, ships: _fleet_array, feature: "none", planet: 0, selections: []}); diff --git a/objects/obj_ini/Create_0.gml b/objects/obj_ini/Create_0.gml index e468be16f6..fc76fe3912 100644 --- a/objects/obj_ini/Create_0.gml +++ b/objects/obj_ini/Create_0.gml @@ -241,21 +241,21 @@ deserialize = function(save_data) { ]; // skip automatic setting of certain vars, handle explicitly later // Automatic var setting - var all_names = struct_get_names(save_data); + var _all_names = struct_get_names(save_data); - if (!array_contains(all_names, "chapter_squad_arrangement")) { + if (!array_contains(_all_names, "chapter_squad_arrangement")) { chapter_squad_arrangement = json_to_gamemaker(working_directory + $"main/squads/company_squad_builds.json", json_parse); } - for (var i = 0; i < array_length(all_names); i++) { - var var_name = all_names[i]; - if (array_contains(exclusions, var_name)) { + for (var i = 0; i < array_length(_all_names); i++) { + var _var_name = _all_names[i]; + if (array_contains(exclusions, _var_name)) { continue; } - var loaded_value = struct_get(save_data, var_name); + var loaded_value = struct_get(save_data, _var_name); try { - variable_instance_set(id, var_name, loaded_value); + variable_instance_set(id, _var_name, loaded_value); } catch (e) { LOGGER.exception("Deserialization failed", e); } diff --git a/objects/obj_ncombat/Alarm_0.gml b/objects/obj_ncombat/Alarm_0.gml index 49add2da9d..5bf96711c6 100644 --- a/objects/obj_ncombat/Alarm_0.gml +++ b/objects/obj_ncombat/Alarm_0.gml @@ -82,14 +82,14 @@ try { alpha_strike = 1; } - if ((battle_special == "study2a") || (battle_special == "study2b")) { + if (battle_special == "mars_tomb") { ally = 3; ally_forces = 1; } xxx = instance_nearest(1000, 240, obj_pnunit).x + 80; - if ((string_count("spyrer", battle_special) > 0) || (string_count("fallen", battle_special) > 0) || (string_count("mech", battle_special) > 0) || (battle_special == "space_hulk") || (battle_special == "study2a") || (battle_special == "study2b")) { + if ((string_count("mech", battle_special) > 0) || (battle_special == "space_hulk") || (battle_special == "mars_tomb")) { fortified = 0; } @@ -131,65 +131,29 @@ try { u.column = (_num - j) - ((xxx / 10) - 10); } - // *** Enemy Forces Special Event *** - // * Malcadon Spyrer * - if (string_count("spyrer", battle_special) > 0) { - fortified = 0; - with (obj_enunit) { - instance_destroy(); - } - u = instance_create(10, 240, obj_enunit); - enemy_dudes = "1"; - u.dudes[1] = "Malcadon Spyrer"; - u.dudes_num[1] = 1; - u.dudes_num[1] = 1; - enemies[1] = 1; - u.flank = 1; - } - - if (battle_special == "protect_raiders") { - fortified = 0; - threat = 3; - u = instance_create(20, 240, obj_enunit); - u.dudes[1] = "Dire Avenger"; - u.dudes_num[1] = 40; - u.dudes_special[1] = "shimmershield"; - u.dudes[2] = "Dire Avenger Exarch"; - u.dudes_num[2] = 4; - u.dudes_special[2] = "shimmershield"; - u.dudes[3] = "Autarch"; - u.dudes_num[3] = 1; - u.dudes[4] = "Farseer"; - u.dudes_num[4] = 1; - u.dudes_special[4] = "farseer_powers"; - u.dudes[5] = "Night Spinner"; - u.dudes_num[5] = 1; - u.enemy = eFACTION.ELDAR; - } - // * Small Fallen Group * - if (battle_special == "fallen1") { - fortified = 0; - with (obj_enunit) { - instance_destroy(); - } - u = instance_create(80, 240, obj_enunit); - enemy_dudes = "1"; - u.dudes[1] = "Fallen"; - u.dudes_num[1] = 1; - enemies[1] = 1; - } - // * Large Fallen Group * - if (battle_special == "fallen2") { - fortified = 0; - with (obj_enunit) { - instance_destroy(); + var _enemies_assigned = false; + if (!is_undefined(battle_enemy_data)){ + move_data_to_curret_scope(battle_enemy_data); + if (struct_exists(battle_enemy_data , "cols")){ + var _cols = battle_enemy_data.cols; + for (var i = 0; i < array_length(_cols); i++){ + var _col = _cols[i]; + if (struct_exists(_col , "engaged") && (_col.engaged)){ + u = instance_create(instance_nearest(x + 1000, 240, obj_pnunit).x + 10, 240, obj_enunit); + u.engaged = true; + with (instance_nearest(x + 1000, 240, obj_pnunit)) { + engaged = 1; + } + } else { + u = instance_create(_col.distance, 240, obj_enunit); + } + u.flank = struct_exists(_col, "flank") && _col.flank; + u.add_enemies(_col.enemies); + } + _enemies_assigned = true; } - u = instance_create(80, 240, obj_enunit); - enemy_dudes = "1"; - u.dudes[1] = "Fallen"; - u.dudes_num[1] = choose(1, 1, 2, 2, 3); - enemies[1] = u.dudes_num[1]; } + if (!_enemies_assigned){ // * Praetorian Servitor Group * if (string_count("mech", battle_special) > 0) { fortified = 0; @@ -223,60 +187,7 @@ try { engaged = 1; } } - // * Necron Wraith Group * - if (battle_special == "wraith_attack") { - fortified = 0; - with (obj_enunit) { - instance_destroy(); - } - u = instance_create(instance_nearest(x + 1000, 240, obj_pnunit).x + 10, 240, obj_enunit); - enemy_dudes = "2"; - u.dudes[1] = "Necron Wraith"; - u.dudes_num[1] = 1; - enemies[1] = 1; - u.dudes[2] = "Necron Wraith"; - u.dudes_num[2] = 1; - enemies[2] = 1; - u.engaged = 1; - with (instance_nearest(x + 1000, 240, obj_pnunit)) { - engaged = 1; - } - } - // * Canoptek Spyder Group * - if (battle_special == "spyder_attack") { - fortified = 0; - with (obj_enunit) { - instance_destroy(); - } - u = instance_create(instance_nearest(x + 1000, 240, obj_pnunit).x + 10, 240, obj_enunit); - enemy_dudes = "21"; - u.dudes[1] = "Canoptek Spyder"; - u.dudes_num[1] = 1; - enemies[1] = u.dudes[1]; - u.dudes[2] = "Canoptek Scarab"; - u.dudes_num[2] = 20; - enemies[2] = u.dudes[2]; - u.engaged = 1; - with (instance_nearest(x + 1000, 240, obj_pnunit)) { - engaged = 1; - } - } - // * Tomb Stalker Group * - if (battle_special == "stalker_attack") { - fortified = 0; - with (obj_enunit) { - instance_destroy(); - } - u = instance_create(instance_nearest(x + 1000, 240, obj_pnunit).x + 10, 240, obj_enunit); - enemy_dudes = "1"; - u.dudes[1] = "Tomb Stalker"; - u.dudes_num[1] = 1; - enemies[1] = 1; - u.engaged = 1; - with (instance_nearest(x + 1000, 240, obj_pnunit)) { - engaged = 1; - } - } + // * Chaos Space Marine Elite Group * if ((battle_special == "cs_meeting_battle5") || (battle_special == "cs_meeting_battle6")) { fortified = 0; @@ -326,28 +237,7 @@ try { u.dudes_num[2] = 3; enemies[2] = 3; } - // * Tomb world attack enemy setup * - if (battle_special == "wake1_attack") { - enemy = eFACTION.NECRONS; - threat = 2; - } - if (battle_special == "wake2_attack") { - enemy = eFACTION.NECRONS; - threat = 3; - } - if (battle_special == "wake3_attack") { - enemy = eFACTION.NECRONS; - threat = 5; - } - // * Tomb world study attack enemy setup * - if (battle_special == "study2a") { - enemy = eFACTION.NECRONS; - threat = 2; - } - if (battle_special == "study2b") { - enemy = eFACTION.NECRONS; - threat = 3; - } + // ** Space Hulk Forces ** if (battle_special == "space_hulk") { var make; @@ -1811,7 +1701,7 @@ try { // ** Tyranid Forces ** // Tyranid story event - if ((enemy == eFACTION.TYRANIDS) || (battle_special == "tyranid_org")) { + if (enemy == eFACTION.TYRANIDS) { u = instance_nearest(xxx, 240, obj_enunit); enemy_dudes = "81"; u.dudes[1] = "Termagaunt"; @@ -2086,7 +1976,7 @@ try { } // ** Chaos Forces ** - if ((enemy == eFACTION.CHAOS) && (battle_special != "ship_demon") && (battle_special != "fallen1") && (battle_special != "fallen2") && (battle_special != "WL10_reveal") && (battle_special != "WL10_later") && (string_count("cs_meeting_battle", battle_special) == 0)) { + if ((enemy == eFACTION.CHAOS) && (battle_special != "ship_demon") && (battle_special != "WL10_reveal") && (battle_special != "WL10_later") && (string_count("cs_meeting_battle", battle_special) == 0)) { // Small Chaos Cult Group if (threat == 1) { u = instance_nearest(xxx, 240, obj_enunit); @@ -2993,7 +2883,7 @@ try { } // ** Necron Forces ** - if ((enemy == eFACTION.NECRONS) && ((string_count("_attack", battle_special) == 0) || (string_count("wake", battle_special) > 0))) { + if (enemy == eFACTION.NECRONS) { // Small Necron Group if (threat == 1) { u = instance_nearest(xxx, 240, obj_enunit); @@ -3178,6 +3068,7 @@ try { u.flank = 1; } } + } // ** Set up player defenses ** if (player_defenses + player_silos > 0) { diff --git a/objects/obj_ncombat/Alarm_1.gml b/objects/obj_ncombat/Alarm_1.gml index 81916c39e1..35b4d6cb51 100644 --- a/objects/obj_ncombat/Alarm_1.gml +++ b/objects/obj_ncombat/Alarm_1.gml @@ -95,13 +95,13 @@ if (battle_special == "") { } } } -if (string_count("spyrer", battle_special) > 0) { +if (battle_special == "inquisition_spyrer") { p1 = "Your marines search through the alleyways and corridors likely to contain the Spyrer. It does not take long before the lunatic attacks, springing off from a wall to fall among your men. Your ranks are made up of "; } -if (string_count("protect_raiders", battle_special) > 0) { +if (battle_special == "protect_raiders") { p1 = "Following responses from scans, Your marine squad deploys and lies in wait on the planets surface. Either the eldar were expecting you or the scope of the raids on the planet had been underplayed by the governor perhaps to hide his incompetence in allowing such foul xenos actions to persist unchecked for so long."; } -if (string_count("fallen", battle_special) > 0) { +if (battle_special == "hunt_fallen") { p1 = "Your marines search through the alleyways and dens likely to contain the Fallen. Several days pass before the search is succesful; the prey is located by Auspex and closed in upon. "; if (battle_climate == "Lava") { p1 = "Your marines search through the broken craggs and spires of the molten planet. Among the bubbling lava, and cracking earth, they search for the Fallen. After several days of searching Auspex detect the prey. "; @@ -127,7 +127,7 @@ if (string_count("fallen", battle_special) > 0) { p1 += " Your ranks are made up of "; } -if (string_count("_attack", battle_special) > 0) { +if ("inquisition_tomb" == battle_special) { var wh = choose(1, 2); if (wh == 1) { p1 = "Cave dirt crunches beneath the soles of your marines as they continue their descent. There is little warning before "; @@ -136,26 +136,26 @@ if (string_count("_attack", battle_special) > 0) { p1 = "The shadows stretch and morph as the lights cast by your marines move along. One large shadow begins to move on its own- "; } - if (string_count("wake", battle_special) > 0) { + if (special_feature.data.tomb_awakens) { p1 = "Cave dirt crunches beneath the soles of your marines as they continue their descent. There is little warning when the ground begins to shake. An old, dusty breeze seems to flow through the tunnel, followed by rumbling sensations and distant mechanical sounds. "; - if (string_count("1", battle_special) > 0) { + if (threat == 2) { p1 += "Within minutes Necrons begin to appear from every direction. There appears to be nearly fourty, cramped in the dark tunnels."; } - if (string_count("2", battle_special) > 0) { + else if (threat == 3) { p1 += "Within minutes Necrons begin to appear from every direction. There appears to be nearly a hundred, cramped in the dark tunnels."; } - if (string_count("3", battle_special) > 0) { + else if (threat == 4) { p1 += "Within minutes Necrons begin to appear from every direction. Their numbers are wihout number."; } - } + } - if (string_count("wraith", battle_special) > 0) { + if (special_feature.data.enemy == "wraith") { p1 += "two Necron Wraiths appear out of nowhere and begin to attack."; } - if (string_count("spyder", battle_special) > 0) { + if (special_feature.data.enemy == "spyder") { p1 += "a large Canoptek Spyder launches towards your marines, a small group of scuttling Scarabs quickly following."; } - if (string_count("stalker", battle_special) > 0) { + if (special_feature.data.enemy == "stalker") { p1 += "the tunnel begins to shake and a massive Tomb Stalker scuttles into your midst."; } _newline = p1; diff --git a/objects/obj_ncombat/Alarm_5.gml b/objects/obj_ncombat/Alarm_5.gml index ea5468bad1..6c4a6a3690 100644 --- a/objects/obj_ncombat/Alarm_5.gml +++ b/objects/obj_ncombat/Alarm_5.gml @@ -282,13 +282,6 @@ if (slime > 0) { instance_activate_object(obj_star); -var reduce_fortification = true; -if (battle_special == "tyranid_org") { - reduce_fortification = false; -} -if (string_count("_attack", battle_special) > 0) { - reduce_fortification = false; -} if (battle_special == "ship_demon") { reduce_fortification = false; } @@ -301,18 +294,6 @@ if (battle_special == "ruins") { if (battle_special == "ruins_eldar") { reduce_fortification = false; } -if (battle_special == "fallen1") { - reduce_fortification = false; -} -if (battle_special == "fallen2") { - reduce_fortification = false; -} -if (battle_special == "study2a") { - reduce_fortification = false; -} -if (battle_special == "study2b") { - reduce_fortification = false; -} if ((fortified > 0) && (!instance_exists(obj_nfort)) && (reduce_fortification == true)) { var _fortification_text = $"Fortification level of {p_data.name()}"; @@ -361,30 +342,21 @@ if (string_count("ruins", battle_special) > 0) { combat_log.push(_newline, eMSG_COLOR.YELLOW); } -var _reduce_power = true; - // Events that should *not* reduce power var _non_power_reduce_events = [ - "tyranid_org", "ship_demon", "space_hulk", - "fallen1", - "fallen2", - "study2a", - "study2b", - "protect_raiders", ]; // Disable power reduction for matching events if (array_contains(_non_power_reduce_events, battle_special)) { - _reduce_power = false; -} else if (string_count("_attack", battle_special) > 0) { - _reduce_power = false; -} else if (string_count("ruins", battle_special) > 0) { - _reduce_power = false; + reduce_power = false; +} +else if (string_count("ruins", battle_special) > 0) { + reduce_power = false; } -if (defeat == 0 && _reduce_power) { +if (defeat == 0 && reduce_power) { var enemy_power = 0, new_power = 0, power_reduction = 0, requisition_reward = 0; if (enemy == eFACTION.IMPERIUM) { @@ -569,31 +541,10 @@ if (defeat == 0 && _reduce_power) { } } -if ((defeat == 0) && (enemy == eFACTION.TYRANIDS) && (battle_special == "tyranid_org")) { - _newline = $"{string_plural_count("Gaunt organism", captured_gaunt)} have been captured."; - combat_log.push(_newline, eMSG_COLOR.YELLOW); - - if (captured_gaunt > 0) { - var why = 0, thatta = 0; - instance_activate_object(obj_star); - with (obj_star) { - remove_star_problem("tyranid_org"); - } - } - - scr_event_log("", "Inquisition Mission Completed: A Gaunt organism has been captured for the Inquisition."); - - if (captured_gaunt > 1) { - if (instance_exists(obj_turn_end)) { - scr_popup("Inquisition Mission Completed", "You have captured several Gaunt organisms. The Inquisitor is pleased with your work, though she notes that only one is needed- the rest are to be purged. It will be stored until it may be retrieved. The mission is a success.", "inquisition", ""); - } - } - if (captured_gaunt == 1) { - if (instance_exists(obj_turn_end)) { - scr_popup("Inquisition Mission Completed", "You have captured a Gaunt organism- the Inquisitor is pleased with your work. The Tyranid will be stored until it may be retrieved. The mission is a success.", "inquisition", ""); - } +if (battle_special != ""){ + if (is_struct(special_feature) && is_instanceof(special_feature, PlanetProblem)){ + special_feature.battle_final_message(); } - instance_deactivate_object(obj_star); } _newline = line_break; diff --git a/objects/obj_ncombat/Alarm_7.gml b/objects/obj_ncombat/Alarm_7.gml index 5a6141bf41..0d4cad7fc2 100644 --- a/objects/obj_ncombat/Alarm_7.gml +++ b/objects/obj_ncombat/Alarm_7.gml @@ -190,28 +190,6 @@ try { } } - if ((battle_special == "study2a") || (battle_special == "study2b")) { - if (defeat == 1) { - if (remove_planet_problem(battle_id, "mech_tomb", battle_object)) { - obj_controller.disposition[3] -= 10; - - if (battle_special == "study2a") { - scr_popup("Mechanicus Mission Failed", "All of your Astartes and the Mechanicus Research party have been killed down to the last man. The research is a bust, and the Adeptus Mechanicus is furious with your chapter for not providing enough security. Relations with them are worse than before.", "", ""); - } - if (battle_special == "study2b") { - battle_object.p_necrons[battle_id] = 5; - awaken_tomb_world(battle_object.p_feature[battle_id]); - alter_dispositions([[eFACTION.MECHANICUS, -15], [eFACTION.INQUISITION, -5]]); - scr_popup("Mechanicus Mission Failed", "All of your Astartes and the Mechanicus Research party have been killed down to the last man. The research is a bust. To make matters worse the Necron Tomb has fully awakened- countless numbers of the souless machines are now pouring out of the tomb. The Adeptus Mechanicus are furious with your chapter.", "necron_army", ""); - scr_alert("", "inqi", "The Inquisition is displeased with your Chapter for tampering with and awakening a Necron Tomb", 0, 0); - scr_event_log("", "The Inquisition is displeased with your Chapter for tampering with and awakening a Necron Tomb"); - } - - scr_event_log("", "Mechanicus Mission Failed: Necron Tomb Research Party and present astartes have been killed."); - } - } - } - if ((enemy == eFACTION.ECCLESIARCHY) && (obj_controller.faction_status[eFACTION.ECCLESIARCHY] != "War")) { obj_controller.loyalty -= 50; obj_controller.loyalty_hidden -= 50; @@ -222,7 +200,7 @@ try { scr_destroy_planet(1); } - if ((string_count("mech", battle_special) > 0) && (defeat == 0)) { + if ((string_count("mech", battle_special) > 0) && (!defeat)) { with (obj_ground_mission) { scr_return_ship(obj_ground_mission.loc, obj_ground_mission, obj_ground_mission.num); with (obj_ground_mission) { @@ -247,11 +225,11 @@ try { instance_activate_all(); if (turn_count < 20) { - if ((defeat == 0) && (threat >= 4)) { + if ((!defeat) && (threat >= 4)) { scr_recent("battle_victory", $"{battle_loc} {scr_roman(battle_id)}", enemy); } - if ((defeat == 1) && (final_marine_deaths + final_command_deaths >= 10)) { + if ((defeat) && (final_marine_deaths + final_command_deaths >= 10)) { scr_recent("battle_defeat", $"{enemy}, {final_marine_deaths + final_command_deaths}"); } } else { @@ -292,52 +270,10 @@ try { } } - if (battle_mission == "necron_tomb_excursion") { - necron_tomb_raid_post_battle_sequence(); + if (is_struct(special_feature) && is_instanceof(special_feature, PlanetProblem)){ + special_feature.after_battle_effects(); } - - if ((string_count("spyrer", battle_special) > 0) && (defeat == 0)) { - instance_activate_object(obj_star); - // title / text / image / speshul - var cur_star = obj_turn_end.battle_object[obj_turn_end.current_battle]; - var planet = obj_turn_end.battle_world[obj_turn_end.current_battle]; - var _planet_string = scr_roman_numerals()[planet - 1]; - - remove_planet_problem(planet, "spyrer", cur_star); - - var tixt = $"The Spyrer on {cur_star.name} {_planet_string} has been removed. The citizens and craftsman may sleep more soundly, the Inquisition likely pleased."; - - scr_popup("Inquisition Mission Completed", tixt, "spyrer", ""); - - if (obj_controller.demanding == 0) { - obj_controller.disposition[4] += 2; - } - if (obj_controller.demanding == 1) { - obj_controller.disposition[4] += choose(0, 0, 1); - } - - scr_event_log("", $"Inquisition Mission Completed: The Spyrer on {cur_star.name} {planet} has been removed.", cur_star.name); - scr_gov_disp(cur_star.name, planet, choose(1, 2, 3, 4)); - - instance_deactivate_object(obj_star); - } else if (battle_special == "protect_raiders") { - protect_raiders_battle_aftermath(); - } else if (string_count("fallen", battle_special) > 0) { - hunt_fallen_battle_aftermath(); - } else if ((defeat == 0) && (enemy == eFACTION.TYRANIDS) && (battle_special == "tyranid_org")) { - if (captured_gaunt > 1) { - var _pop = instance_create(0, 0, obj_popup); - _pop.image = "inquisition"; - _pop.title = "Inquisition Mission Completed"; - _pop.text = "You have captured several Gaunt organisms. The Inquisitor is pleased with your work, though she notes that only one is needed- the rest are to be purged. It will be stored until it may be retrieved. The mission is a success."; - } - if (captured_gaunt == 1) { - var _pop = instance_create(0, 0, obj_popup); - _pop.image = "inquisition"; - _pop.title = "Inquisition Mission Completed"; - _pop.text = "You have captured a Gaunt organism- the Inquisitor is pleased with your work. The Tyranid will be stored until it may be retrieved. The mission is a success."; - } - } else if ((enemy == eFACTION.PLAYER) && (on_ship == true) && (defeat == 0)) { + if ((enemy == eFACTION.PLAYER && on_ship == true) && (!defeat)) { var diceh = roll_dice_chapter(1, 100, "high"); if (diceh <= 15) { diff --git a/objects/obj_ncombat/Create_0.gml b/objects/obj_ncombat/Create_0.gml index 41a2026375..a7d2820f60 100644 --- a/objects/obj_ncombat/Create_0.gml +++ b/objects/obj_ncombat/Create_0.gml @@ -29,6 +29,9 @@ vehicles_to_recover = 0; end_alive_units = []; average_battle_exp_gain = 0; upgraded_librarians = []; +special_feature = undefined; +reduce_fortification = true; +reduce_power = true; view_x = obj_controller.x; view_y = obj_controller.y; @@ -63,9 +66,7 @@ if (instance_exists(obj_star)) { LOGGER.error("No obj_star instance found for combat; battle_object defaulted to noone"); } battle_id = 0; -battle_mission = ""; battle_special = ""; -battle_data = {}; defeat = 0; defeat_message = 0; fugg = 0; @@ -77,7 +78,6 @@ stage_elapsed2 = 0; battle_over = 0; done = 0; -captured_gaunt = 0; ethereal = 0; hulk_treasure = 0; four_show = 0; @@ -118,6 +118,7 @@ charged = 0; fadein = 40; enemy = undefined; +battle_enemy_data = undefined; enem = "Orks"; enem_sing = "Ork"; threat = 0; @@ -271,3 +272,18 @@ betchers = obj_ini.betchers; // slight melee penalty catalepsean = obj_ini.catalepsean; // minor global attack decrease occulobe = obj_ini.occulobe; // penalty if morning and susceptible to flash grenades mucranoid = obj_ini.mucranoid; // chance to short-circuit + + +register_kills_to_missions = function(casulties){ + if (obj_ncombat.battle_special != ""){ + if (is_struct(obj_ncombat.special_feature) && is_instanceof(obj_ncombat.special_feature, PlanetProblem)){ + var _feat = obj_ncombat.special_feature; + _feat.casualty_packet = casulties; + _feat.battle_on_enemy_casulties(); + } + } +} + + + + diff --git a/objects/obj_p_fleet/Alarm_1.gml b/objects/obj_p_fleet/Alarm_1.gml index b0656e3c18..e69de29bb2 100644 --- a/objects/obj_p_fleet/Alarm_1.gml +++ b/objects/obj_p_fleet/Alarm_1.gml @@ -1,161 +0,0 @@ -try { - acted = 0; - - if (action == "Lost") { - set_fleet_location("Lost"); - exit; - } else if (action == "") { - var spid = instance_nearest(x, y, obj_star); - fleet_register_at_star(self, spid); - - if (instance_exists(orbiting)) { - if (orbiting.visited == 0) { - 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); - } - } - } - orbiting.visited = 1; - } - - meet_system_governors(orbiting); - } - } else if (array_contains(global.fleet_move_options, action)) { - set_fleet_location("Warp"); - - if (instance_nearest(action_x, action_y, obj_star).storm > 0) { - exit; - } - - var spid = point_distance(x, y, action_x, action_y); - spid = spid / action_eta; - var dir = point_direction(x, y, action_x, action_y); - - x = x + lengthdir_x(spid, dir); - y = y + lengthdir_y(spid, dir); - - action_eta -= 1; - just_left = false; - - if ((action_eta == 0) && (action == "crusade1")) { - var dr = point_direction(room_width / 2, room_height / 2, x, y); - action_x = x + lengthdir_x(600, dr); - action_y = y + lengthdir_y(600, dr); - action = "crusade2"; - set_fleet_movement(false, "crusade2"); - } - if ((action_eta == 0) && (action == "crusade2")) { - with (obj_star) { - if (owner > 5) { - instance_deactivate_object(id); - } - var enemies = false; - for (var i = 6; i < 13; i++) { - if (scr_orbiting_fleet(i) != noone) { - enemies = true; - break; - } - } - if (enemies) { - instance_deactivate_object(id); - } - } - var ret = instance_nearest(x, y, obj_star); - action_x = ret.x; - action_y = ret.y; - action = "crusade3"; - set_fleet_movement(false, "crusade3"); - instance_activate_object(obj_star); - } - if ((action_eta == 0) && (action == "crusade3")) { - // Popup here - scr_crusade(); - action = ""; - } - - if ((action_eta == 0) && (action != "crusade1") && (action != "crusade2")) { - // Check to see if there are already player ships in the spot where this object will move to - // If yes, combine the two of them - - var steh = instance_nearest(action_x, action_y, obj_star); - if (steh.vision == 0) { - steh.vision = 1; - } - fleet_register_at_star(id, steh); - - meet_system_governors(steh); - - if ((steh.p_owner[1] == eFACTION.ECCLESIARCHY) || (steh.p_owner[2] == eFACTION.ECCLESIARCHY) || (steh.p_owner[3] == eFACTION.ECCLESIARCHY) || (steh.p_owner[4] == eFACTION.ECCLESIARCHY)) { - if ((obj_controller.faction_defeated[5] == 0) && (obj_controller.known[eFACTION.ECCLESIARCHY] == 0)) { - obj_controller.known[eFACTION.ECCLESIARCHY] = 1; - } - } - if ((steh.owner == eFACTION.ELDAR) && (obj_controller.faction_defeated[6] == 0) && (obj_controller.known[eFACTION.ELDAR] == 0)) { - obj_controller.known[eFACTION.ELDAR] = 1; - } - if ((steh.owner == eFACTION.TAU) && (obj_controller.faction_defeated[8] == 0) && (obj_controller.known[eFACTION.TAU] == 0)) { - obj_controller.known[eFACTION.TAU] = 1; - } - - action = ""; - x = action_x; - y = action_y; - action_x = 0; - action_y = 0; - - var i; - set_fleet_location(steh.name); - if (steh.visited == 0) { - 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); - } - } - } - steh.visited = 1; - } - if (array_length(complex_route) > 0) { - set_new_player_fleet_course(complex_route); - } - } - } - - if ((action == "") && (obj_controller.known[eFACTION.ELDAR] == 0)) { - instance_activate_object(obj_star); // Kind of half-ass band-aiding that bug, might need to remove this later; this might cause problems later - - with (obj_star) { - if (p_type[1] != "Craftworld") { - instance_deactivate_object(id); - } - } - - var steh = instance_nearest(x, y, obj_star); - if (instance_exists(steh) && (steh != 0)) { - if (steh.p_type[1] == "Craftworld") { - var dist, rando; - dist = 999; - rando = floor(random(100)) + 1; - dist = point_distance(x, y, steh.old_x, steh.old_y); - - if ((rando >= 95) && (dist <= 300)) { - obj_controller.known[eFACTION.ELDAR] = 1; - scr_alert("green", "elfs", "Eldar Craftworld discovered.", steh.old_x, steh.old_y); - with (obj_en_fleet) { - if (owner == eFACTION.ELDAR) { - image_alpha = 1; - } - } - } - // Quene eldar introduction - // if (rando>=95) and (dist<=300) then show_message("MON'KEIGH"); - } - } - - instance_activate_object(obj_star); - } -} catch (_exception) { - ERROR_HANDLER.handle_exception(_exception); -} diff --git a/objects/obj_p_fleet/Alarm_7.gml b/objects/obj_p_fleet/Alarm_7.gml index 7c35df479b..51ad0d35c9 100644 --- a/objects/obj_p_fleet/Alarm_7.gml +++ b/objects/obj_p_fleet/Alarm_7.gml @@ -6,7 +6,7 @@ if (capital_number == 0) { var c = 0; var good = 0; var capital_id; -var capital_list = fleet_full_ship_array(,, true, true); +var capital_list = full_ship_array(false, true, true); for (var i = 0; i < array_length(capital_list); i++) { // Find the healthiest capital ship capital_id = capital_list[i]; @@ -20,7 +20,7 @@ for (var i = 0; i < array_length(capital_list); i++) { } if (good > 0) { - var ships_list = fleet_full_ship_array(, true); + var ships_list = full_ship_array(, true); var _art_keys = struct_get_names(obj_ini.artifact_map); for (var _i = 0; _i < array_length(_art_keys); _i++) { var arti = obj_ini.artifact_map[$ _art_keys[_i]]; diff --git a/objects/obj_p_fleet/Create_0.gml b/objects/obj_p_fleet/Create_0.gml index b966ba1002..50cfc7a67b 100644 --- a/objects/obj_p_fleet/Create_0.gml +++ b/objects/obj_p_fleet/Create_0.gml @@ -37,6 +37,7 @@ escort_health = 100; complex_route = []; just_left = false; +beyond_engagement = false; action = ""; action_x = 0; @@ -48,6 +49,122 @@ acted = 0; hurssy = 0; hurssy_time = 0; /// Called from save function to take all object variables and convert them to a json savable format and return it + +problems = []; +/// @param {string} _name +/// @param {Real} _timer +/// @param {struct} _data +/// @returns {Struct.FleetProblem} +add_problem = function(_name, _timer, _data = {}){ + var _problem = new FleetProblem(_name, _timer, _data, self); + if (_problem.delete_mission){ + return undefined; + } + array_push(problems, _problem); + return _problem; +} + +problems_to_mission_log = function(){ + var _temp_log = [] + for (var i = 0; i < array_length(problems); i++) { + var _mission_data = problems[i].mission_log_entry(); + array_push(_temp_log, _mission_data); + } + + return _temp_log; +} + + +arrived_at_star = function(){ + set_fleet_location(orbiting.name); + if (orbiting.visited == 0) { + for (var plan_num = 1; plan_num <= orbiting.planets; plan_num++) { + if (array_length(orbiting.p_feature[plan_num]) != 0) { + with (orbiting) { + scr_planetary_feature(plan_num); + } + } + } + orbiting.visited = 1; + } + if (orbiting.vision == 0) { + orbiting.vision = 1; + } + meet_system_governors(orbiting); + + if (array_contains(orbiting.p_owner, eFACTION.ECCLESIARCHY)) { + if ((obj_controller.faction_defeated[5] == 0) && (obj_controller.known[eFACTION.ECCLESIARCHY] == 0)) { + obj_controller.known[eFACTION.ECCLESIARCHY] = 1; + } + } + if ((orbiting.owner == eFACTION.ELDAR) && (obj_controller.faction_defeated[eFACTION.ELDAR] == 0) && (obj_controller.known[eFACTION.ELDAR] == 0)) { + obj_controller.known[eFACTION.ELDAR] = 1; + } + if ((orbiting.owner == eFACTION.TAU) && (obj_controller.faction_defeated[eFACTION.TAU] == 0) && (obj_controller.known[eFACTION.TAU] == 0)) { + obj_controller.known[eFACTION.TAU] = 1; + } + + + if (steh.p_type[1] == "Craftworld") { + rando = roll_dice_chapter(1, 100, "high"); + + if ((rando >= 95)) { + obj_controller.known[eFACTION.ELDAR] = 1; + scr_alert("green", "elfs", "Eldar Craftworld discovered.", steh.old_x, steh.old_y); + with (obj_en_fleet) { + if (owner == eFACTION.ELDAR) { + image_alpha = 1; + } + } + } + // Quene eldar introduction + // if (rando>=95) and (dist<=300) then show_message("MON'KEIGH"); + } + + instance_activate_object(obj_star); +} + +arrive_at_waypoint = function(){ + for (var i = 0; i < array_length(problems); i++){ + problems[i].on_waypoint_arrival(); + } + set_new_player_fleet_course(complex_route); +} + +full_ship_array = function(exclude_capitals = false, exclude_frigates = false, exclude_escorts = false) { + var all_ships = []; + var _ship_count = array_length(obj_ini.ship); + + if (!exclude_capitals) { + for (var i = 0; i < array_length(capital_num); i++) { + if (capital_num[i] < _ship_count) { + array_push(all_ships, capital_num[i]); + } + } + } + if (!exclude_frigates) { + for (var i = 0; i < array_length(frigate_num); i++) { + if (frigate_num[i] < _ship_count) { + array_push(all_ships, frigate_num[i]); + } + } + } + if (!exclude_escorts) { + for (var i = 0; i < array_length(escort_num); i++) { + if (escort_num[i] < _ship_count) { + array_push(all_ships, escort_num[i]); + } + } + } + + return all_ships; +} + +calculate_eta = function(target_x, target_y,from_star = true, to_star = true){ + calculate_fleet_eta(x, y, target_x, target_y, fleet_speed, from_star , to_star , warp_able); +} + +move = method(self, set_fleet_movement); serialize = function() { var object_fleet = self; @@ -62,15 +179,21 @@ serialize = function() { "serialize", "deserialize", "orbiting", + "problems", ]; copy_serializable_fields(object_fleet, save_data, excluded_from_save); + save_data.problems = []; + for (var i = 0; i < array_length(problems); i++) { + array_push(save_data.problems, problems[i].save()); + } + return save_data; }; deserialize = function(save_data) { - var exclusions = ["orbiting"]; // skip automatic setting of certain vars, handle explicitly later + var exclusions = ["orbiting", "problems"]; // skip automatic setting of certain vars, handle explicitly later // Automatic var setting var all_names = struct_get_names(save_data); @@ -88,7 +211,21 @@ deserialize = function(save_data) { } } - set_player_fleet_image(); -}; + // Problems, old saves won't have this key + problems = []; + if (struct_exists(save_data, "problems")) { + for (var i = 0; i < array_length(save_data.problems); i++) { + try { + // empty p_id stops __init from running, load() then restores the real p_id and timer + var _problem = new FleetProblem("", 0, {}, self); + _problem.load(save_data.problems[i]); + _problem.fleet = self; + array_push(problems, _problem); + } catch (e) { + LOGGER.exception("Fleet problem deserialization failed", e); + } + } + } -#endregion + set_player_fleet_image(); +}; \ No newline at end of file diff --git a/objects/obj_popup/Step_0.gml b/objects/obj_popup/Step_0.gml index 92c1c7a9cb..7d701548ee 100644 --- a/objects/obj_popup/Step_0.gml +++ b/objects/obj_popup/Step_0.gml @@ -208,76 +208,32 @@ try { } if ((press == 0) && array_length(options) || ((demand == 1) && (mission != "") && (string_count("Inquisition", title) > 0)) || ((demand == 1) && (title == "Inquisition Recon"))) { - if (title == "Inquisition Recon") { - obj_controller.temp[200] = string(loc); - var mission_star = find_star_by_name(obj_controller.temp[200]); - if (add_new_problem(planet, "recon", estimate, mission_star)) { - title = "Inquisition Mission Demand"; - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to land Astartes on {mission_star.name} {scr_roman(planet)} to investigate the planet within {estimate} months."; - with (mission_star) { - new_star_event_marker("green"); - } - scr_event_log("", $"Inquisition Mission Accepted: The Inquisition wish for Astartes to land on and investigate {mission_star.name} {scr_roman(planet)} within {estimate} months.", mission_star.name); - } - } if ((mission != "") && (title == "Inquisition Mission")) { obj_controller.temp[200] = string(loc); var onceh = 0; - var mission_star = find_star_by_name(obj_controller.temp[200]); + var _mission_star = find_star_by_name(obj_controller.temp[200]); var mission_is_go = false; - if (mission_star != noone && planet > 0) { + if (_mission_star != noone && planet > 0) { var _estimate = estimate; var _planet = planet; var _mission = mission; - with (mission_star) { - if (add_new_problem(_planet, _mission, _estimate)) { - new_star_event_marker("green"); - mission_is_go = true; - } + var _p_data = _mission_star.get_planet_data(_planet); + with (_mission_star) { + _p_data.new_problem(_mission, _estimate) + new_star_event_marker("green"); + mission_is_go = true; } if (mission_is_go) { if (demand) { title = "Inquisition Mission Demand"; } - - if (mission == "purge") { - scr_event_log("", $"Inquisition Mission Accepted: The nobles of {mission_star.name} {scr_roman(planet)} must be selectively purged within {estimate} months.", mission_star.name); - if (demand) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to selectively purge the Nobles on {mission_star.name} {scr_roman(onceh)} within {estimate} months."; - } - } else if (mission == "cleanse") { - scr_event_log("", $"Inquisition Mission Accepted: The mutants beneath {planet_numeral_name(planet, mission_star)} must be cleansed by fire within {estimate} months.", mission_star.name); - if (demand) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to cleanse by fire the mutants in Hive {planet_numeral_name(planet, mission_star)} within {estimate} months."; - } - } - if (mission == "spyrer") { - scr_event_log("", $"Inquisition Mission Accepted: The Spyrer on {mission_star.name} {scr_roman(planet)} must be killed within {estimate} months.", mission_star.name); - if (demand) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. An out of control Spyrer on Hive {mission_star.name} {scr_roman(onceh)} must be removed within {estimate} months."; - } - } else if (mission == "tyranid_org") { - image = "webber"; - title = "New Equipment"; - fancy_title = 0; - text_center = 0; - text = $"{global.chapter_name} have been provided with 4x Astartes Webbers in order to complete the mission."; - + if (mission == "inquisition_spyrer") { + scr_event_log("", $"Inquisition Mission Accepted: The Spyrer on {_mission_star.name} {scr_roman(planet)} must be killed within {estimate} months.", _mission_star.name); if (demand) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to capture a Gaunt organism and return it, unharmed- 4x Webbers have been provided for this purpose."; + text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. An out of control Spyrer on Hive {_mission_star.name} {scr_roman(onceh)} must be removed within {estimate} months."; } - - reset_popup_options(); - scr_add_item("Webber", 4); - obj_controller.cooldown = 10; - scr_event_log("", $"Inquisition Mission Accepted: The Inquisition wishes for the capture of a particular strain Gaunt noticed on {mission_star.name} {scr_roman(planet)} is advisable.", mission_star.name); - obj_controller.useful_info += "Tyr|"; - if (demand) { - demand = 0; - } - exit; } else if (mission == "ethereal") { with (obj_star) { if ((p_tau[1] >= 4) || (p_tau[2] >= 4) || (p_tau[3] >= 4) || (p_tau[4] >= 4)) { @@ -289,15 +245,7 @@ try { if (demand) { title = "Inquisition Mission Demand"; - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to capture the Tau Ethereal somewhere within the {mission_star.name} system."; - } - if (has_problem_star("recon", mission_star)) { - scr_event_log("", $"Inquisition Mission Accepted: The Inquisition wish for {global.chapter_name} to capture the Tau Ethereal somewhere within {mission_star.name}.", mission_star.name); - } - } else if (mission == "demon_world") { - scr_event_log("", $"Inquisition Mission Accepted: The demon world of {mission_star.name} {scr_roman(planet)} will be purged by your hand.", mission_star.name); - if (demand) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. An out of control Demon World {mission_star.name} {scr_roman(onceh)} must be cleansed within {estimate} months."; + text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to capture the Tau Ethereal somewhere within the {_mission_star.name} system."; } } } @@ -352,11 +300,6 @@ try { } // Remove multi-choices } - if ((image == "inquisition") && (title == "Investigation Completed")) { - obj_temp7.alarm[1] = 1; - instance_destroy(); - } - if (image == "artifact2") { ground_forces_collect_artifact(); obj_controller.cooldown = 10; @@ -373,19 +316,6 @@ try { } if ((press == 1) && (option2 != "")) { - if (mission == "spyrer") { - obj_controller.disposition[4] -= 2; - } - if (title == "Inquisition Recon") { - obj_controller.disposition[4] -= 2; - } - if ((image == "inquisition") && (title == "Investigation Completed")) { - with (obj_temp7) { - instance_destroy(); - } - instance_destroy(); - } - if (title == "Mercy Plea") { // If have any marines within the fleet on the ships diff --git a/objects/obj_star/Create_0.gml b/objects/obj_star/Create_0.gml index ba816ea713..908d44f27f 100644 --- a/objects/obj_star/Create_0.gml +++ b/objects/obj_star/Create_0.gml @@ -28,55 +28,54 @@ storm_image = 0; trader = 0; visited = 0; stored_owner = -1; +navy_enemy_fleet_enroute = false; in_view = true; garrisoned = false; // sets up default planet variables -var _planet_array_size = 9; -planet = array_create(_planet_array_size, 0); -dispo = array_create(_planet_array_size, -50); -p_type = array_create(_planet_array_size, ""); -p_owner = array_create(_planet_array_size, 0); -p_first = array_create(_planet_array_size, 0); -p_population = array_create(_planet_array_size, 0); -p_max_population = array_create(_planet_array_size, 0); -p_large = array_create(_planet_array_size, 0); -p_pop = array_create(_planet_array_size, ""); -p_guardsmen = array_create(_planet_array_size, 0); -p_pdf = array_create(_planet_array_size, 0); -p_fortified = array_create(_planet_array_size, 0); -p_station = array_create(_planet_array_size, 0); -p_player = array_create(_planet_array_size, 0); -p_lasers = array_create(_planet_array_size, 0); -p_silo = array_create(_planet_array_size, 0); -p_defenses = array_create(_planet_array_size, 0); -p_orks = array_create(_planet_array_size, 0); -p_tau = array_create(_planet_array_size, 0); -p_eldar = array_create(_planet_array_size, 0); -p_tyranids = array_create(_planet_array_size, 0); -p_traitors = array_create(_planet_array_size, 0); -p_chaos = array_create(_planet_array_size, 0); -p_demons = array_create(_planet_array_size, 0); -p_sisters = array_create(_planet_array_size, 0); -p_necrons = array_create(_planet_array_size, 0); -p_halp = array_create(_planet_array_size, 0); -p_heresy = array_create(_planet_array_size, 0); -p_hurssy = array_create(_planet_array_size, 0); -p_hurssy_time = array_create(_planet_array_size, 0); -p_heresy_secret = array_create(_planet_array_size, 0); -p_raided = array_create(_planet_array_size, false); -p_governor = array_create(_planet_array_size, false); -p_operatives = array_create_advanced(_planet_array_size, []); -p_feature = array_create_advanced(_planet_array_size, []); -p_upgrades = array_create_advanced(_planet_array_size, []); -p_influence = array_create_advanced(_planet_array_size, array_create(15, 0)); -p_problem = array_create_advanced(_planet_array_size, array_create(8, "")); -p_problem_other_data = array_create_advanced(_planet_array_size, array_create_advanced(8, {})); -p_timer = array_create_advanced(_planet_array_size, array_create(8, -1)); +planet = array_create(PLANET_ARRAY_SIZE, 0); +dispo = array_create(PLANET_ARRAY_SIZE, -50); +p_type = array_create(PLANET_ARRAY_SIZE, ""); +p_owner = array_create(PLANET_ARRAY_SIZE, 0); +p_first = array_create(PLANET_ARRAY_SIZE, 0); +p_population = array_create(PLANET_ARRAY_SIZE, 0); +p_max_population = array_create(PLANET_ARRAY_SIZE, 0); +p_large = array_create(PLANET_ARRAY_SIZE, 0); +p_pop = array_create(PLANET_ARRAY_SIZE, ""); +p_guardsmen = array_create(PLANET_ARRAY_SIZE, 0); +p_pdf = array_create(PLANET_ARRAY_SIZE, 0); +p_fortified = array_create(PLANET_ARRAY_SIZE, 0); +p_station = array_create(PLANET_ARRAY_SIZE, 0); +p_player = array_create(PLANET_ARRAY_SIZE, 0); +p_lasers = array_create(PLANET_ARRAY_SIZE, 0); +p_silo = array_create(PLANET_ARRAY_SIZE, 0); +p_defenses = array_create(PLANET_ARRAY_SIZE, 0); +p_orks = array_create(PLANET_ARRAY_SIZE, 0); +p_tau = array_create(PLANET_ARRAY_SIZE, 0); +p_eldar = array_create(PLANET_ARRAY_SIZE, 0); +p_tyranids = array_create(PLANET_ARRAY_SIZE, 0); +p_traitors = array_create(PLANET_ARRAY_SIZE, 0); +p_chaos = array_create(PLANET_ARRAY_SIZE, 0); +p_demons = array_create(PLANET_ARRAY_SIZE, 0); +p_sisters = array_create(PLANET_ARRAY_SIZE, 0); +p_necrons = array_create(PLANET_ARRAY_SIZE, 0); +p_halp = array_create(PLANET_ARRAY_SIZE, 0); +p_heresy = array_create(PLANET_ARRAY_SIZE, 0); +p_hurssy = array_create(PLANET_ARRAY_SIZE, 0); +p_hurssy_time = array_create(PLANET_ARRAY_SIZE, 0); +p_heresy_secret = array_create(PLANET_ARRAY_SIZE, 0); +p_raided = array_create(PLANET_ARRAY_SIZE, false); +p_governor = array_create(PLANET_ARRAY_SIZE, false); +p_operatives = array_create_advanced(PLANET_ARRAY_SIZE, []); +p_feature = array_create_advanced(PLANET_ARRAY_SIZE, []); +p_upgrades = array_create_advanced(PLANET_ARRAY_SIZE, []); +p_influence = array_create_advanced(PLANET_ARRAY_SIZE, array_create(15, 0)); +p_problem = array_create_advanced(PLANET_ARRAY_SIZE, []); p_psionic = []; -for (var i = 0; i < _planet_array_size; i++) { +for (var i = 0; i < PLANET_ARRAY_SIZE; i++) { p_psionic[i] = irandom(5); } + system_datas = array_create(8, undefined); system_garrison = array_create(8, undefined); system_sabatours = array_create(8, undefined); @@ -123,6 +122,59 @@ add_feature = function(planet, feature) { array_push(p_feature[planet], feature); }; +problems = []; + +add_problem = function(p_id, data = {}){ + var _prob = new SystemProblem(p_id, self, data); + array_push(problems, _prob); + return _prob; +} + +problems_to_mission_log = function(){ + var _temp_log = []; + for (var i = 1; i <= planets; i++) { + var _p_data = get_planet_data(i); + _temp_log = array_concat(_temp_log, _p_data.problems_to_mission_log()); + } + _temp_log = array_concat(_temp_log, generic_problems_to_mission_log()); + return _temp_log; +} + +/// @self Asset.GMObject.obj_star +has_orbiting_player_fleet = function () { + if (instance_exists(obj_p_fleet)) { + var _nearest = instance_nearest(x, y, obj_p_fleet); + if (_nearest.action != "move" && point_distance(_nearest.x, _nearest.y, x, y) == 0) { + return true; + } + } + return false; +} + +/// @function get_orbiting_player_fleet() +/// @description Returns the ID of the nearest player fleet orbiting the given system or star. +/// The system instance or identifier to check. If `noone`, the function checks the calling star instance. +/// @returns {Id.Instance.obj_p_fleet} The instance ID of the orbiting player fleet, or -1 if none is found. +/// +/// @example +/// ```gml +/// var fleet_id = get_orbiting_player_fleet(); +/// if (fleet_id != noone) { +/// LOGGER.debug("Fleet orbiting star: " + string(fleet_id)); +/// } +/// ``` +get_orbiting_player_fleet = function() { + var _fleet = instance_nearest(x, y, obj_p_fleet); + if (!instance_exists(_fleet)){ + return noone; + } + if (object_distance(self, _fleet) > 0 || _fleet.action == "move") { + return noone; + } else { + return _fleet.id; + } +} + system_player_ground_forces = 0; /// @desc Reports whether any planet in this system holds a garrison squad that still has members. @@ -138,7 +190,7 @@ function has_garrison() { if (_operative.job != "garrison") { continue; } - if (array_length(fetch_squad(_operative.reference).members) > 0) { + if (array_length(fetch_squad(_operative.reference).get_members()) > 0) { return true; } } @@ -166,18 +218,7 @@ serialize = function() { var planet_data = []; for (var p = 1; p <= object_star.planets; p++) { - planet_data[p] = { - dispo: object_star.dispo[p], - planet: object_star.planet[p], - }; - var var_names = variable_instance_get_names(object_star); - for (var n = 0; n < array_length(var_names); n++) { - var var_name = var_names[n]; - if (string_starts_with(var_name, "p_")) { - var val = object_star[$ var_name][p]; - variable_struct_set(planet_data[p], var_name, val); - } - } + planet_data[p] = get_planet_data(p).save(); } var save_data = { @@ -219,26 +260,26 @@ function deserialize(save_data) { ]; // skip automatic setting of certain vars, handle explicitly later // Automatic var setting - var all_names = struct_get_names(save_data); - for (var i = 0; i < array_length(all_names); i++) { - var var_name = all_names[i]; - if (array_contains(exclusions, var_name)) { + var _all_names = struct_get_names(save_data); + for (var i = 0; i < array_length(_all_names); i++) { + var _var_name = _all_names[i]; + if (array_contains(exclusions, _var_name)) { continue; } - var loaded_value = struct_get(save_data, var_name); - variable_instance_set(id, var_name, loaded_value); + var _loaded_value = struct_get(save_data, _var_name); + variable_instance_set(id, _var_name, _loaded_value); } if (struct_exists(save_data, "planet_data")) { var planet_arr = save_data.planet_data; for (var p = 1; p < array_length(planet_arr); p++) { - var planet = planet_arr[p]; - var var_names = struct_get_names(planet); - for (var v = 0; v < array_length(var_names); v++) { - var var_name = var_names[v]; + var _planet = planet_arr[p]; + var _var_names = struct_get_names(_planet); + for (var v = 0; v < array_length(_var_names); v++) { + var _var_name = _var_names[v]; - if (var_name == "p_feature") { - var _planet_features = planet[$ var_name]; + if (_var_name == "p_feature") { + var _planet_features = _planet[$ _var_name]; for (var f = 0; f < array_length(_planet_features); f++) { var _feat = _planet_features[f]; if (!is_struct(_feat) || !struct_exists(_feat, "f_type")) { @@ -253,8 +294,23 @@ function deserialize(save_data) { } continue; } - var val = planet[$ var_name]; - self[$ var_name][p] = val; + if (_var_name == "p_problem") { + var _planet_problems = _planet[$ _var_name]; + for (var f = 0; f < array_length(_planet_problems); f++) { + if (!is_struct(_planet_problems[f])){ + continue; + } + var _new_prob = new PlanetProblem("", 0, {}, {planet:p,system:id}); + _new_prob.load(_planet_problems[f]); + array_push(p_problem[p], _new_prob); + } + continue; + } + var _val = _planet[$ _var_name]; + if (!is_array(self[$ _var_name])) { + self[$ _var_name] = array_create(PLANET_ARRAY_SIZE, 0); + } + self[$ _var_name][p] = _val; } } } diff --git a/objects/obj_star/Draw_0.gml b/objects/obj_star/Draw_0.gml index 70cd413c79..bcc7c35316 100644 --- a/objects/obj_star/Draw_0.gml +++ b/objects/obj_star/Draw_0.gml @@ -18,9 +18,6 @@ if ((p_type[1] == "Craftworld") && (obj_controller.known[eFACTION.ELDAR] == 0)) var show = name; -if (global.cheat_debug == true) { - show = string(name) + "#" + string(p_problem[1][1]) + ":" + string(p_timer[1][1]) + "#" + string(p_problem[1][2]) + ":" + string(p_timer[1][2]) + "#" + string(p_problem[1][3]) + ":" + string(p_timer[1][3]); -} var _scale = obj_controller.star_scale; draw_set_color(c_white); draw_set_alpha(0.25); diff --git a/objects/obj_star_select/Draw_64.gml b/objects/obj_star_select/Draw_64.gml index 26d6ffa84b..5edc9d254a 100644 --- a/objects/obj_star_select/Draw_64.gml +++ b/objects/obj_star_select/Draw_64.gml @@ -158,11 +158,9 @@ try { } if (torpedo > 0) { - var pfleet = instance_nearest(x, y, obj_p_fleet); - if (instance_exists(pfleet) && (point_distance(pfleet.x, pfleet.y, target.x, target.y) <= 40) && (pfleet.action == "")) { - if (pfleet.capital_number + pfleet.frigate_number > 0) { - array_push(buttons, "Cyclonic Torpedo"); - } + var _pfleet = target.get_orbiting_player_fleet(); + if (_pfleet != noone && calculate_fleet_bombard_score(_pfleet.full_ship_array()) > 0) { + array_push(buttons, "Cyclonic Torpedo"); } } } else if (p_data.player_forces > 0) { @@ -292,6 +290,7 @@ try { } } } + var _p_fleet = target.get_orbiting_player_fleet() if (current_button != "") { if (array_contains(["Build", "Base", "Arsenal", "Gene-Vault"], current_button)) { /// @type {Id.Instance.obj_temp_build} @@ -312,12 +311,12 @@ try { with (obj_star_select) { instance_destroy(); } - } else if (current_button == "Raid" && instance_nearest(x, y, obj_p_fleet).acted <= 1) { + } else if (current_button == "Raid" && _p_fleet.acted <= 1) { // feather ignore once GM2064 - instance_create_layer(x, y, layer_get_all()[0], obj_drop_select, {p_target: target, planet_number: obj_controller.selecting_planet, sh_target: instance_nearest(x, y, obj_p_fleet), purge: 0}); + instance_create_layer(x, y, layer_get_all()[0], obj_drop_select, {p_target: target, planet_number: obj_controller.selecting_planet, sh_target: _p_fleet, purge: 0}); } else if (current_button == "Attack") { var _allow_attack = true; - var _targ = !target.present_fleet[1] ? noone : instance_nearest(x, y, obj_p_fleet); + var _targ = !target.present_fleet[1] ? noone : _p_fleet; if (instance_exists(_targ)) { if (_targ.acted >= 2) { _allow_attack = false; @@ -329,7 +328,7 @@ try { } } else if (current_button == "Purge") { var _allow_attack = true; - var _targ = !target.present_fleet[1] ? noone : instance_nearest(x, y, obj_p_fleet); + var _targ = !target.present_fleet[1] ? noone : _p_fleet; if (instance_exists(_targ)) { if (_targ.acted >= 2) { _allow_attack = false; @@ -343,9 +342,9 @@ try { instance_create(x, y, obj_bomb_select); if (instance_exists(obj_bomb_select)) { obj_bomb_select.p_target = target; - obj_bomb_select.sh_target = instance_nearest(x, y, obj_p_fleet); + obj_bomb_select.sh_target = _p_fleet; obj_bomb_select.p_data = p_data; - if (instance_nearest(x, y, obj_p_fleet).acted > 0) { + if (_p_fleet.acted > 0) { with (obj_bomb_select) { instance_destroy(); } @@ -375,6 +374,8 @@ try { scr_destroy_planet(2); } } + } else if (global.cheat_debug ){ + draw_system_debug(); } if (target != 0) { diff --git a/objects/obj_temp7/Alarm_0.gml b/objects/obj_temp7/Alarm_0.gml deleted file mode 100644 index 3791505b73..0000000000 --- a/objects/obj_temp7/Alarm_0.gml +++ /dev/null @@ -1,21 +0,0 @@ -if (num > 0) { - // Hmmmmmmm - var stah; - stah = instance_nearest(x, y, obj_star); - obj_controller.menu = 0; - - if (has_problem_planet(num, "recon", stah)) { - var pop; - pop = instance_create(0, 0, obj_popup); - pop.image = "inquisition"; - pop.title = "Investigation Completed"; - pop.text = "Your marines have scouted out " + string(stah.name) + " " + string(scr_roman(num)) + " and satisfied the mission requirements."; - - pop.add_option("Reload Marines"); - pop.add_option("Do Nothing"); - - scr_event_log("", "Inquisition Mission Completed: Your Astartes have succesfully scouted " + string(stah.name) + " " + scr_roman(num) + "."); - - remove_planet_problem(num, "recon", stah); - } -} diff --git a/objects/obj_temp7/Alarm_1.gml b/objects/obj_temp7/Alarm_1.gml deleted file mode 100644 index 6e782b11ce..0000000000 --- a/objects/obj_temp7/Alarm_1.gml +++ /dev/null @@ -1,2 +0,0 @@ -scr_return_ship(loc, self, num); -instance_destroy(); diff --git a/objects/obj_temp7/Create_0.gml b/objects/obj_temp7/Create_0.gml deleted file mode 100644 index e8bfa9df6c..0000000000 --- a/objects/obj_temp7/Create_0.gml +++ /dev/null @@ -1,4 +0,0 @@ -num = 0; -loc = ""; -managing = 0; -type = ""; diff --git a/objects/obj_temp7/obj_temp7.yy b/objects/obj_temp7/obj_temp7.yy deleted file mode 100644 index b5cd83e011..0000000000 --- a/objects/obj_temp7/obj_temp7.yy +++ /dev/null @@ -1,37 +0,0 @@ -{ - "$GMObject":"", - "%Name":"obj_temp7", - "eventList":[ - {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":0,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":1,"eventType":2,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - {"$GMEvent":"v1","%Name":"","collisionObjectId":null,"eventNum":0,"eventType":2,"isDnD":false,"name":"","resourceType":"GMEvent","resourceVersion":"2.0",}, - ], - "managed":true, - "name":"obj_temp7", - "overriddenProperties":[], - "parent":{ - "name":"Temp", - "path":"folders/Objects/Temp.yy", - }, - "parentObjectId":null, - "persistent":false, - "physicsAngularDamping":0.1, - "physicsDensity":0.5, - "physicsFriction":0.2, - "physicsGroup":0, - "physicsKinematic":false, - "physicsLinearDamping":0.1, - "physicsObject":false, - "physicsRestitution":0.1, - "physicsSensor":false, - "physicsShape":0, - "physicsShapePoints":[], - "physicsStartAwake":true, - "properties":[], - "resourceType":"GMObject", - "resourceVersion":"2.0", - "solid":false, - "spriteId":null, - "spriteMaskId":null, - "visible":true, -} \ No newline at end of file diff --git a/objects/obj_turn_end/Mouse_56.gml b/objects/obj_turn_end/Mouse_56.gml index a67db2d289..b5fffeca97 100644 --- a/objects/obj_turn_end/Mouse_56.gml +++ b/objects/obj_turn_end/Mouse_56.gml @@ -149,7 +149,16 @@ if (!instance_exists(obj_saveload) && !instance_exists(obj_popup) && !instance_e obj_ncombat.fortified = 0; } - obj_ncombat.battle_special = battle_special[current_battle]; + if (is_struct(battle_special[current_battle])){ + var _spec_data = battle_special[current_battle]; + obj_ncombat.battle_special = _spec_data.special_id; + obj_ncombat.special_feature = _spec_data.special_feature; + if (struct_exists(_spec_data, "battle_enemy_data")){ + obj_ncombat.battle_enemy_data = _spec_data.battle_enemy_data; + } + } else { + obj_ncombat.battle_special = battle_special[current_battle]; + } obj_ncombat.battle_climate = _planet_data.planet_type; if (_enemy == eFACTION.IMPERIUM) { diff --git a/scripts/FleetProblem/FleetProblem.gml b/scripts/FleetProblem/FleetProblem.gml new file mode 100644 index 0000000000..f456531f8b --- /dev/null +++ b/scripts/FleetProblem/FleetProblem.gml @@ -0,0 +1,580 @@ +//All missions that run on a fleet need their own FleetProblem instance +//missions for the most part can only run from predefined points in the code +// to run from each of these points each mission must have a registered function these functions are then called implicitly +//each function follows the format `___` +/* the current entry points for the code are + "per_turn" - runs every end turn to check for certain conditions often contains reactions to actions player has done last turn + - runs via basic_turn_end + + "init" - runs immediately after problem is created often used to populate initial popup or stack popup for turn end + + "on_arrival" - runs when the fleet arrives at a star, fleet_event_data holds {star} + "on_load" - runs when units are loaded onto the fleet, fleet_event_data holds {units} + "on_unload" - runs when units are unloaded from the fleet, fleet_event_data holds {units} + "on_split" - runs on the original fleet when it splits, fleet_event_data holds {new_fleet} + "on_merge" - runs on the receiving fleet when another fleet merges into it, fleet_event_data holds {merged_fleet} + "on_destruction" - runs when the fleet is destroyed, the mission is deleted after this function has run + - must be triggered BEFORE the fleet instance is destroyed + + "mission_log_entry" - runs to provide a data row for the mission log + +- other than these entry points and any other later defined positions mission specific code should not run outside of the FleetProblem container + +- to set an entry point up simply register the function as a static e.g + if i create static __example_per_turn once an "example" problem is registered on a fleet the per turn check will run + no other code is required + +other info + - the owning fleet must have a `problems = []` array in its create event + - entry points that receive extra information read it from fleet_event_data, which only exists for the duration of the call + - set a mission for deletion by setting delete_mission = true; this will delete the mission after the current function + has finished executing + - functions prefixed with `__` are only accessible from within the FleetProblem's internal scope +*/ + +//ANYTIME an exception is caught on a entry point for a mission the mission is prematurely deleted this ensures the player is not unfairly penalised for errors + +/// @param {string} _name +/// @param {Real} _timer +/// @param {struct} _data +/// @param {Id.Instance.obj_p_fleet} _fleet +function FleetProblem(_name, _timer, _data, _fleet) : Problem(_name, _timer, _data) constructor{ +fleet = _fleet; + +static __refresh_data = function(){ + if (!instance_exists(fleet)){ + delete_mission = true; + } +} + +per_turn_checks = true; + +static save = function(){ + var _save_copy = variable_clone(self); + struct_remove(_save_copy, "fleet"); + return _save_copy; +} + +//the owning fleet must re-attach itself after loading (problem.fleet = self) +static load = function(data){ + move_data_to_current_scope(data); +} + +//requires the completion and required_months flag to be in the data struct +static __increment_mission_completion = function() { + if (!struct_exists(data, "completion")) { + data.completion = 0; + } + data.completion++; + if (!struct_exists(data, "required_months") || data.required_months <= 0) { + LOGGER.error("Invalid required_months in mission_data"); + return 0; + } + return (data.completion / data.required_months) * 100; +} + +static __check_delete = function(){ + if (timer == -1 || (delete_mission)){ + if (!instance_exists(fleet)){ + exit; + } + var _prob = -1; + for (var i = 0; i < array_length(fleet.problems); i++){ + if (fleet.problems[i] == self){ + _prob = i; + } + } + if (_prob > -1){ + array_delete(fleet.problems, _prob, 1); + } + } +} + +//runs the entry point with fleet_event_data available for the duration of the call +static __trigger_with_event = function(trigger_string, _event_data){ + var _func = find_func(trigger_string); + if (is_undefined(_func)){ + exit; + } + fleet_event_data = _event_data; + __handle_triggered_mission_func(_func); + struct_remove(self, "fleet_event_data"); +} + +static basic_turn_end = function(){ + timer--; + if ((timer > -1) && per_turn_checks) { + var _func = find_func("per_turn"); + __handle_triggered_mission_func(_func); + } + __check_delete(); +} + +/// @param {Id.Instance.obj_star} star +static on_arrival = function(star){ + __trigger_with_event("on_arrival", {star}); +} + +/// @param {array} units +static on_load = function(units){ + __trigger_with_event("on_load", {units}); +} + +/// @param {array} units +static on_unload = function(units){ + __trigger_with_event("on_unload", {units}); +} + +/// @param {Id.Instance.obj_p_fleet} new_fleet +static on_split = function(new_fleet){ + __trigger_with_event("on_split", {new_fleet}); +} + +/// @param {Id.Instance.obj_p_fleet} merged_fleet +static on_merge = function(merged_fleet){ + __trigger_with_event("on_merge", {merged_fleet}); +} + +//call this before the fleet instance is destroyed +static on_destruction = function(){ + __trigger_with_event("on_destruction", {}); + delete_mission = true; + __check_delete(); +} + +static mission_log_entry = function(){ + var _func = find_func("mission_log_entry"); + if (!is_undefined(_func)){ + try { + return _func(); + } catch (_exception) { + delete_mission = true; + ERROR_HANDLER.handle_exception(_exception); + __check_delete(); + return undefined; + } + } + return __default_mission_log_entry(); +} + +static __default_mission_log_entry = function(){ + if (!instance_exists(fleet)){ + return undefined; + } + var _data = { + system: is_callable(fleet.name) ? fleet.name() : object_get_name(fleet.object_index), + mission: description(), + time: timer, + problem: self, + }; + + _data.click_left = method(_data, function() { + set_map_pan_to_loc(problem.fleet); + }); + + return _data; +} + +static __init = function(){ + if (p_id == ""){ + exit; + } + var _func = find_func("init"); + if (!is_undefined(_func)){ + __handle_triggered_mission_func(_func); + } +} +__init(); + +//runs the entry point with fleet_event_data available for the duration of the call +static __trigger_with_event = function(trigger_string, _event_data = {}){ + var _func = find_func(trigger_string); + if (is_undefined(_func)){ + exit; + } + fleet_event_data = _event_data; + __handle_triggered_mission_func(_func); + struct_remove(self, "fleet_event_data"); +} + +static basic_turn_end = function(){ + timer--; + var _func = undefined; + if ((timer > -1) && per_turn_checks) { + var _func = find_func("per_turn"); + } + __handle_triggered_mission_func(_func); +} + +static on_waypoint_arrival = function(){ + __trigger_with_event("on_waypoint_arrival"); +} + +static on_final_arrival = function(){ + __trigger_with_event("on_final_arrival"); +} + +/// @param {array} units +static on_load = function(units){ + __trigger_with_event("on_load", {units}); +} + +/// @param {array} units +static on_unload = function(units){ + __trigger_with_event("on_unload", {units}); +} + +/// @param {Id.Instance.obj_p_fleet} new_fleet +static on_split = function(new_fleet){ + __trigger_with_event("on_split", {new_fleet}); +} + +/// @param {Id.Instance.obj_p_fleet} merged_fleet +static on_merge = function(merged_fleet){ + __trigger_with_event("on_merge", {merged_fleet}); +} + +//call this before the fleet instance is destroyed +static on_destruction = function(){ + __trigger_with_event("on_destruction", {}); + delete_mission = true; + __check_delete(); +} + +static mission_log_entry = function(){ + var _func = find_func("mission_log_entry"); + if (!is_undefined(_func)){ + try { + return _func(); + } catch (_exception) { + delete_mission = true; + ERROR_HANDLER.handle_exception(_exception); + __check_delete(); + return undefined; + } + } + return __default_mission_log_entry(); +} + +static __default_mission_log_entry = function(){ + if (!instance_exists(fleet)){ + return undefined; + } + var _near_star = instance_nearest(fleet.x, fleet.y ,obj_star); + var _data = { + system: _near_star, + mission: description(), + time: timer, + problem: self, + }; + + _data.click_left = method(_data, function() { + set_map_pan_to_loc(problem.fleet); + }); + + return _data; +} + +static __init = function(){ + if (p_id == ""){ + exit; + } + var _func = find_func("init"); + if (!is_undefined(_func)){ + __handle_triggered_mission_func(_func); + } +} +__init(); + +static __great_crusade_init = function(){ + var _crusade_direction = point_direction(room_width / 2, room_height / 2, fleet.x, fleet.y); + fleet.action_x = fleet.x + lengthdir_x(1200, _crusade_direction); + fleet.action_y = fleet.y + lengthdir_y(1200, _crusade_direction); + fleet.move(false, "move"); + stage_id = "travel_to_crusade"; + fleet.beyond_engagement = true; +} + +static __great_crusade_on_final_arrival = function(){ + if (stage_id == "travel_to_crusade"){ + var _direction = point_direction(room_width / 2, room_height / 2, fleet.x, fleet.y); + fleet.action_x = fleet.x + lengthdir_x(600, _direction); + fleet.action_y = fleet.y + lengthdir_y(600, _direction); + fleet.move(false, "move"); + stage_id = "crusading" + fleet.beyond_engagement = true; + } else if (stage_id == "crusading"){ + with (obj_star) { + if (owner > 5) { + instance_deactivate_object(id); + } + var enemies = false; + for (var i = 6; i < 13; i++) { + if (scr_orbiting_fleet(i) != noone) { + enemies = true; + break; + } + } + if (enemies) { + instance_deactivate_object(id); + } + } + var _return_star = instance_nearest(x, fleet.y, obj_star); + action_x = _return_star.x; + action_y = _return_star.y; + fleet.move(false, "move"); + instance_activate_object(obj_star); + fleet.beyond_engagement = true; + stage_id = "returning_home" + } else if (stage_id == "returning_home"){ + __great_crusade_results(); + fleet.beyond_engagement = false; + } +} + +static __great_crusade_status_description = function(){ + +} + +static __great_crusade_results = function(){ + var _apoth = 0, _death_determination = 0, _death_determination_2 = 0, _roll3 = 0, _type = "", _artifacts = 0; + var _seed = 0; + var _marines_lost = 0; + var _heroics_strings = []; + var _clean = []; + + //index 1: death_determine 1 //index 2: death_determine 2 /index 3: apoth_recovery + //index 3 exp_gains irandom + static + var death_sets = { + normal: [ + 80, + 90, + 40, + [ + 5, + 10, + ], + ], + hard: [ + 60, + 80, + 30, + [ + 20, + 20, + ], + ], + brutal: [ + 20, + 65, + 20, + [ + 40, + 20, + ], + ], + }; + + _death_determination = floor(random(100)) + 1; + _roll3 = irandom(99) + 1; + + if (_death_determination <= 50) { + _type = "normal"; + _artifacts = choose(0, 0, 0, 0, 0, 1); + } else if (_death_determination > 50 && _death_determination <= 80) { + _type = "hard"; + _artifacts = choose(0, 0, 1); + } else if (_death_determination > 80) { + _type = "brutal"; + _artifacts = choose(1, 2, 3); + } + + var death_data = death_sets[$ _type]; + + for (var co = 0; co <= obj_ini.companies; co++) { + _clean[co] = 0; + } + var total_ship_id = array_concat(fleet.capital_num, fleet.frigate_num, fleet.escort_num); + + var _units = collect_role_group("all", ["", 0 , total_ship_id],false, {}, true); + for (var i = 0; i < _units.number(); i++){ + var _unit = _units.units[i]; + + _death_determination = floor(random(100)) + 1; + //specialist trait greatly reduces death risk + //TODO figure out how to quantify and present these risks so the player knows to protect dudes with trait + if (_unit.has_trait("very_hard_to_kill")) { + _death_determination -= 20; + } + _death_determination_2 = _death_determination; + _death_determination -= _unit.experience / 2; + + //more generalised trait bonus mainly linked to chapter advantage of same name + if (_unit.has_trait("slow_and_purposeful")) { + _death_determination -= 10; + } + + var _dead = false; + if (_death_determination > death_data[0] || _death_determination_2 > death_data[1]) { + _dead = true; + if (_unit.has_role(eROLE.CAPTAIN)) { + if (irandom(20) < _unit.luck) { + _dead = false; + } else { + if (irandom(100) < _unit.weapon_skill) { + var _heroic_deed = choose("holding a breach in imperial defenses allowing allied forces to regroup,", "slaying the enemy leader in glorious combat, while victorious he ultimately succumbed to his wounds,", "leading an imortant boarding mission,"); + //TODO figure out a blance in reward for captains or high rnaking death on crusade + //adds dynamacism as itt creates reward for the potential loss of men and talent during crusades + //var consolations = ["ship", "req",""] + //var consolation_prize = irandom(2) + var heroic_death = $"{_unit.full_title()} died {_heroic_deed} {_unit.name()} dies a hero of the {global.chapter_name}"; + array_push(_heroics_strings, heroic_death); + } + } + } else if (_unit.has_role(eROLE.ANCIENT) || _unit.has_role(eROLE.CHAPTERMASTER)) { + _dead = false; + } + } + if (_dead) { + obj_ini.ship_carrying[_unit.ship_location] -= _unit.get_unit_size(); + if (_unit.IsSpecialist(SPECIALISTS_STANDARD, true)) { + obj_controller.command--; + } else { + obj_controller.marines--; + } + + _clean[co] = 1; + _marines_lost++; + _unit.kill(false, true); + } else { + if (_unit.IsSpecialist(SPECIALISTS_APOTHECARIES) && (_unit.gear() == "Narthecium")) { + _apoth++; + } + _unit.add_exp(irandom(death_data[3][0]) + death_data[3][1]); + + if (irandom(99) == 1 && irandom(20) < _unit.luck) { + var _heroic_deed = choose("still_standing", "lone_survivor", "beast_slayer"); + _unit.add_trait(_heroic_deed); + array_push(_heroics_strings, string(global.trait_list[$ _heroic_deed].flavour_text, _unit.full_title())); + } + } + } + + if (obj_ini.doomed == 0) { + if (_apoth > 0) { + _seed = min(_seed, _apoth * death_data[2]); + } + if (_apoth == 0) { + _seed = floor(_seed * 0.2); + } + obj_controller.gene_seed += _seed; + } + + with (obj_ini) { + for (var _c = 0; _c <= obj_ini.companies; _c++) { + scr_company_order(_c); + } + } + + if (_roll3 <= 10) { + _artifacts += 1; + } + if (_artifacts > 0) { + repeat (_artifacts) { + if (obj_ini.fleet_type == ePLAYER_BASE.HOME_WORLD) { + scr_add_artifact("random", "", 4, obj_ini.home_name, -1); + } + if (obj_ini.fleet_type != ePLAYER_BASE.HOME_WORLD) { + scr_add_artifact("random", "", 4, obj_ini.ship[0], 0); + } + } + } + + var tixt = "Your ships have returned from the Crusade. "; + if (_type == "normal") { + tixt += "The combat was as could be expected- "; + } + if (_type == "hard") { + tixt += "The combat was fairly grueling- "; + } + if (_type == "brutal") { + tixt += "The combat was absolutely brutal- fleet.your marines were the first into the fray, and as a result "; + } + + tixt += $"{_marines_lost} of fleet.your battle brothers fell in combat."; + + var _apoth_role = obj_ini.player_role_data[eROLE.APOTHECARY].role; + if (obj_ini.doomed == 0) { + if ((_apoth > 0) && (_seed > 0)) { + tixt += $" The {_apoth} surviving {_apoth_role} were able to recover {_seed} Gene-Seed."; + } + if ((_apoth == 0) && (_seed > 0)) { + tixt += $" fleet.You had no able-bodied {_apoth_role}, or all of them perished in the Crusade. Foreign Apothecaries were able to recover " + string(_seed) + " of fleet.your Gene-Seed."; + } + } + if (obj_ini.doomed == 1) { + tixt += " Due to fatal mutations in fleet.your marines none of the fallen Gene-Seed was recoverable."; + } + + if (_artifacts > 0) { + tixt += $" {_artifacts} Artifacts were granted to fleet.your Chapter or looted."; + } + if ((_roll3 <= 10) && (_artifacts > 1)) { + tixt += " One of them were given as a bonus for exceptional valor."; + } + + if (array_length(_heroics_strings) == 1) { + tixt += " A heroic deed was recorded"; + } else if (array_length(_heroics_strings) > 1) { + tixt += " Several deeds were recorded"; + } + // title / text / image / speshul + scr_popup("Crusade Results", tixt, "crusade", ""); + for (var i = 0; i < array_length(_heroics_strings); i++) { + scr_popup("Heroic Deed", _heroics_strings[i], "crusade", ""); + } + + delete_mission = true; + fleet.action = ""; +} + +static __deliver_hunt_trophy_mission_log_entry = function(){ + var _mission = localize("Deliver Trophy Guard"); + var _sys = fleets_next_location(); + var _mission_data = { + mission: self, + system: _sys.name, + system_id: _sys.id, + target: self, + important_person: _event.data.trophy_owner, + person_name: _event.data.delivering_marine, + planet: 0, + start_system: _event.data.system, + time: timer, + }; + + _mission_data.click_left = method(_mission_data, function() { + set_map_pan_to_loc(system_id); + }); + + _mission_data.hover = method(_mission_data, function() { + tooltip_draw(localize("You are to have {0} deliver trophy hunted on {1} to the {1} regiments\n\nLeft click to see target fleet intercept system right click to view the trophy bearing marine {0}", [person_name, start_system])); + }); + + _mission_data.click_right = method(_mission_data, function() { + var _unit = fetch_unit_uid(important_person); + if (is_struct(_unit)) { + var _unit_l = [_unit]; + group_selection(_unit_l); + } + }); + return _mission_data; +} +} + + + + + + + diff --git a/scripts/FleetProblem/FleetProblem.yy b/scripts/FleetProblem/FleetProblem.yy new file mode 100644 index 0000000000..d8ada024c5 --- /dev/null +++ b/scripts/FleetProblem/FleetProblem.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"v1", + "%Name":"FleetProblem", + "isCompatibility":false, + "isDnD":false, + "name":"FleetProblem", + "parent":{ + "name":"Constructors", + "path":"folders/Scripts/Constructors.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/PlanetProblem/PlanetProblem.gml b/scripts/PlanetProblem/PlanetProblem.gml new file mode 100644 index 0000000000..c2945cd67b --- /dev/null +++ b/scripts/PlanetProblem/PlanetProblem.gml @@ -0,0 +1,2050 @@ +//All missions that run on a planet now need their own PlanetProblem instance +//missions for the most part can only run from predefined points in the code +// to run from each of these points each mission must have a registered function these functions are then called implicitly +//each function follows the format `___` +/* the current entry points for the code are + "per_turn" - runs every end turn to check for certain conditions often contains reactions to actions player has done last turn + "resolve" - runs when the mission timer hits 0 often contains the failure conditions for the mission + - both of the above run via basic_turn_end -> PlanetData.problem_count_down -> scr_enemy_ai_d + + "setup_battle" - runs when the player initiates a battle via drop select window on a planet with a problem on + "on_enemy_casulties" - runs during combat after player inflicts casualties to log data or inject mission specific combat logs + "battle_final_message" - runs during combat to tally data and display a final log to the combat log + "battle_aftermath" - runs post combat during obj_ncombat alarm_7 + "squad_selected" - runs after selecting a squad inn the squad select window (scr_manage_task_selector) + "unit_select" - runs after selecting units in the unit selection screen (scr_manage_task_selector) + "on_purge" - at the top of PlanetData.purge() passes in {action_type, action_score} as purge_data overrides standard purge popups + "init" - runs immediately after problem is created often used to populate initial popup or stack popup for turn end + + "accept" - is an edge case currently reserved for binding to button clicks in popups + + "planet_draw_feature_selected" - runs in a FeatureSelected instance it allows a player to select the mission from the star_Select/planet screen and view data about it + - each `____feature_selected` function fills the draw_data struct so that __feature_selected_draw can run + - by attaching a function to draw_data.button_function you can create windows to select specific marines and squads for missions + - do this by using select_units and select_squads which are binds of group_selection + - to handle the selected marines create `___unit_select` and ___squad_selected` functions + - selected marines will automatically get added to the members array creating a direct link to marines participating in a mission + + +- other than these entry points and any other later defined positions mission specific code should not run outside of the PlanetProblem container + +- to set an entry point up simply register the function as a static e.g + if i create static __inquisition_are_dicks_per_turn once a "inquisition_are_dicks" problem is registered on a planet via + PlanetData.new_problem("inquisition_are_dicks",200) the per turn check will run no other code is required +other info + - set a mission for deletion by setting delete_mission = true; this will delete the mission after the current function + has finished executing and +*/ + +//ANYTIME an exception is caught on a entry point for a mission the mission is prematurely deleted this ensures the player is not unfairly penalised for errors + +/// @param {string} _name +/// @param {Real} _timer +/// @param {struct} _data +/// @param {constructor PlanetData} _planet_data +function PlanetProblem(_name, _timer, _data, _planet_data) : Problem(_name, _timer, _data) constructor{ +p_data = _planet_data; +planet = p_data.planet; +system = p_data.system; + +//base only assigns members when data.members exists; default it here without clobbering that +if (!variable_struct_exists(self, "members")){ + members = []; +} + +static __refresh_data = function(){ + p_data = system.get_planet_data(planet); + members = clean_unit_array(members); +} + +extend_timer_for_warp_storm = true; +remove = false; +zero_timer_checks = true; +per_turn_checks = true; + +static mark = function(colour){ + __refresh_data(); + with (p_data.system){ + new_star_event_marker(colour) + } +} + +static save = function(){ + var _save_copy = variable_clone(self); + struct_remove(_save_copy, "system"); + struct_remove(_save_copy, "p_data"); + var _mems = clean_unit_array(members); + _save_copy.members = []; + for (var i=0;i -1){ + array_delete(system.p_problem[planet], _prob,1); + array_delete(p_data.problems, _prob,1); + } + } +} + +//overrides Problem's base version +static __handle_triggered_mission_func = function(func){ + if (!is_undefined(func)){ + __refresh_data(); + try { + func(); + } catch (_exception) { + delete_mission = true; + ERROR_HANDLER.handle_exception(_exception); + } + } + __check_delete(); + obj_controller.location_viewer.update_mission_log(); +} + +static basic_turn_end = function(){ + if (p_data.system.storm <= 0){ + timer--; + } + if ((timer > -1) && per_turn_checks) { + var _func = find_func("per_turn"); + __handle_triggered_mission_func(_func); + } + if ((timer == 0) && zero_timer_checks && !delete_mission) { + var _func = find_func("resolve"); + __handle_triggered_mission_func(_func); + } +} + +//triggered within drop select +static before_battle_effects = function(){ + instance_activate_object(obj_star); + var _func = find_func("setup_battle"); + __handle_triggered_mission_func(_func); + instance_deactivate_object(obj_star); +} + + +//triggered at the end of scr_shoot +static battle_on_enemy_casulties = function(){ + if (!struct_exists(self, "casualty_packet")){ + exit; + } + instance_activate_object(obj_star); + var _func = find_func("on_enemy_casulties"); + __handle_triggered_mission_func(_func); + + struct_remove(self, "casualty_packet"); + + instance_deactivate_object(obj_star); +} + +//triggers in obj_ncombat alarm 5 +static battle_final_message = function(){ + instance_activate_object(obj_star); + var _func = find_func("battle_final_message"); + __handle_triggered_mission_func(_func); + instance_deactivate_object(obj_star); +} + +static after_battle_effects = function(){ + instance_activate_object(obj_star); + var _func = find_func("battle_aftermath"); + __handle_triggered_mission_func(_func); + instance_deactivate_object(obj_star); +} + +static on_squad_selection = function(){ + var _func = find_func("squad_selected"); + __handle_triggered_mission_func(_func); + instance_deactivate_object(obj_star); +} + + +static on_unit_selection = function(){ + var _func = find_func("unit_select"); + if (!is_undefined(_func)){ + var _selec_data = obj_controller.selection_data; + if (struct_exists(_selec_data, "selections")){ + members = _selec_data.selections; + } + __handle_triggered_mission_func(_func); + } + instance_deactivate_object(obj_star); +} + +//TODO in the future this should be calculated once on feature selection and then draw each turn +static planet_draw_feature_selected = function(){ + if (!struct_exists(self, "draw_data")){ + exit; + } + draw_data.mission_description = ""; + draw_data.button_text = ""; + draw_data.button_function = noone; + draw_data.help = ""; + draw_data.button_tooltip = ""; + var _func = find_func("feature_selected"); + __handle_triggered_mission_func(_func); + __feature_selected_draw(); + struct_remove(self, "draw_data"); +} + +static __feature_selected_draw = function(){ + draw_text_transformed(draw_data.x1 + (draw_data.w / 2), draw_data.y1 + 5, description(), 2, 2, 0); + draw_set_halign(fa_left); + draw_set_color(c_gray); + draw_text_ext(draw_data.x1 + 10, draw_data.y1 + 40, draw_data.mission_description, -1, draw_data.w - 20); + var _text_body_height = string_height_ext(draw_data.mission_description, -1, draw_data.w - 20); + if (draw_data.help != "") { + draw_text_ext(draw_data.x1 + 10, draw_data.y1 + 40 + _text_body_height + 10, draw_data.help, -1, draw_data.w - 20); + _text_body_height += string_height_ext(draw_data.mission_description, -1, draw_data.w - 20) + 10; + } + + if (draw_data.button_text != "") { + var _button = draw_unit_buttons([draw_data.x1 + ((draw_data.w / 2) - (string_width(draw_data.button_text) / 2)), draw_data.y1 + 40 + _text_body_height + 10], draw_data.button_text); + if (draw_data.button_tooltip != "" && scr_hit(_button)) { + tooltip_draw(draw_data.button_tooltip); + } + if (point_and_click(_button)) { + if (is_callable(draw_data.button_function)) { + draw_data.button_function(); + destroy = true; + } else { + tooltip_draw("no implemented function"); + } + } + } +} + +static on_purge = function(){ + if (!struct_exists(self, "purge_data")){ + exit; + } + var _func = find_func("on_purge"); + __handle_triggered_mission_func(_func); + + struct_remove(self, "purge_data"); +} + +static __init = function(){ + if (p_id == ""){ + exit; + } + var _func = find_func("init"); + if (!is_undefined(_func)){ + __handle_triggered_mission_func(_func); + } else { + mark("green"); + } + /*switch(p_id){ + case "meeting": + var rando = choose(1, 2); + if (rando == 1) { + obj_controller.diplo_text += $"A proposal that needs further consideration and some negotiation. Meet me at {p_data.name()} and we shall resolve this."; + } + if (rando == 2) { + obj_controller.diplo_text += $"Interesting. I shall be at {p_data.name()} and, if you are sincere, you will come to me and we can take this proposal to its logical conclusion."; + } + scr_event_log("", $"Chaos Lord {obj_controller.faction_leader[eFACTION.CHAOS]} agrees to meet with you on {p_data.name()} to discuss an alliance."); + mark("purple"); + break; + case "harlequins": + var _text = $"Eldar Harlequins have been seen on planet {p_data.name()}. Their purposes are unknown."; + scr_popup("Harlequin Troupe", _text, "harlequin", ""); + mark("green"); + break; + default: + mark("green"); + break; + + }*/ +} +__init(); + +//self must be referenced like this or the compiler assumes i want feature to refer to the arg struct i'm passing +static select_units = function(select_from, purpose_string, number, selections = []){ + var _self = self; + group_selection(select_from, {purpose: purpose_string, purpose_code: p_id, number: number, system , feature: _self, planet, selections}); +} + +static select_squads = function(select_from, purpose_string, number, selections = []){ + var _self = self; + group_selection(select_from, {purpose: purpose_string, purpose_code: p_id, number: number, system , feature: _self, planet, selections, select_type: eMISSION_SELECT_TYPE.SQUADS}); +} +// by default mission battles do not reduce the fortification level or enemy power on a planet +static new_end_turn_battle = function(battle_opponent_id, special_id = p_id, enemy_data = undefined){ + var _battle_index = obj_turn_end.battles++; + obj_turn_end.battle[_battle_index] = 1; + obj_turn_end.battle_world[_battle_index] = planet; + obj_turn_end.battle_opponent[_battle_index] = battle_opponent_id; + obj_turn_end.battle_location[_battle_index] = system.name; + obj_turn_end.battle_object[_battle_index] = system; + obj_turn_end.battle_special[_battle_index] = { + special_id : special_id, + special_feature : self, + }; + if (is_undefined(enemy_data)){ + enemy_data = { + } + } + if (!struct_exists(enemy_data, "reduce_power")){ + enemy_data.reduce_power = false; + } + if (!struct_exists(enemy_data, "reduce_fortification")){ + enemy_data.reduce_fortification = false; + } + obj_turn_end.battle_special[_battle_index].battle_enemy_data = enemy_data; +} + +static new_battle = function(battle_opponent_id,special_id = p_id){ + var _battle = instance_create(0, 0, obj_ncombat); + _battle.enemy = battle_opponent_id; + _battle.battle_object = system; + _battle.battle_loc = system.name; + _battle.battle_id = planet; + _battle.battle_special = special_id; + _battle.special_feature = self; + return _battle; +} + +static __set_members_job_to_mission = function(){ + for (var i = 0; i < array_length(members); i++){ + var _unit = members[i]; + _unit.job = { + type: p_id, + planet: planet, + location: system.name, + }; + _unit.unload(planet, system); + } +}; + +static __hunt_beast_init = function(){ + stage_id = "preliminary"; + data.applicant = "Governor" +} + +static __hunt_beast_feature_selected = function(){ + draw_data.mission_description = $"The governor of {p_data.name()} has bemoaned the raiding of huge beasts on the fringes of the planets largest city, the numbers have swelled recently and are causing huge damage to the planets small economy. You could send a force to intervene, it would provide a fine test of metal for any that partake."; + draw_data.help = "This is a good opportunity to provide experience and training, having at least one marine with experience in such matters would be advisable"; + draw_data.button_text = "Send Hunters"; + draw_data.button_function = function() { + var _dudes = collect_role_group("all", system.name); + select_units(_dudes, "Beast Hunt", 3); + }; +}; + + +static __hunt_beast_unit_select = function() { + if (stage_id == "preliminary") { + __set_members_job_to_mission(); + var _numeral_name = p_data.name() + stage_id = "active"; + timer = irandom_range(2, 5);; + var _gar_pop = instance_create(0, 0, obj_popup); + //TODO some new MissonHelper methods for popups + _gar_pop.title = $"Marines assigned to hunt beasts around {_numeral_name}"; + _gar_pop.text = $"The governor of {_numeral_name} Thanks you for the participation of your elite warriors in your execution of such a menial task."; + _gar_pop.add_option("Happy Hunting"); + _gar_pop.image = ""; + _gar_pop.cooldown = 8; + obj_controller.cooldown = 20; + scr_event_log("", $"Beast hunters deployed to {_numeral_name} for {timer} months.", p_data.system.name); + obj_controller.close_popups = false; + } +} + +static __hunt_beast_resolve = function() { + delete_mission = true; + if (stage_id == "preliminary"){ + exit; + } + var _hunters = clean_unit_array(members); + if (array_length(_hunters) == 0){ + var _man_conditions = { + "job": "hunt_beast", + "max": 3, + }; + _hunters = collect_role_group("all", [system.name, planet, 0], false, _man_conditions); + if (array_length(_hunters) == 0){ + exit; + } + } + + var _mission_string = ""; + var _success = false; + var _tester = global.character_tester; + var _unit_report_string = ""; + var _deaths = 0; + var _successful_hunters = []; + + if (!array_length(_hunters)) { + return; + } + + for (var i = 0; i < array_length(_hunters); i++) { + var _unit = _hunters[i]; + var _unit_pass = _tester.standard_test(_unit, "weapon_skill", 10, ["beast"]); + if (_unit_pass[0]) { + if (!_success) { + _success = true; + } + _unit_report_string += _unit.add_trait("beast_slayer", true, true); + array_push(_successful_hunters, _unit); + } else { + var _tough_check = _tester.standard_test(_unit, "constitution", _unit.luck); + if (!_tough_check[0]) { + if (_tough_check[1] < -10) { + _unit_report_string += $"{_unit.name_role()} Was mauled to death\n"; + _unit.kill(true, false); + _deaths++; + } else { + if (irandom(30) < _unit.luck) { + _unit.add_or_sub_health(-100); + _unit_report_string += $"{_unit.name_role()} Was injured (health - 100)\n"; + } else { + _unit.add_or_sub_health(-250); + _unit_report_string += $"{_unit.name_role()} Was Badly injured, it is unknown if he will recover (health - 250)\n"; + } + } + } + } + _unit.job = "none"; + } + + if (_success) { + _mission_string = $"The mission was a success and a great number of beasts rounded up and slain, your marines were able to gain great skills and the prestige of your chapter has increased greatly across the planets populace."; + if (_deaths) { + _mission_string += $"Unfortunately {_deaths} of your marines died."; + } + _mission_string += $"\n{_unit_report_string}"; + } else { + _mission_string = $"The mission was a failure. The governor is disappointed and the legend of your chapter has undoubtedly been diminished"; + _mission_string += $"\n{_unit_report_string}"; + } + + scr_popup($"Beast Hunt on {p_data.name()}", _mission_string, "", ""); + for (var i = 0; i < array_length(_hunters); i++) { + _hunters[i].job = "none"; + } + delete_mission = true; +} + +static __train_forces_feature_selected = function() { + draw_data.mission_description = $"The governor of {p_data.name()} fears the planet will not hold in the case of major incursion, it has not seen war in some time and he fears the ineptitude of the commanders available, he asks for aid in planning a thorough plan for defense and schedule of works for a period of at least 6 months."; + draw_data.help = $"A task best suited to the more knowledgable or wise of your Commanders"; + draw_data.button_text = "Assign Officer"; + draw_data.button_function = function() { + var _dudes = collect_role_group(SPECIALISTS_CAPTAIN_CANDIDATES, system.name); + select_units(_dudes,"Select Officer", 1); + }; +} + +static __train_forces_unit_select = function() { + if (stage_id != "preliminary" || array_length(members) == 0) { + exit; + } + var _trainer = members[0]; + var _numeral_name = p_data.name(); + stage_id = "active"; + var _mission_length = irandom_range(3, 12); + timer = _mission_length; + //pop.image="ancient_ruins"; + var _gar_pop = instance_create(0, 0, obj_popup); + //TODO some new universal methods for popups + _gar_pop.title = $"Training forces on {_numeral_name} begins"; + _gar_pop.text = $"{_trainer.name_role()} Has taken leave of his current post in order to aid the governor of {_numeral_name} and his pdf commanders with training local forces and bolstering defences."; + var _is_cap = _trainer.has_role(eROLE.CAPTAIN); + + if (_is_cap) { + _gar_pop.text += "the governor seems to be impressed that such a high ranking officer has been assigned to his request (disp +3)"; + p_data.add_disposition(3); + } + + data.assigned_unit = _trainer.uid; + + //pip.image="event_march" + _gar_pop.add_option($"Good luck {_trainer.name()}"); + _gar_pop.image = ""; + _gar_pop.cooldown = 500; + obj_controller.cooldown = 500; + scr_event_log("", $"{_trainer.name_role()} deployed to {_numeral_name} for {_mission_length} months.", p_data.system.name); + obj_controller.close_popups = false; +} + +static __train_forces_resolve = function() { + delete_mission = true; + if (stage_id != "active") { + exit; + } + var _mission_string = ""; + var _trainer = fetch_unit_uid(data.assigned_unit); + if (!is_struct(_trainer)) { + exit; + } + var _unit_report_string = ""; + var _tester = global.character_tester; + var _wis_test_difficulty = -20; + var _tyannic_vet = _trainer.has_trait("tyrannic_vet"); + if (_tyannic_vet) { + _wis_test_difficulty += 10; + if (p_data.has_feature(eP_FEATURES.GENE_STEALER_CULT)) { + var _cult = p_data.get_features(eP_FEATURES.GENE_STEALER_CULT)[0]; + if (_cult.hiding) { + p_data.delete_feature(eP_FEATURES.GENE_STEALER_CULT); + _mission_string += $"Fortune has smiled on this mission, {_trainer.name_role()}'s abilities as a Veteran of dealing with the Tyranids came in handy and in a short period was able to discern the existencee of a _cult. He was able to organise those he considered to be still loyal to rally an extermiation of the _cult, reeports suggest he was so successful as to have completely wiped the genestealer presence from the planet"; + } + } + } + var _siege_master = _trainer.has_trait("siege_master"); + if (_siege_master) { + _wis_test_difficulty += 10; + } + var _brute = _trainer.has_trait("brute"); + if (_brute) { + _wis_test_difficulty -= 10; + } + + var _leader = _trainer.has_trait("natural_leader"); + if (_leader) { + _wis_test_difficulty += 10; + } + + var _unit_pass = _tester.standard_test(_trainer, "wisdom", _wis_test_difficulty); + if (_unit_pass[0]) { + var _new_pdf = p_data.recruit_pdf((_unit_pass[1] / 10)); //this will approximate podf improvement for the time being + _mission_string += $"Training of the Pdf went well and improved the quality of the pdf as well as providing sizeable big recruitment improvement for the planet {_new_pdf} new pdf were recruited"; + if (_leader) { + var _disp_gain = 10; + p_data.add_disposition(_disp_gain); + _mission_string += $"\n{_trainer.name_role()}s reputation a natural and confident leader proved well earned as he also made excellent diplomatic headway with the governor and his generals (disposition +{_disp_gain})"; + } + if (_siege_master) { + _mission_string += $"{_trainer.name()}s trained eye as a Siege Master also allowed him to make several improvements to the planets fortifications (fortification +1)"; + p_data.alter_fortification(1); + } else { + if (roll_dice(1, 100) > 75 && _trainer.intelligence > 45) { + _mission_string += $"{_trainer.name()} has proven themselves a great strategist when it comes to defensive structures beyond previousy known "; + var _start_stats = variable_clone(_trainer.get_stat_line()); + _trainer.add_trait("siege_master"); + var end_stat = _trainer.get_stat_line(); + var _stat_diff = compare_stats(end_stat, _start_stats); + _unit_report_string += $"{_trainer.name_role()} Has gained the trait {global.trait_list.siege_master.display_name}, {print_stat_diffs(_stat_diff)}\n"; + _mission_string += "The new insights have allowed for minor improvements to planetary fortifications (fortification +1)"; + p_data.alter_fortification(1); + } + } + } else { + var disp_loss = -5; + _mission_string += "The original training mission was a failure"; + if (_brute) { + _mission_string += "in no short part due to his brutish nature"; + } + _mission_string += "."; + + _mission_string += "He failed to work effectively with the existing chain of command"; + + if (_unit_pass[1] < -20) { + var _hard_loss_traits = [ + "harshborn", + "feral", + "zealous_faith", + "blood_for_blood", + "blunt", + "brute", + "brawler", + ]; + var _hard_loss = false; + for (var i = 0; i < array_length(_hard_loss_traits); i++) { + if (array_contains(_trainer.traits, _hard_loss_traits[i])) { + _hard_loss = true; + } + } + if (_hard_loss) { + _mission_string += $"His particularly gruelling regimes and standards imposed upon the senior officers of the pdf caused friction with physical injury being caused to one officer"; + disp_loss = -25; + _mission_string += "(disposition -25)"; + } + } + p_data.add_disposition(disp_loss); + } + _mission_string += $"\n{_unit_report_string}"; + scr_popup($"Training Forces on {p_data.name()}", _mission_string, "", ""); + _trainer.job = "none"; +} + +static __succession_resolve = function() { + var _result, _alert_text; + var _dice1 = roll_dice(1, 100); + var _dice2 = roll_dice(1, 100); + + _result = eFACTION.IMPERIUM; + _alert_text = ""; + if (_dice1 <= (p_data.corruption * 2)) { + _result = eFACTION.CHAOS; + } + if (_dice2 <= (p_data.population_influences[eFACTION.TAU] * 2)) { + _result = eFACTION.TAU; + } + + if (p_data.current_owner == eFACTION.IMPERIUM && _result != eFACTION.IMPERIUM) { + p_data.edit_pdf(p_data.guardsmen); + p_data.edit_guardsmen(-p_data.guardsmen); + p_data.set_new_owner(_result); + } + + _alert_text = $"War of Succession on {p_data.name()} has ended"; + + if (_result == eFACTION.CHAOS) { + _alert_text += " with Chaos in control."; + p_data.set_player_disposition(0); + scr_alert("red", "succession", _alert_text, p_data.system.x, p_data.system.y); + scr_event_log("purple", _alert_text); + } else if (_result == eFACTION.TAU) { + _alert_text += " with a Tau sympathizer in control."; + p_data.set_player_disposition(10 + choose(1, 2, 3, 4, 5, 6)); + p_data.add_forces(eFACTION.TAU, 2); + scr_alert("red", "succession", _alert_text, p_data.system.x, p_data.system.y); + scr_event_log("red", _alert_text); + } else if (_result == eFACTION.IMPERIUM) { + _alert_text += " The resultant governor is the most staunch pillar of the imperium."; + _alert_text += "."; + scr_alert("green", "succession", _alert_text, p_data.system.x, p_data.system.y); + scr_event_log("", _alert_text); + } else { + //At the moment does not fire but a worthy flavour option for down the line + _alert_text += " Word is the new Governor has Heretical leanings and sympathises with xenos."; + } + + p_data.delete_feature(eP_FEATURES.SUCCESSION_WAR); +} + +static __inquisition_recon_init = function(){ + + var _pop_data = { + mission: self, + options : __inquisition_mission_options() + }; + + var _text = $"The Inquisition wishes for you to investigate {p_data.name()}"; + _text += $" Boots are expected to be planted on its surface over the course of your investigation."; + _text += $" You have {timer} months to complete this task."; + scr_popup("Inquisition Recon", _text, "inquisition", _pop_data); +} + +static __inquisition_recon_accept = function(){ + mark("green"); + scr_event_log("", $"Inquisition Mission Accepted: The Inquisition wish for Astartes to land on and investigate {p_data.name()} within {timer} months.", system.name); + __popup_delete(); +} + +static __inquisition_recon_per_turn = function() { + if (p_data.player_forces <= 0){ + exit; + } + + var _pop_data = { + mission: self, + }; + scr_popup( + "Investigation Completed", + "Your marines have scouted out {p_data.name()} and satisfied the mission requirements.", + "inquisition", + _pop_data + ); + scr_event_log("", $"Inquisition Mission Completed: Your Astartes have successfully scouted {p_data.name()}."); + + delete_mission = true; + +} +static __inquisition_recon_resolve = function() { + delete_mission = true; + var _alert_text = "Inquisition Mission Failed: Investigate "; + alter_disposition(eFACTION.INQUISITION, -5); + _alert_text += $"{p_data.name()}."; + scr_alert("red", "mission_failed", _alert_text, 0, 0); + scr_event_log("red", _alert_text); +} + +static __inquisition_spyrer_init = function(){ + var _text = $"The Inquisition is trusting you with a special mission. An experienced Spyrer on hive world {p_data.name()}"; + _text += $" has began to hunt indiscriminately, and proven impossible to take down by conventional means. If they are not put down within {timer} month's time panic is likely. Can your chapter handle this mission?"; + var _pop_data = { + mission: self, + options: __inquisition_mission_options(), + }; + scr_popup("Inquisition Mission", _text, "inquisition", _pop_data); +} + +static __inquisition_spyrer_accept = function(){ + var _text = $"Inquisition Mission Accepted: An experienced Spyrer on {p_data.name()} must be put down within {timer} months."; + scr_event_log("", _text, system.name); +} +static __inquisition_spyrer_resolve = function() { + delete_mission = true; + var _planet_name = p_data.name(); + alter_disposition(eFACTION.INQUISITION, -3); + var _alert_text = $"The Spyrer on {_planet_name} has been left unchecked. In the ensuing carnage some high-ranking officials have been killed, along with several Nobles. Panic is running amock in several parts of the hives and the Inquisition is less than pleased."; + var _text = "Inquisition Mission Failed: The Spyrer on {_planet_name} was not removed."; + scr_popup("Inquisition Mission Failed", _alert_text, p_id, ""); + scr_event_log("red", _text); +} + +static __inquisition_spyrer_per_turn = function() { + if (p_data.player_forces > 20) { + var _tixt = $"The Spyrer on {p_data.name()} seems to have vanished, presumably gone into hiding."; + scr_popup("Spyrer Rampage", _tixt, p_id, ""); + } else if (p_data.player_forces <= 20) { + new_end_turn_battle( + 30, + p_id, + { + threat : 1, + fortified : false, + cols : [ + { + distance : 10, + flank : true, + enemies : [ + { + name : "Malcadon Spyrer", + number : 1 + } + ] + } + ] + } + ); + } +} + +static __inquisition_spyrer_battle_aftermath = function(){ + // title / text / image / special + if (!obj_ncombat.defeat){ + exit; + } + + delete_mission = true; + + var _tixt = $"The Spyrer on {p_data.name()} has been removed. The citizens and craftsman may sleep more soundly, the Inquisition likely pleased."; + + scr_popup("Inquisition Mission Completed", _tixt, p_id, ""); + + var _disp_gain = obj_controller.demanding ? choose(0, 0, 1) : 2; + var _disp_gain_string = alter_disposition(eFACTION.INQUISITION, _disp_gain, true); + + scr_event_log("", $"Inquisition Mission Completed: The Spyrer on {system.name} {planet} has been removed. {_disp_gain_string}", system.name); + scr_gov_disp(system.name, planet, choose(1, 2, 3, 4)); +} + +static __hunt_fallen_init = function(){ + var _text = localize("Sources indicate one of the Fallen may be upon {0}. We have {1} months to send out a strike team and scour the planet. Any longer and any Fallen that might be there will have escaped.", [p_data.name(), timer]); + scr_popup(localize("Hunt the Fallen"), _text, "fallen", ""); + scr_event_log("", localize("Sources indicate one of the Fallen may be upon {0}. We have {1} months to investigate.", [p_data.name(), timer])); + mark("purple"); +} + +static __hunt_fallen_per_turn = function() { + if (p_data.player_forces <= 0){ + exit; + } + if (irandom(1) == 1) { + var _group_big = choose(true, false); + var _battle_enemy_data = {}; + if (_group_big){ + _battle_enemy_data = { + threat : 1, + fortified : false, + cols : [ + { + distance : 80, + enemies : [ + { + name : "Fallen", + number : 1 + } + ] + } + ] + }; + + // * Large Fallen Group * + _battle_enemy_data = { + threat : 1, + fortified : false, + cols : [ + { + distance : 80, + enemies : [ + { + name : "Fallen", + number : choose(3, 4, 5) + } + ] + } + ] + }; + } + new_end_turn_battle( + 10, + p_id, + _battle_enemy_data + ); + } else { + delete_mission = true; + var _tixt = $"Your marines have scoured {p_data.name()} in search of the Fallen. Despite their best efforts, and meticulous searching, none have been found. It appears as though the information was faulty or out of date."; + scr_popup("Hunt the Fallen", _tixt, "fallen", ""); + scr_event_log("", $"Mission Successful: No Fallen located upon {p_data.name()}"); + } +} + +static __hunt_fallen_resolve = function() { + delete_mission = true; + //TODO marker point for cohesion mechanics + var _alert_text = ""; + if (irandom(100) > 33) { + // Give all marines +3d6 corruption and reduce loyalty by 20*/ + for (var _co = 0; _co <= obj_ini.companies; _co++) { + for (var _me = 0; _me < company_length(_co); _me++) { + var _unit = fetch_unit([_co, _me]); + if (_unit.base_group != "astartes") { + continue; + } + _unit.edit_corruption(irandom_range(3, 6)); + _unit.alter_loyalty(-10); + } + } + } + _alert_text = $"Any Fallen that may have been on {p_data.name()} "; + _alert_text += "have been given sufficient time to escape. Morale within your chapter has plummeted; some of your battle brothers have become restless and speak among each other in hushed tones."; + scr_popup("Hunt the Fallen Failed", _alert_text + "\n\n(Chapter wide loyalty: -10)\nChaplains note marked changes in behaviour of some brothers", "fallen", ""); + obj_controller.loyalty -= 10; + obj_controller.loyalty_hidden -= 10; + scr_event_log("red", $"Mission Failed: Any Fallen within the {system.name} system have been given time to escape."); +} + +function __hunt_fallen_battle_aftermath() { + if (obj_ncombat.defeat) { + exit; + } + delete_mission = true; + var _tixt = "The Fallen on " + p_data.name(); + scr_event_log("", $"Mission Successful: {_tixt} have been captured or purged."); + _tixt += $" have been captured or purged. They shall be brought to the Chapter {obj_ini.player_role_data[eROLE.CHAPLAIN].role}s posthaste, in order to account for their sins. "; + var _tex_options = [ + "Suffering is the beginning to penance.", + "Their screams shall be the harbinger of their contrition.", + "The shame they inflicted upon us shall be written in their flesh.", + ]; + _tixt += _tex_options[choose(0, 0, 1, 2)]; + scr_popup("Hunt the Fallen Completed", _tixt, "fallen", ""); +} + +static __mech_raider_init = function(){ + var _mission_loc = p_data.name(); + var _nearest_fleet = get_nearest_player_fleet(system.x, system.y); + if (_nearest_fleet == noone){ + delete_mission = true; + exit; + } + timer = get_viable_travel_time(5, _nearest_fleet.x, _nearest_fleet.y, system.x, system.y, _nearest_fleet, false); + var _vacation_time = 24; + timer += _vacation_time; + var _techs = collect_role_group([SPECIALISTS_TECHMARINES, false, true]); + + //tech count is calculated earlier called mission is not added to p_problems array if less than 3 + var _techs_required = min(array_length(_techs) - 2, 6); + data = {completion: 0, required_months: _vacation_time,techs_required:_techs_required} + var _eligible_roles = role_groups(SPECIALISTS_TECHMARINES); + obj_popup.text = $"The Adeptus Mechanicus await your forces at {_mission_loc}. They are expecting {_techs_required} {_eligible_roles}s and a Land Raider."; + scr_event_log("", $"Mechanicus Mission Accepted: {_techs_required} of your {_eligible_roles}s and a Land Raider are to be stationed at {_mission_loc} for {timer} months.", system.name); + mark("green"); + title = "Mechanicus Mission Accepted"; +} + +static __mech_raider_per_turn = function() { + var _techs = collect_role_group(SPECIALISTS_TECHMARINES,[system.name, planet, -1] , false,{},true ); + var _lr_count = scr_vehicle_count("Land Raider", [system.name, planet, -1]); + var _percent_complete = 0; + if ((_techs.number() >= data.techs_required) && (_lr_count >= 1)) { + _percent_complete = __increment_mission_completion(); + scr_alert("", "mission", $"Mechanicus Mission on {p_data.name()} is {floor(_percent_complete)}% complete.", 0, 0); + } + if (_percent_complete < 100){ + exit; + } + var _cleanup = array_create(obj_ini.companies+1, false); + delete_mission = true; + timer = -1 + per_turn_checks = false; + zero_timer_checks = false; + + var _roll1 = roll_dice_chapter(1, 100, "low"); + var result = ""; + + if (_roll1 <= 33) { + result = "New"; + } + if ((_roll1 > 33) && (_roll1 <= 66)) { + result = "Land Raider"; + } + if (_roll1 > 66) { + result = "Requisition"; + } + var _tech_role = obj_ini.player_role_data[eROLE.TECHMARINE].role; + + if (result == "New") { + scr_popup("Mechanicus Mission Completed", $"Your {obj_ini.player_role_data[eROLE.TECHMARINE].role} have worked with the Adeptus Mechanicus in a satisfactory manor. The testing and training went well, but your Land Raider was ultimately lost. 300 Requisition has been given to your Chapter and relations are better than before.", "mechanicus", ""); + obj_controller.requisition += 300; + alter_disposition(eFACTION.MECHANICUS ,2); + var _found = false; + for (var com = 0; com <= obj_ini.companies; com++) { + if (_found) { + break; + } + for (var i = 1; i <= 100; i++) { + if ((obj_ini.veh_role[com][i] == "Land Raider") && (obj_ini.veh_loc[com][i] == system.name) && (obj_ini.veh_wid[com][i] == planet)) { + destroy_vehicle(com, i); + _cleanup[com] = true; + _found = true; + break; + } + } + } + } + if (result == "Land Raider") { + scr_popup("Mechanicus Mission Completed", $"Your {_tech_role} have worked with the Adeptus Mechanicus in a satisfactory manor. The testing and training went well, but your Land Raider was ultimately lost. A new Land Raider has been provided in return.", "mechanicus", ""); + var _found = false; + alter_disposition(eFACTION.MECHANICUS ,1); + for (var com = 0; com <= obj_ini.companies; com++) { + if (_found) { + break; + } + for (var i = 1; i <= 100; i++) { + if ((obj_ini.veh_role[com][i] == "Land Raider") && (obj_ini.veh_loc[com][i] == system.name) && (obj_ini.veh_wid[com][i] == planet)) { + _found = true; + obj_ini.veh_hp[com][i] = 100; + } + } + } + } + if (result == "Requisition") { + scr_popup("Mechanicus Mission Completed", $"Your {_tech_role} have worked with the Adeptus Mechanicus in a satisfactory manor. The testing and training went well, but your Land Raider was ultimately lost. 600 Requisition has been given to your Chapter as compensation.", "mechanicus", ""); + obj_controller.requisition += 600; + alter_disposition(eFACTION.MECHANICUS ,1); + } + + for (var i = 0; i <= obj_ini.companies; i++) { + if (_cleanup[i]) { + with (obj_ini) { + scr_vehicle_order(i); + } + } + } + +} + +static __mech_raider_resolve = function() { + delete_mission = true; + var _alert_text = $"Mechanicus Mission Failed: Land Raider testing at {p_data.name()}."; + scr_alert("red", "mission_failed", _alert_text, 0, 0); + scr_event_log("red", _alert_text); + alter_disposition(eFACTION.MECHANICUS, -6); + delete_mission = true; +} + +static __mech_bionics_per_turn = function() { + var _units = p_data.collect_planet_group(); + var _bionics = _units.tally_attr("bionics"); + var _percent_complete = 0; + if (_bionics >= 10) { + _percent_complete = __increment_mission_completion(); + scr_alert("", "mission", $"Mechanicus Mission on {p_data.name()} is {floor(_percent_complete)}% complete.", 0, 0); + } + if (_percent_complete < 100){ + exit; + } + var _cleanup = array_create(obj_ini.companies + 1, 0); + delete_mission = true; + timer = -1 + per_turn_checks = false; + zero_timer_checks = false; + var _roll1 = roll_dice_chapter(1, 100, "low"); + var result = ""; + + if (_roll1 <= 33) { + result = "Requisition"; + } + if ((_roll1 > 33) && (_roll1 <= 66)) { + result = "Bionics"; + } + if (_roll1 > 66) { + result = "Marines Lost"; + } + var _mech_disp_change = 0; + var _text = "The Adeptus Mechanicus have finished experimenting on your marines"; + var _marines = collect_role_group("all", [system.name, planet, -1], false, {}, true); + if (result == "Marines Lost") { + _text += "- unfortunantly none of them have survived. 150 Requisition has provided as weregild for each Astartes lost."; + _mech_disp_change = 2; + obj_controller.requisition += 150 * _marines.number(); + _marines.kill_percent(100); + } else if (result == "Bionics" || result == "Requisition") { + _mech_disp_change = 1; + + if (result == "Bionics") { + var _new_bionics = irandom_range(40, 100); + scr_add_item("Bionics", _new_bionics); + _text += $" A large amount of additional Bionics have been provided by the Mechanicus as a reward ( X{_new_bionics} Bionics added to stocks)"; + } else if (result == "Requisition") { + var _req_gain = irandom_range(200, 650); + _text += $"{_req_gain} Requisition has been provided by the Mechanicus as a reward."; + obj_controller.requisition += _req_gain; + } + var _limit = 0; + for (var i = 0; i < array_length(_marines.units); i++) { + var _unit = _marines.units[i]; + if (_unit.bionics > 0) { + _unit.update_health(irandom_range(2, 80)); + + if (!_unit.has_trait("flesh_is_weak")) { + _unit.update_loyalty(-20); + } + + repeat (choose(2, 3, 4)) { + _unit.add_bionics("none", "any", false); + } + _limit++; + } + if (_limit >= 10) { + break; + } + } + } + _text += $"\n{alter_disposition(eFACTION.MECHANICUS, _mech_disp_change, true)}"; + scr_popup("Mechanicus Mission Completed", _text, "mechanicus"); + sort_all_companies_to_map(_cleanup); +} + +static __mech_bionics_resolve = function() { + delete_mission = true; + var _alert_text = $"Mechanicus Mission Failed: bionics testing at {p_data.name()}."; + scr_alert("red", "mission_failed", _alert_text, 0, 0); + scr_event_log("red", _alert_text); + alter_disposition(eFACTION.MECHANICUS, -6); + delete_mission = true; +} +static __mech_tomb_init = function() { + var _name = p_data.name(); + obj_popup.text = $"The Adeptus Mechanicus await your forces at {_name}. They are expecting at least two squads of Astartes and have placed the testing on hold until their arrival. {global.chapter_name} have 16 months to arrive."; + scr_event_log("", $"Mechanicus Mission Accepted: At least two squads of marines are expected at {_name} within 16 months.", system.name); + mark("green"); + obj_popup.title = "Mechanicus Mission Accepted"; + reset_popup_options(); + obj_popup.cooldown = 15; +} +static __mech_tomb_per_turn = function() { + if (stage_id == "awating_player"){ + var _marines = collect_role_group("all", [system.name, planet, -1]); + if (array_length(_marines) >= 20) { + stage_id = "exploring"; + timer = 999; + data.turns = 0; + scr_popup("Mechanicus Research", $"The Mechanicus Research team on planet {p_data.name()} has taken note of your Astartes and are now prepared to begin their research. Your marines are to stay on the planet until further notice.", "necron_cave", ""); + } + } else { + __mech_tomb_exploring(); + } +} + +static __mech_tomb_exploring = function() { + data.turns++; + var _battli = 0; + var _roll1 = roll_dice_chapter(1, 100 + data.turns, "low"); + + if (_roll1 > 98) { + if ((_roll1 >= 90) && (_roll1 < 98)) { + _battli = 1; + } // oops + if (_roll1 >= 98) { + _battli = 2; + } // very oops, much necron, wow + + if ((_battli > 0) && (p_data.player_forces > 0)) { + // Queue the battle + var _special = _battli == 1 ? "study2a" : "study2b"; + data.battle_key = _special; + //currently inaccessible + if (obj_turn_end.battle_opponent[obj_turn_end.battles] == 11) { + if (p_data.has_feature(eP_FEATURES.CHAOSWARBAND)) { + _special = "ChaosWarband"; + } + } + new_end_turn_battle(13, "mars_tomb",{threat : choose(2,3)}); + } + if ((_battli > 0) && (p_data.player_forces <= 0)) { + // XDDDDD + scr_popup("Mechanicus Mission Failed", $"The Mechanicus Research team on planet {p_data.name()} have been killed by Necrons in the absence of your astartes. The Mechanicus are absolutely livid, doubly so because of the promised security they did not recieve.", "", ""); + obj_controller.turns_ignored[3] += choose(8, 10, 12, 14, 16, 18, 20, 22, 24); + alter_disposition(eFACTION.MECHANICUS, -25); + delete_mission = true; + } + } else { + if (_roll1 > 20) { + scr_alert("", "mission", $"Adeptus Mechanicus research within the Necron Tomb of {p_data.name()} continues.", 0, 0); + } else if (_roll1 <= 20) { + var _text, _reward = choose(1, 1, 2); + if (scr_has_adv("Tech-Brothers")) { + _reward = choose(1, 2); + } + + if (_reward == 1) { + obj_controller.requisition += 400; + _text = $"The Mechanicus Research team on planet {p_data.name()} have completed their work without any major setbacks. Pleased with your astartes' work, they have granted you 400 Requisition to be used as you see fit."; + scr_event_log("", $"Mechanicus Mission Completed: The Mechanicus research team on {p_data.name()} have completed their work."); + } else if (_reward == 2) { + var _last_artifact = scr_add_artifact("random", "", 0); + _text = $"The Mechanicus Research team on planet {p_data.name()} have completed their work without any major setbacks. Pleased with your astartes' work, they have granted your Chapter an artifact, to be used as you see fit."; + scr_event_log("", $"Mechanicus Mission Completed: The Mechanicus research team on {p_data.name()} have completed their work."); + scr_event_log("", "Artefact gifted from Mechanicus."); + } + _text += "\n" + add_disposition(eFACTION.MECHANICUS, 1); + scr_popup("Mechanicus Mission Completed", _text, "mechanicus", ""); + delete_mission = true; + timer = -1 + per_turn_checks = false; + zero_timer_checks = false; + } + } +} + +static __mech_tomb_resolve = function() { + delete_mission = true; + var _alert_text = $"Mechanicus Mission Failed: Necron Tomb Study at {p_data.name()}."; + scr_alert("red", "mission_failed", _alert_text, 0, 0); + scr_event_log("red", _alert_text, system.name); + alter_disposition(eFACTION.MECHANICUS, -15); + delete_mission = true; +} + +static __mech_tomb_battle_aftermath = function() { + if (obj_ncombat.defeat) { + delete_mission = true; + + var _disp_change = alter_disposition(eFACTION.MECHANICUS, -10, true); + + if (data.battle_key == "study2a") { + scr_popup("Mechanicus Mission Failed", $"All of your Astartes and the Mechanicus Research party have been killed down to the last man. The research is a bust, and the Adeptus Mechanicus is furious with your chapter for not providing enough security. Relations with them are worse than before. {_disp_change}", "", ""); + } + if (data.battle_key == "study2b") { + battle_object.p_necrons[battle_id] = 5; + awaken_tomb_world(battle_object.p_feature[battle_id]); + _disp_change = alter_dispositions([[eFACTION.MECHANICUS, -15], [eFACTION.INQUISITION, -5]], true); + scr_popup("Mechanicus Mission Failed", $"All of your Astartes and the Mechanicus Research party have been killed down to the last man. The research is a bust. To make matters worse the Necron Tomb has fully awakened- countless numbers of the souless machines are now pouring out of the tomb. The Adeptus Mechanicus are furious with your chapter. {_disp_change}", "necron_army", ""); + scr_alert("", "inquisition", "The Inquisition is displeased with your Chapter for tampering with and awakening a Necron Tomb", 0, 0); + scr_event_log("", "The Inquisition is displeased with your Chapter for tampering with and awakening a Necron Tomb"); + } + + scr_event_log("", "Mechanicus Mission Failed: Necron Tomb Research Party and present Astartes have been killed."); + + } +} + +static __mech_mars_resolve = function() { + delete_mission = true; + var _techs_taken = 0; + var _techs = collect_role_group([SPECIALISTS_TECHMARINES,false,true],system.name); + for (var i = 0; i < array_length(_techs); i++) { + var _unit = _techs[i]; + system.p_player[planet] -= _unit.get_unit_size(); + _unit.location_string = "Mechanicus Vessel"; + _unit.planet_location = 0; + _unit.ship_location = -1; + _unit.job = { + type: "mechanicus mission", + }; + _techs_taken += 1; + } + + if (_techs_taken == 0) { + var alert_text = $"Mechanicus Mission Failed: Journey to Mars Catacombs at {p_data.name()}."; + scr_alert("red", "mission_failed", alert_text, 0, 0); + scr_event_log("red", alert_text); + alter_disposition(eFACTION.MECHANICUS,-10) + } else if (_techs_taken > 0) { + if (_techs_taken >= 5) { + alter_disposition(eFACTION.MECHANICUS,max(_techs_taken, 4)) + } + var _text = $"Mechanicus Ship departs for the Mars catacombs. Onboard are {_techs_taken} of your {obj_ini.player_role_data[eROLE.TECHMARINE].role}s."; + scr_alert("", "mission", _text, 0, 0); + scr_event_log("green", _text); + var flit = create_enemy_fleet(system.x, system.y, eFACTION.MECHANICUS); + + with (flit) { + sprite_index = spr_fleet_mechanicus; + capital_number = 1; + image_index = 0; + image_speed = 0; + trade_goods = "mars_spelunk1"; + home_x = x; + home_y = y; + action_x = x + lengthdir_x(3000, obj_controller.terra_direction); + action_y = y + lengthdir_y(3000, obj_controller.terra_direction); + set_fleet_movement(false, "move", 48, 48); + } + } +} + +static __provide_garrison_init = function(){ + if (system.get_garrison(planet).garrison_force) { + delete_mission = true; + exit; + } + stage_id = "preliminary"; + data.applicant = "Governor" + data.reason = choose("stability", "importance"); +} + +static __provide_garrison_feature_selected = function() { + //TODO : complete logic if (data.reason == "importance") {} + draw_data.mission_description = $"The governor of {p_data.name()} has requested a force of marines might stay behind following your departure.\n\n\n assign a squad to garrison to initiate mission, The garrison leeader will need to be capable of conducting himself in a diplomatic manner in order for the garrison duration to be a success"; +} + +static provide_garrison_on_garrison = function() { + if (stage_id != "preliminary") { + exit; + } + var _numeral_name = p_data.name(); + stage_id = "active"; + var _garrison_length = 10 + irandom(6); + timer = _garrison_length; + var _gar_pop = instance_create(0, 0, obj_popup); + //TODO some new universal methods for popups + _gar_pop.title = $"Requested Garrison Provided to {_numeral_name}"; + _gar_pop.text = $"The governor of {_numeral_name} Thanks you for considering his request for a garrison, you agree that the garrison will remain for at least {_garrison_length} months."; + _gar_pop.add_option("Commence Garrison"); + _gar_pop.image = ""; + _gar_pop.cooldown = 8; + obj_controller.cooldown = 8; + scr_event_log("", $"Garrison committed to {_numeral_name} for {_garrison_length} months.", p_data.system.name); +} + +static __provide_garrison_resolve = function() { + delete_mission = true; + if (stage_id != "active"){ + exit; + } + + var _garrison = p_data.garrisons; + _garrison.update(); + if (p_data.current_owner != eFACTION.IMPERIUM || !_garrison.garrison_force) { + p_data.add_disposition(-20); + scr_popup($"Agreed Garrison of {p_data.name()}", $"your agreed garrison of {p_data.name()} was cut short by your chapter the planetary governor has expressed his displeasure (disposition -20)", "", ""); + return; + } + + var _mission_string = $"The garrison on {p_data.name()} has finished the period of garrison support agreed with the planetary governor."; + var _result = _garrison.garrison_disposition_change(); + if (!_garrison.garrison_leader) { + _garrison.find_leader(); + } + var _leader = _garrison.garrison_leader; + + var _effect = 0; + if (_result == "none") { + //TODO make a dedicated plus minus string function if there isn't one already + } else if (_result < 0) { + _effect = _result * irandom_range(1, 5); + _mission_string += $"A number of diplomatic incidents occurred over the period which had considerable negative effects on our disposition with the planetary governor (disposition -{_effect})"; + } else { + _effect = _result * irandom_range(1, 5); + _mission_string += $"As a diplomatic mission the duration of the stay was a success with our political position with the planet being enhanced greatly (disposition +{_effect})"; + } + + p_data.add_disposition(_effect); + var _tester = global.character_tester; + var _widom_test = _tester.standard_test(_leader, "wisdom", 0, ["siege"]); + + if (_widom_test[0]) { + p_data.alter_fortification(1); + _mission_string += $"while stationed {_leader.name_role()} makes several notable observations and is able to instruct the planets defense core leaving the world better defended (fortifications+1)."; + } + //TODO just generally apply this each turn with a garrison to see if a cult is found + if (p_data.has_feature(eP_FEATURES.GENE_STEALER_CULT)) { + var _cult = p_data.get_features(eP_FEATURES.GENE_STEALER_CULT)[0]; + if (_cult.hiding) { + _widom_test = _tester.standard_test(_leader, "wisdom", 0, ["tyranids"]); + if (_widom_test[0]) { + _cult.hiding = false; + _mission_string += "Most alarmingly signs of a Genestealer cult are noted by the garrison. how far the rot has gone will now need to be investigated and the xenos taint purged."; + } + } + } + scr_popup($"Agreed Garrison of {p_data.name()} complete", _mission_string, "", ""); +} + +static __protect_raiders_init = function(){ + stage_id = "preliminary"; + data.applicant = "Governor"; +} + +static __protect_raiders_feature_selected = function() { + draw_data.mission_description = $"The governor of {p_data.name()} has sent many requests to the sector commander for help with defending against xenos raids on the populace of the planet, the reports seem to suggest the xenos in question are in fact dark eldar."; + draw_data.help = "Set a squads to ambush"; + draw_data.button_text = "Send Squad"; + draw_data.button_tooltip = "mileage may vary on playability of this mission progress at your own risk"; + draw_data.button_function = function() { + var _dudes = collect_role_group("all", system.name); + select_squads(_dudes, "Select Squad for Ambush", 1) + }; +} + +static __protect_raiders_battle_aftermath = function() { + // show_message(obj_turn_end.current_battle); + // show_message(obj_turn_end.battle_world[obj_turn_end.current_battle]); + // title / text / image / speshul + var _planet_string = p_data.name(); + delete_mission = true; + if (!obj_ncombat.defeat) { + p_data.add_disposition(15); + var _tixt = $"The Raiding forces on {_planet_string} have been removed. The citizens and craftsman may sleep more soundly. ({_planet_string} disp +15)"; + + scr_popup("Planet Protected", _tixt, "protect_raiders", ""); + scr_event_log("", $"Governor Request completed: Raiding forces on {_planet_string} have been eliminated.", system.name); + } else { + p_data.add_disposition(-15); + var _tixt = $"The Raiding forces on {_planet_string} dispatched with your forces and will continue with their bloody practices. The citizens remain unsafe and the governor is unimpressed. (planet disp -15)"; + scr_popup("Planet Protected", _tixt, "protect_raiders", ""); + scr_event_log("", $"Governor Request failed: Raiding forces on {_planet_string} continue to harrass population.", system.name); + } +} + +static __protect_raiders_squad_selected = function() { + data.squad = data.squads[0]; + var _squad = data.squad; + var _squad_units = _squad.get_members(); + var _squad_wisdom = stat_average(_squad_units, "wisdom"); + var _squad_dex = stat_average(_squad_units, "dexterity"); + var _tester = global.character_tester; + + var _mod = _squad_wisdom + _squad_dex / 20; + if (scr_has_adv("Ambushers")) { + _mod += 10; + } + + var _leader = _squad.determine_leader(); + if (!is_struct(_leader)) { + return; + } + var _wis_test = _tester.standard_test(_leader, "wisdom", _mod, ["ambush"]); + + if (!_wis_test[0]) { + scr_toggle_manage(); + if (_wis_test[1] < -25) { + var _gar_pop = instance_create(0, 0, obj_popup); + _gar_pop.title = $"Strange Disappearance"; + _gar_pop.pdata = p_data; + _gar_pop.text = $"Your Marines make planet fall and are directed to report to the governor for the duration of the operation after a period of reconnaissance dig in for their ambush. After a two weeks have passed A message from the governor reaches your astropaths that your marines have not been heard of for some time, The raiders also were not noted to have arrived onor left the planet"; + var _dead_marine = array_random_index(_squad_units); + for (var i = 0; i < array_length(_dead_marine); i++) { + if (i == _dead_marine) { + continue; + } + + var _marine = _dead_marine[i]; + + _marine.location_string = "Lost"; + _marine.ship_location = -1; + _marine.planet_location = 0; + } + _gar_pop.text += $"After eventual investigation it appears the eldar anticipated the would be ambushers and turned the tides. {_squad_units[_dead_marine].name_role()}s body is eventually discovered some way off from the main battle his rent armour and body showing the extent of combat that must have occured"; + + _gar_pop.text += "\nThe total loss of a squad in what was meant to be a routine operation is bad for moral and your chapters reputation you must now decide how to proceed"; + + _gar_pop.add_option({str1: "Suppress the Information", choice_func: protect_raiders_suppress_information}); + + _gar_pop.add_option({str1: "Hold a Memorial", choice_func: protect_raiders_hold_memorial}); + } else { + var _gar_pop = instance_create(0, 0, obj_popup); + _gar_pop.title = $"Ineffective Ambush"; + _gar_pop.text = $"Your Marines Are ineffective at setting up an ambush the assailants clearly got wind of the operation or the plan was otherwise so ill thought out that by the time your forces arrived there was little that could be done to intercept them"; + _gar_pop.text += $""; + _gar_pop.pathway = "protect_raiders_ineffective"; + _gar_pop.pdata = p_data; + p_data.add_disposition(-10); + _gar_pop.text += "\nThe governor is unhappy and it has done little to improve your reputation with the planets populace but otherwise very little harm has been done. It is likely the raiders will choose better targets without the possible threat of space marine presence for the foreseeable future\nGovernor Disposition : -10"; + + _gar_pop.add_option("continue"); + } + } else { + var _battle = new_battle(eFACTION.ELDAR); + + _roster = new Roster(); + with (_roster) { + selected_units = _squad_units; + setup_battle_formations(); + add_to_battle(); + } + exit_adhoc_manage(); + + _battle.battle_enemy_data = { + threat : 3, + fortified : false, + reduce_fortification : true, + reduce_power : true, + cols : [ + { + distance : 20, + enemies : [ + { + name : "Dire Avenger", + number : 40, + special : "shimmershield" + }, + { + name : "Dire Avenger Exarch", + number : 4, + special : "shimmershield" + }, + { + name : "Autarch", + number : 1 + }, + { + name : "Farseer", + number : 1, + special : "farseer_powers" + }, + { + name : "Night Spinner", + number : 1 + } + ] + } + ] + }; + } +} + +static __inquisition_tomb_init = function(){ + var _text = $"The Inquisition is trusting you with a special mission. They have reason to suspect the Necron Tomb on planet {p_data.name()}"; + _text += $" may become active. You are to send a small group of marines to plant a bomb deep inside, within {timer} months. Can your chapter handle this mission?"; + var _pop_data = { + mission: self, + options: __inquisition_mission_options(), + }; + scr_popup("Inquisition Mission", _text, "inquisition", _pop_data); +} + +static __inquisition_tomb_accept = function(){ + var _text = $"Inquisition Mission Accepted: A bomb must be planted within the Necron Tomb on {p_data.name()} within {timer} months."; + scr_event_log("", _text, system.name); +} + +static __inquisition_tomb_per_turn = function() { + if (p_data.player_forces <= 0){ + exit; + } + LOGGER.info($"player on planet with necron mission {name} planet: {planet}"); + var _have_bomb = 0; + _have_bomb = scr_check_equip("Plasma Bomb", system.name, planet, 0); + LOGGER.info($"have bomb? {_have_bomb} "); + if (_have_bomb == 0) { + exit; + } + var _tixt; + _tixt = $"Your marines on {p_data.name()}"; + _tixt += " are prepared and ready to enter the Necron Tombs. A Plasma Bomb is in tow."; + var _number = instance_exists(obj_turn_end) ? 1 : 0; + var _pop_data = { + mission: self, + loc: system.name, + planet: planet, + number: _number, + options: [ + { + str1: "Begin the Mission", + choice_func: inquisition_tomb_mission_start, + }, + { + str1: "Not Yet", + choice_func:__popup_delete, + }, + ], + }; + scr_popup("Necron Tomb Excursion", _tixt, $"necron_cave", _pop_data); +} + +static inquisition_tomb_mission_start = function() { + obj_popup.title = $"Necron Tunnels : {data.mission_stage}"; + obj_popup.replace_options([ + {str1: "Continue", choice_func: inquisition_tomb_mission_sequence}, + {str1: "Return to the surface", choice_func: __popup_delete } + ]); + obj_popup.image = "necron_tunnels_1"; + obj_popup.text = "Your marines enter the massive tunnel complex, following the energy readings. At first the walls are cramped and tiny, closing about them, but the tunnels widen at a rapid pace."; +} + +/// @self Asset.GMObject.obj_popup +/// @desc Advances the Necron Tomb mission or starts a combat encounter. +/// @returns {Undefined} +static inquisition_tomb_mission_sequence = function() { + var _battle; + var player_forces = system.player_forces; + var _penalty = 0; + var _roll = roll_dice_chapter(1, 100, "low"); + _battle = 0; + instance_activate_all(); + + // SMALL TEAM OF MARINES + if (player_forces > 6) { + _penalty = 10; + } + if (player_forces > 10) { + _penalty = 20; + } + if (player_forces >= 20) { + _penalty = 30; + } + if (player_forces >= 40) { + _penalty = 50; + } + if (player_forces >= 60) { + _penalty = 100; + } + _roll += _penalty; + + // _roll=30;if (string_count("3",title)>0) then _roll=70; + + // Result + data.tomb_awakens = false; + if (_roll <= 60) { + advance_inquisition_tomb_mission(); + exit; + } + if ((_roll > 60) && (_roll <= 82)) { + // Necron Wraith attack + _battle = 1; + } + if ((_roll > 82) && (_roll <= 92)) { + // Tomb Spyder attack + _battle = 2; + } + if ((_roll > 92) && (_roll <= 97)) { + // Tomb Stalker + _battle = 3; + } + if (_roll > 97) { + // Tomb World wakes up + data.tomb_awakens = true; + if (player_forces <= 30) { + _battle = 4; + } + if (player_forces > 30) { + _battle = 5; + } + if (player_forces > 100) { + _battle = 6; + } + } + + if (_battle > 0) { + instance_deactivate_all_safe(); + instance_activate_object(obj_star); + var _col = []; + var _battle_data = { + threat : 1, + formation_set : 1, + fortified : 0, + reduce_fortification : true, + reduce_power : true, + } + switch (_battle){ + case 1: + _battle_data.cols = [ + { + distance : 10, + engaged : true, + enemies : [ + { + name : "Necron Wraith", + number : 1 + }, + { + name : "Necron Wraith", + number : 1 + } + ] + + } + ] + data.enemy = "wraith"; + break; + case 2: + _battle_data.cols = [ + { + distance : 10, + engaged : true, + enemies : [ + { + name : "Canoptek Spyder", + number : 1 + }, + { + name : "Canoptek Scarab", + number : 20 + } + ] + + } + ] + data.enemy = "spyder"; + break; + case 3: + _battle_data.cols = [ + { + distance : 10, + engaged : true, + enemies : [ + { + name : "Tomb Stalker", + number : 1 + } + ] + + } + ] + data.enemy = "stalker"; + break; + case 4: + _battle_data.threat = 2 + break + case 5: + case 6: + _battle_data.threat = 3 + break + } + + var _battle = new_battle( + eFACTION.NECRONS, + ) + _battle.battle_enemy_data = _battle_data; + _roster = new Roster(); + with (_roster) { + roster_location = system.name; + roster_planet = planet; + determine_full_roster(); + only_locals(); + update_roster(); + if (array_length(selected_units)) { + setup_battle_formations(); + add_to_battle(); + } + } + + instance_deactivate_object(obj_star); + + instance_destroy(obj_popup); + } + + exit; +} + +static __inquisition_tomb_battle_aftermath = function(){ + if (!data.tomb_awakens) { + if (defeat == 1) { + obj_controller.combat = 0; + obj_controller.cooldown = 10; + obj_turn_end.alarm[1] = 4; + } else if (defeat == 0) { + obj_controller.combat = 0; + var pip = instance_create(0, 0, obj_popup); + inquisition_tomb_mission_start(); + var _completed = advance_inquisition_tomb_mission(); + with (pip) { + if (_completed) { + keyboard_clear(vk_enter); + } else { + text = "The last of the attackers is cut down. Your marines regroup in the tunnel and ready themselves to press deeper into the complex.\n\n" + text; + } + number = instance_exists(obj_turn_end); + } + } + } else { + var pip = instance_create(0, 0, obj_popup); + with (pip) { + title = "Necron Tomb Awakens"; + image = "necron_army"; + if (obj_ncombat.defeat == 0) { + text = "Your marines make a tactical retreat back to the surface, hounded by Necrons all the way. The Inquisition mission is a failure- you were to blow up the Necron Tomb World stealthily, not wake it up. The Inquisition is not pleased with your conduct."; + } else { + text = "Your marines are killed down to the last man. The Inquisition mission is a failure- you were to blow up the Necron Tomb World stealthily, not wake it up. The Inquisition is not pleased with your conduct."; + } + } + + delete_mission = true; + + with (system) { + var _planet = obj_ncombat.battle_id; + p_necrons[planet] = 4; + if (awake_tomb_world(p_feature[_planet]) == 0) { + awaken_tomb_world(p_feature[_planet]); + } + } + + + alter_disposition(eFACTION.INQUISITION, -5); + obj_controller.combat = 0; + + with (pip) { + number = instance_exists(obj_turn_end); + } + } +} + +static advance_inquisition_tomb_mission = function() { + data.mission_stage++; + obj_popup.title = $"Necron Tunnels : {data.mission_stage}"; + + if (data.mission_stage == 2) { + obj_popup.image = "necron_tunnels_2"; + obj_popup.text = "The energy readings are much stronger, now that your marines are deep inside the tunnels. What was once cramped is now luxuriously large, the tunnel ceiling far overhead decorated by stalactites."; + return false; + } + if (data.mission_stage == 3) { + obj_popup.image = "necron_tunnels_3"; + obj_popup.text = "After several hours of descent the entrance to the Necron Tomb finally looms ahead- dancing, sickly green light shining free. Your marine confirms that the Plasma Bomb is ready."; + return false; + } + if (data.mission_stage >= 4) { + obj_popup.image = ""; + obj_popup.title = "Inquisition Mission Completed"; + obj_popup.text = "Your marines finally enter the deepest catacombs of the Necron Tomb. There they place the Plasma Bomb and arm it. All around are signs of increasing Necron activity. With half an hour set, your men escape back to the surface. There is a brief rumble as the charge goes off, your mission a success."; + reset_popup_options(); + __refresh_data(); + + alter_disposition(eFACTION.INQUISITION, obj_controller.demanding ? choose(0, 0, 1) : 1); + + delete_mission = true; + seal_tomb_world(p_data.features); + + scr_event_log("", $"Inquisition Mission Completed: Your Astartes have sealed the Necron Tomb on {p_data.name()}.", system.name); + p_data.add_disposition(irandom_range(3, 7)); + scr_check_equip("Plasma Bomb", system.name, planet, 1); + return true; + } + return false; +} + +static __inquisition_tomb_resolve = function() { + delete_mission = true; + alter_disposition(eFACTION.INQUISITION, -8); + var _alert_text = $"The Necron Tomb of planet {p_data.name()} has not been deactivated in time. It has awakened, rank upon rank of Necrons pouring out to the planet's surface. The Inquisition is not pleased with your failure."; + scr_popup("Inquisition Mission Failed", _alert_text, "necron_army", ""); + scr_event_log("red", $"Inquisition Mission Failed: Bombing run failed; the Necron Tomb on {p_data.name()} has become active."); + + p_data.add_forces(eFACTION.NECRONS, 4); + if (awake_tomb_world(p_data.features) == 0) { + awaken_tomb_world(p_data.features); + } +} + +static __inquisition_demon_world_init = function(){ + var _text = $"The Inquisitor is trusting you with a special mission. The planet {p_data.name()} has been uncovered as a Demon World"; + if (obj_controller.demanding) { + _text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. An out of control Demon World {p_data.name()} must be cleansed within {timer} months."; + } + _text += $"The taint of chaos must be eradicated from this system. Can your chapter handle this mission?"; + var _pop_data = { + mission: self, + options: __inquisition_mission_options(), + }; + scr_popup( + "Inquisition Mission Demon World", + _text, + "inquisition", + _pop_data + ); +} + +static __inquisition_demon_world_accept = function(){ + scr_event_log("", $"Inquisition Mission Accepted: The demon world of {system.name} {scr_roman(planet)} will be purged by your hand.", system.name); + new_star_event_marker("green"); + with(obj_popup){ + popup_default_close(); + } +} + +static __inquisition_tyranid_org_init = function(){ + var _pop_data = { + mission: self, + options: __inquisition_mission_options(), + }; + var _text = $"An Inquisitor is trusting you with a special mission. The planet {p_data.name()}"; + _text += " is ripe with Tyranid organisms. They require that you capture one of the Gaunt species for research purposes. Can your chapter handle this mission?"; + if (obj_controller.demanding) { + _text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. {global.chapter_name} are to capture a Gaunt organism and return it, unharmed- 4x Webbers have been provided for this purpose."; + } + scr_popup("Inquisition Mission", _text, "inquisition",_pop_data); +} + +static __inquisition_tyranid_org_accept = function(){ + obj_popup.image = "webber"; + obj_popup.title = "New Equipment"; + obj_popup.fancy_title = 0; + obj_popup.text_center = 0; + obj_popup.text = $"{global.chapter_name} have been provided with 4x Astartes Webbers in order to complete the mission."; + reset_popup_options(); + scr_add_item("Webber", 4); + obj_controller.cooldown = 10; + scr_event_log("", $"Inquisition Mission Accepted: The Inquisition wishes for the capture of a particular strain Gaunt noticed on {p_data.name()} is advisable.", system.name); + obj_controller.useful_info += "Tyr|"; + data.captured_gaunt = 0; +} + +static __inquisition_tyranid_org_setup_battle = function(){ + if ((obj_ncombat.enemy != eFACTION.TYRANIDS) || (obj_ncombat.battle_object.space_hulk)) { + exit; + } + obj_ncombat.battle_special = p_id; + obj_ncombat.reduce_fortification = false; + obj_ncombat.reduce_power = false; +} + +static __inquisition_tyranid_org_on_enemy_casulties = function(){ + var _c_data = casualty_packet; + if (array_contains(["Termagaunt", "Hormagaunt"], _c_data.weapon) && (_c_data.casulties > 0)) { + data.captured_gaunt += _c_data.casulties; + } +} + +static __inquisition_tyranid_org_battle_final_message = function(){ + if (obj_ncombat.defeat || data.captured_gaunt == 0) { + exit; + } + var _gaunts = string_plural_count("Gaunt organism", data.captured_gaunt); + var _newline = $"{_gaunts} have been captured."; + obj_ncombat.combat_log.push(_newline, eMSG_COLOR.YELLOW); + +} + +static __inquisition_tyranid_org_battle_aftermath = function(){ + if (obj_ncombat.defeat|| data.captured_gaunt == 0){ + exit; + } + if (data.captured_gaunt > 1) { + var _text = "You have captured several Gaunt organisms. The Inquisitor is pleased with your work, though she notes that only one is needed- the rest are to be purged. It will be stored until it may be retrieved. The mission is a success."; + } else { + var _text = "You have captured a Gaunt organism- the Inquisitor is pleased with your work. The Tyranid will be stored until it may be retrieved. The mission is a success."; + } + scr_popup("Inquisition Mission Completed",_text, "inquisition", ""); + if (data.captured_gaunt > 0) { + delete_mission = true; + } +} + +static __hive_fleet_to_cult_init = function(){ + var _x1 = (random_range(room_width * 1.25, room_width * 2) * choose(-1, 1)) + system.x; + var _y1 = (random_range(room_height * 1.25, room_height * 2) * choose(-1, 1)) + system.y; + var _fleet = create_enemy_fleet(_x1, _y1, eFACTION.TYRANIDS); + _fleet.sprite_index = spr_fleet_tyranid; + _fleet.image_speed = 0; + + _fleet.capital_number = choose(7, 8, 9); + _fleet.frigate_number = round(random_range(6, 12)); + _fleet.escort_number = round(random_range(12, 27)); + + _fleet.image_index = floor(_fleet.capital_number + (_fleet.frigate_number / 2) + (_fleet.escort_number / 4)); + _fleet.image_alpha = 0; + + _fleet.action_x = system.x; + _fleet.action_y = system.y; + + _fleet.action_eta = timer; + _fleet.action = "move"; +} + +static __hive_fleet_to_cult_per_turn = function(){ + if (timer != 3 || scr_has_disadv("Psyker Intolerant")){ + exit; + } + var _has_head_lib = scr_role_count(obj_ini.player_role_data[eROLE.CHIEFLIBRARIAN].role, ""); + + var _head = get_department_head(eCHAPTER_DEPARTMENTS.LIB); + + if ((obj_controller.known[eFACTION.TYRANIDS] == 0) && (_has_head_lib != 0) && is_struct(_head)) { + scr_popup("Shadow in the Warp", $"Chief {_head.name_role()} reports a disturbance in the warp. He claims it is like a shadow.", "shadow", ""); + scr_event_log("red", $"Chief {obj_ini.player_role_data[eROLE.LIBRARIAN].role} reports a disturbance in the warp. He claims it is like a shadow."); + } + if ((obj_controller.known[eFACTION.TYRANIDS] == 0) && (_has_head_lib == 0)) { + for (var q = 0; q < array_length(obj_ini.TTRPG[0]); q++) { + var _unit = fetch_unit([0, q]); + if (_unit.has_role(eROLE.CHAPTERMASTER)) { + if (string_count("0", _unit.specials) > 0) { + scr_popup("Shadow in the Warp", "You are distracted and bothered by a nagging sensation in the warp. It feels as though a shadow descends upon your sector.", "shadow", ""); + scr_event_log("red", "You sense a disturbance in the warp. It feels something like a massive shadow."); + } + break; + } + } + } + + obj_controller.known[eFACTION.TYRANIDS] = 1; +} + +static __inquisition_purge_init = function(){ + var _text = "The Inquisition is trusting you with a special mission."; + if (data.mission_flavour == 1) { + _text += $" A number of high-ranking nobility on the {p_data.name()} are being difficult and harboring heretical thoughts. They are to be selectively purged within {timer} months. Can your chapter handle this mission?"; + } else if (data.mission_flavour == 2) { + _text += $" A powerful crime-lord on the {p_data.name()} is gaining an unacceptable amount of power and disrupting daily operations. They are to be selectively purged within {timer} months. Can your chapter handle this mission?"; + } else if (data.mission_flavour == 3) { + _text += $" The mutants of hive world {p_data.name()} are growing in numbers and ferocity, rising sporadically from the underhive. They are to be cleansed by promethium within {timer} months. Can your chapter handle this mission?"; + } + var _pop_data = { + mission: self, + options: __inquisition_mission_options(), + }; + scr_popup("Inquisition Mission", _text, "inquisition", _pop_data); +} + +static __inquisition_purge_accept = function(){ + var _text = "Inquisition Mission Accepted:" + if (data.purge_type == eDROP_TYPE.PURGEFIRE){ + _text += $" The mutants beneath {p_data.name()} must be cleansed by fire within {timer} months."; + } else { + _text += $" The nobles of {p_data.name()} must be selectively purged within {timer} months." + } + scr_event_log("", _text, system.name); +} + +static __inquisition_purge_on_purge = function(){ + switch (purge_data.action_type){ + case eDROP_TYPE.PURGESELECTIVE: + delete_mission = true; + + alter_disposition(eFACTION.INQUISITION, obj_controller.demanding ? choose(0, 0, 1) : 1); + + var _popup_text = "Your marines drop fast and hard, blowing through guards and mercenaries with minimal resistance. Before ten minutes have passed all your targets are executed."; + scr_event_log("", $"Inquisition Mission Completed: The unruly Nobles of {p_data.name()} have been purged."); + p_data.add_disposition(choose(1, 2, 3)); + scr_popup("Inquisition Mission Completed", _popup_text, "inquisition"); + break; + case eDROP_TYPE.PURGEFIRE: + delete_mission = true; + + alter_disposition(eFACTION.INQUISITION, obj_controller.demanding ? choose(0, 0, 1) : 1); + + var _popup_text = $"Your marines scour the under-hive of {p_data.name()}, spraying mutants down with promethium as they go. It takes several days but a sizeable dent is put in their numbers."; + scr_event_log("", $"Inquisition Mission Completed: The mutants of {p_data.name()} have been cleansed by promethium."); + p_data.add_disposition(choose(1, 2, 3)); + scr_popup("Inquisition Mission Completed", _popup_text, "inquisition"); + break; + } +} + +static __join_communion_init = function(){ + stage_id = "preliminary"; + data.applicant = "Governor"; +} +static __join_communion_feature_selected = function(){ + draw_data.mission_description = $"The governor of {p_data.name()} has Invited a delegate of your forces to take part in ceremony."; + draw_data.help = "This mission is not yet completed" +} + +static __governor_purge_enemies_init = function(){ + if (system.planets < 2){ + delete_mission = true; + exit; + } + var _planet = planet; + var _enemy = 0; + with (system){ + for (var i = 1; i <= planets; i++) { + if (i == _planet) { + continue; + } + if (p_owner[i] == eFACTION.IMPERIUM) { + _enemy = i; + break; + } + } + } + if (_enemy == 0){ + delete_mission = true; + exit; + } + data.target = _enemy; + stage_id = "preliminary"; + data.applicant = "Governor"; +} + +static __governor_purge_enemies_feature_selected = function(){ + draw_data.mission_description = $"The governor of {p_data.name()} has expressed his distaste of the neighbouring governance of {system.name} {data.target} he has expressed his views that they engage in heretical ways and harbor xenos enemies though in truth it is more likely that he simply wishes his political enemies disposed of, whatever the case his planet has great economic means and he has made bare his plans to compensate the emperors angels for their aid"; + draw_data.help = "This mission is not yet complete"; +} + +} + + diff --git a/scripts/PlanetProblem/PlanetProblem.yy b/scripts/PlanetProblem/PlanetProblem.yy new file mode 100644 index 0000000000..7469c69c2d --- /dev/null +++ b/scripts/PlanetProblem/PlanetProblem.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"v1", + "%Name":"PlanetProblem", + "isCompatibility":false, + "isDnD":false, + "name":"PlanetProblem", + "parent":{ + "name":"Scripts", + "path":"folders/Scripts.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/SystemProblem/SystemProblem.gml b/scripts/SystemProblem/SystemProblem.gml new file mode 100644 index 0000000000..37a35b6408 --- /dev/null +++ b/scripts/SystemProblem/SystemProblem.gml @@ -0,0 +1,113 @@ +/// @param {string} _name +/// @param {Asset.GMObject.obj_star} _system +/// @param {struct} _data +/// @param {Real} _timer +function SystemProblem(_name, _system, _data = {}, _timer = -1) : Problem(_name, _timer, _data) constructor{ +system = _system; + +//base only assigns members when data.members exists; default it here without clobbering that +if (!variable_struct_exists(self, "members")){ + members = []; +} + +zero_timer_checks = true; +per_turn_checks = true; + +//overrides Problem's base version — appends the stage suffix and skips __refresh_data/location_viewer +static __handle_triggered_mission_func = function(func){ + if (!is_undefined(func)){ + try { + func(); + } catch (_exception) { + ERROR_HANDLER.handle_exception(_exception); + } + } + if (timer == -1 || (delete_mission)){ + var _prob = -1; + for (var i = 0; i < array_length(system.problems); i++){ + if (system.problems[i] == self){ + _prob = i; + } + } + if (_prob > -1){ + array_delete(system.problems, _prob,1); + } + } +} + +static basic_turn_end = function(){ + if (system.storm <= 0){ + timer--; + } + if ((timer > -1) && per_turn_checks) { + var _func = find_func("per_turn"); + __handle_triggered_mission_func(_func); + } + if ((timer == 0) && zero_timer_checks && !delete_mission) { + var _func = find_func("resolve"); + __handle_triggered_mission_func(_func); + } +} + + +static find_func = function(trigger_string){ + var _func_string = find_func_ref(trigger_string); + if (struct_exists(self,_func_string)){ + return self[$ _func_string] + } + return undefined; +} + +static mark = function(colour){ + with (system){ + new_star_event_marker(colour) + } +} + +static __init = function(){ + var _func = find_func("init"); + if (!is_undefined(_func)){ + __handle_triggered_mission_func(_func); + } +} + +__init(); + +static __great_crusade_init = function(){ + //TODO decide the target/purpose of the crusade to create more variety and to help with post crusade rewards + var _nearest_player_fleet = has_data("nearest_player_fleet") ? data.nearest_player_fleet : instance_nearest(system.x, system.y, obj_p_fleet); + var _travel_leeway = 10; + if (_nearest_player_fleet.action == "move") { + _travel_leeway += _nearest_player_fleet.action_eta; + } + timer = get_viable_travel_time(_travel_leeway, _nearest_player_fleet.x, _nearest_player_fleet.y, system.x, system.y, _nearest_player_fleet, false); + scr_popup("Crusade", $"Fellow Astartes legions are preparing to embark on a Crusade to a nearby sector. Your forces are expected at {system.name}; {timer} months from now your ships there shall begin their journey.", "crusade", ""); + mark("green") + scr_event_log("", $"A Crusade is called; our forces are expected at {system.name} in {timer} months.", system.name); +} + +static __great_crusade_resolve = function() { + var _player_fleet = system.get_orbiting_player_fleet(); + + if (_player_fleet != noone) { + _player_fleet.add_problem("great_crusade",infinity, {}); + + scr_alert("green", "crusade", "Fleet embarks upon Crusade.", system.x, system.y); + scr_event_log("", "Fleet embarks upon Crusade."); + } else { + // hit loyalty here + alter_dispositions([[eFACTION.INQUISITION, -10], [eFACTION.IMPERIUM, -5]]); + var _string = $"No ships designated for Crusade."; + if (obj_controller.penitent == 1) { + obj_controller.penitent_current = 0; + _string += "Your penitence crusade has been lengthened for your failings"; + } + + scr_alert("red", "crusade", _string, system.x, system.y); + scr_loyalty("Refusing to Crusade", "+"); + scr_event_log("red", "No ships designated for Crusade."); + } + delete_mission = true; +} + +} \ No newline at end of file diff --git a/scripts/SystemProblem/SystemProblem.yy b/scripts/SystemProblem/SystemProblem.yy new file mode 100644 index 0000000000..21231b06ff --- /dev/null +++ b/scripts/SystemProblem/SystemProblem.yy @@ -0,0 +1,13 @@ +{ + "$GMScript":"v1", + "%Name":"SystemProblem", + "isCompatibility":false, + "isDnD":false, + "name":"SystemProblem", + "parent":{ + "name":"Constructors", + "path":"folders/Scripts/Constructors.yy", + }, + "resourceType":"GMScript", + "resourceVersion":"2.0", +} \ No newline at end of file diff --git a/scripts/globals/globals.gml b/scripts/globals/globals.gml index 51140787ff..021cda3333 100644 --- a/scripts/globals/globals.gml +++ b/scripts/globals/globals.gml @@ -135,14 +135,6 @@ global.xenos_factions = [ eFACTION.TYRANIDS, ]; -global.fleet_move_options = [ - "move", - "crusade1", - "crusade2", - "crusade3", - "mars_spelunk1", -]; - global.alliance_grades = [ "Hated", "Hostile", diff --git a/scripts/macros/macros.gml b/scripts/macros/macros.gml index 4ce6a2aa96..6a3ae40f16 100644 --- a/scripts/macros/macros.gml +++ b/scripts/macros/macros.gml @@ -10,6 +10,7 @@ #macro CM_RED_COLOR #bf4040 #macro COL_REQUISITION #2398F8 #macro COL_FORGE_POINTS #af5a00 +#macro PLANET_ARRAY_SIZE 9 // First candidate TTF used when a language needs CJK glyphs that the latin fonts lack. #macro STR_CJK_FALLBACK_FONT "fonts/simhei.ttf" diff --git a/scripts/scr_PlanetData/scr_PlanetData.gml b/scripts/scr_PlanetData/scr_PlanetData.gml index cc62a6a689..e961c62585 100644 --- a/scripts/scr_PlanetData/scr_PlanetData.gml +++ b/scripts/scr_PlanetData/scr_PlanetData.gml @@ -9,6 +9,34 @@ function PlanetData(_planet, _system) constructor { planet = _planet; system = _system; + static save_problems = function(){ + var _probs = []; + for (var i = 0; i < array_length(problems); i++){ + array_push(_probs, problems[i].save()); + } + return _probs; + } + static save = function(){ + var _planet_data = { + dispo: system.dispo[planet], + planet: system.planet[planet], + }; + var __var_names = variable_instance_get_names(system); + for (var n = 0; n < array_length(__var_names); n++) { + var _var_name = __var_names[n]; + if (!string_starts_with(_var_name, "p_")) { + continue; + } + var _val = system[$ _var_name][planet]; + if (_var_name == "p_problem"){ + _val = save_problems(); + } + variable_struct_set(_planet_data, _var_name, _val); + } + + return _planet_data; + } + static refresh_data = function() { features = system.p_feature[planet]; current_owner = system.p_owner[planet]; @@ -72,8 +100,6 @@ function PlanetData(_planet, _system) constructor { governor = system.p_governor[planet]; problems = system.p_problem[planet]; - problems_data = system.p_problem_other_data[planet]; - problem_timers = system.p_timer[planet]; deamons = system.p_demons[planet]; chaos_forces = system.p_chaos[planet]; @@ -615,15 +641,12 @@ function PlanetData(_planet, _system) constructor { } // Empire bonus, was 15 before // Check for industrial facilities - var fleet_buildable = (planet_type != "Dead" && planet_type != "Lava") || _has_warboss || _has_stronghold; - if (fleet_buildable && planet_forces[eFACTION.ORK] >= 4) { + var _fleet_buildable = (planet_type != "Dead" && planet_type != "Lava") || _has_warboss || _has_stronghold; + if (_fleet_buildable && planet_forces[eFACTION.ORK] >= 4) { // Used to not have Ice either - if (instance_exists(obj_p_fleet)) { - var ppp = instance_nearest(x, y, obj_p_fleet); - if ((point_distance(x, y, ppp.x, ppp.y) < 50) && (ppp.action == "")) { - exit; - } + if (system.has_orbiting_player_fleet()) { + exit; } if (planet_type == "Forge") { _rando -= 80; @@ -730,13 +753,6 @@ function PlanetData(_planet, _system) constructor { } }; - deamons = system.p_demons[planet]; - chaos_forces = system.p_chaos[planet]; - - requests_help = system.p_halp[planet]; - - corruption = system.p_heresy[planet]; - static alter_corruption = function(value) { alter_planet_corruption(value, planet, system); corruption = system.p_heresy[planet]; @@ -747,24 +763,13 @@ function PlanetData(_planet, _system) constructor { corruption = system.p_heresy[planet]; }; - is_heretic = system.p_hurssy[planet]; - - heretic_timer = system.p_hurssy_time[planet]; - - secret_corruption = system.p_heresy_secret[planet]; - - population_influences = system.p_influence[planet]; - - raided_this_turn = system.p_raided[planet]; - - governor = system.p_governor[planet]; - - problems = system.p_problem[planet]; - problems_data = system.p_problem_other_data[planet]; - problem_timers = system.p_timer[planet]; - static has_problem = function(problem) { - return has_problem_planet(planet, problem, system); + for (var i = 0; i < array_length(problems); i++){ + if (problems[i].p_id == problem){ + return true; + } + } + return false; }; static remove_problem = function(problem) { @@ -772,12 +777,36 @@ function PlanetData(_planet, _system) constructor { }; static find_problem = function(problem) { - return find_problem_planet(planet, problem, system); + for (var i = 0; i < array_length(problems); i++){ + if (problems[i].p_id == problem){ + return problems[i]; + } + } + return noone; }; - static add_problem = function(problem, timer, other_data = {}) { - return add_new_problem(planet, problem, timer, system, other_data); - }; + static new_problem = function(p_id, timer = -1, data = {}, register = true){ + var _prob = new PlanetProblem(p_id, timer, data, self); + if (register){ + register_problem(_prob) + } + return _prob; + } + + static register_problem = function(problem){ + array_push(system.p_problem[planet], problem); + problems = system.p_problem[planet]; + } + + + static problem_count_down = function (count_change = 1) { + for (var i = array_length(problems) -1; i >= 0; i--) { + var _problem = problems[i]; + _problem.basic_turn_end(); + } + } + + static problems_to_mission_log = method(self, generic_problems_to_mission_log); static name = function() { return planet_numeral_name(planet, system); @@ -1353,29 +1382,29 @@ function PlanetData(_planet, _system) constructor { draw_text(xx + 349, yy + 346, string_hash_to_newline(string(presence_text))); - var planet_displays = []; - var feat_count = array_length(features); - var upgrade_count = array_length(upgrades); + var _planet_displays = []; + var _feat_count = array_length(features); + var _upgrade_count = array_length(upgrades); var size = global.planet_size; - if (feat_count > 0) { - for (var i = 0; i < feat_count; i++) { + if (_feat_count > 0) { + for (var i = 0; i < _feat_count; i++) { var cur_feature = features[i]; try { if (cur_feature.planet_display != 0) { if (cur_feature.f_type == eP_FEATURES.GENE_STEALER_CULT) { if (!cur_feature.hiding) { - array_push(planet_displays, [cur_feature.planet_display, cur_feature]); + array_push(_planet_displays, [cur_feature.planet_display, cur_feature]); } } else if (cur_feature.player_hidden == 1) { - array_push(planet_displays, ["????", ""]); + array_push(_planet_displays, ["????", ""]); } else { - array_push(planet_displays, [cur_feature.planet_display, cur_feature]); + array_push(_planet_displays, [cur_feature.planet_display, cur_feature]); } if (cur_feature.f_type == eP_FEATURES.MONASTERY) { if (cur_feature.forge > 0) { - var forge = cur_feature.forge_data; - var size_string = localize("{0} Chapter Forge", [size[forge.size]]); - array_push(planet_displays, [size_string, forge]); + var _forge = cur_feature.forge_data; + var _size_string = localize("{0} Chapter Forge", [size[_forge.size]]); + array_push(_planet_displays, [_size_string, _forge]); } } } @@ -1385,49 +1414,40 @@ function PlanetData(_planet, _system) constructor { } } } - if (upgrade_count > 0) { - for (var i = 0; i < upgrade_count; i++) { + if (_upgrade_count > 0) { + for (var i = 0; i < _upgrade_count; i++) { var _upgrade = upgrades[i]; if (_upgrade.f_type == eP_FEATURES.SECRET_BASE) { if (_upgrade.forge > 0) { - var forge = _upgrade.forge_data; - var size_string = localize("{0} Chapter Forge", [size[forge.size]]); - array_push(planet_displays, [size_string, forge]); + var _forge = _upgrade.forge_data; + var _size_string = localize("{0} Chapter Forge", [size[_forge.size]]); + array_push(_planet_displays, [_size_string, _forge]); } } } } for (var i = 0; i < array_length(problems); i++) { - if (problems[i] == "") { - continue; - } - var problem_data = problems_data[i]; - if (struct_exists(problem_data, "stage")) { - if (problem_data.stage == "preliminary") { - var mission_string = localize("{0} Audience", [problem_data.applicant]); - problem_data.f_type = eP_FEATURES.MISSION; - problem_data.time = problem_timers[i]; - problem_data.problem = problems[i]; - problem_data.array_position = i; - array_push(planet_displays, [mission_string, problem_data]); - } - } - } - - var button_size; - var y_move = 0; - var button_colour; - for (var i = 0; i < array_length(planet_displays); i++) { - button_colour = c_green; - if (planet_displays[i][0] == "????") { - button_colour = c_red; - } - button_size = draw_unit_buttons([xx + 535, yy + 346 + y_move], planet_displays[i][0], [1, 1], button_colour,, fnt_40k_14b, 1); - y_move += button_size[3] - button_size[1]; - if (point_and_click(button_size)) { - if (planet_displays[i][0] != "????") { - obj_star_select.feature = new FeatureSelected(planet_displays[i][1], system, current_planet); + var _problem = problems[i]; + if (_problem.view_on_planet_screen()) { + var _mission_string = localize("{0} Audience", [_problem.data.applicant]); + array_push(_planet_displays, [_mission_string, _problem]); + } + } + + var _button_size; + var _y_move = 0; + var _button_colour; + for (var i = 0; i < array_length(_planet_displays); i++) { + _button_colour = c_green; + if (_planet_displays[i][0] == "????") { + _button_colour = c_red; + } + _button_size = draw_unit_buttons([xx + 535, yy + 346 + _y_move], _planet_displays[i][0], [1, 1], _button_colour,, fnt_40k_14b, 1); + _y_move += _button_size[3] - _button_size[1]; + if (point_and_click(_button_size)) { + if (_planet_displays[i][0] != "????") { + obj_star_select.feature = new FeatureSelected(_planet_displays[i][1], system, current_planet); } else { obj_star_select.feature = ""; } @@ -1524,9 +1544,9 @@ function PlanetData(_planet, _system) constructor { add_operatives(operation_data); //if there was an outstanding mission to provide the given garrison - var garrison_request = find_problem("provide_garrison"); - if (garrison_request > -1) { - init_garrison_mission(planet, system, garrison_request); + var _garrison_request = find_problem("provide_garrison"); + if (is_struct(_garrison_request)) { + _garrison_request.provide_garrison_on_garrison(); } instance_destroy(obj_star_select); }; @@ -1539,7 +1559,7 @@ function PlanetData(_planet, _system) constructor { if (garrisons.garrison_force) { garrisons.find_leader(); garrisons.garrison_disposition_change(true); - } + } }; static planet_selection_logic = function() { @@ -1576,20 +1596,6 @@ function PlanetData(_planet, _system) constructor { // 135 ; SPECIAL PLANET CRAP HERE // Recon Stuff - - if (has_problem("recon")) { - var arti = instance_create(system.x, system.y, obj_temp7); // Unloading / artifact crap - - arti.num = planet; - arti.alarm[0] = 1; - arti.loc = obj_controller.selecting_location; - arti.managing = obj_controller.managing; - arti.type = "recon"; - - with (arti) { - setup_planet_mission_group(); - } - } if (!instance_exists(obj_ground_mission)) { check_for_artifact_grab_mission(); } @@ -2059,7 +2065,7 @@ function PlanetData(_planet, _system) constructor { static init_war_of_succession = function() { add_feature(eP_FEATURES.SUCCESSION_WAR); - add_problem("succession", irandom(6) + 4); + new_problem("succession", irandom(6) + 4); set_player_disposition(-5000); scr_popup(localize("War of Succession"), localize("The planetary governor of {0} has died. Several subordinates and other parties each claim to be the true heir and successor- war has erupted across the planet as a result. Heresy thrives in chaos.", [name()]), "succession", ""); @@ -2069,23 +2075,4 @@ function PlanetData(_planet, _system) constructor { _star_alert.col = "red"; scr_event_log("red", localize("War of Succession on {0}", [name()])); }; - - static init_fallen_marines = function() { - var _eta = scr_mission_eta(system.x, system.y, 1); - - var assigned_problem = add_problem("fallen", _eta); - - if (!assigned_problem) { - LOGGER.error("RE: Hunt the Fallen, coulnd't assign a problem to the planet"); - return; - } - - var _text = localize("Sources indicate one of the Fallen may be upon {0}. We have {1} months to send out a strike team and scour the planet. Any longer and any Fallen that might be there will have escaped.", [name(), _eta]); - scr_popup(localize("Hunt the Fallen"), _text, "fallen", ""); - scr_event_log("", localize("Sources indicate one of the Fallen may be upon {0}. We have {1} months to investigate.", [name(), _eta])); - var star_alert = create_alert(); - star_alert.image_alpha = 1; - star_alert.image_speed = 1; - star_alert.col = "purple"; - }; } diff --git a/scripts/scr_UnitGroup/scr_UnitGroup.gml b/scripts/scr_UnitGroup/scr_UnitGroup.gml index 35f56efdd1..ef86aa86ac 100644 --- a/scripts/scr_UnitGroup/scr_UnitGroup.gml +++ b/scripts/scr_UnitGroup/scr_UnitGroup.gml @@ -107,7 +107,7 @@ function UnitGroup(units = []) constructor { var _squad = fetch_squad(_squads[s]); var _squad_units = _replica.get_from({squad: _squads[s]}, true, true); - if (_squad_units.number() < array_length(_squad.members)) { + if (_squad_units.number() < array_length(_squad.get_members())) { _squad_units.move_to_company(company, false, false); continue; } else { @@ -503,7 +503,7 @@ function UnitGroup(units = []) constructor { continue; } var _squad = fetch_squad(_unit.squad); - var _members_count = array_length(_squad.members); + var _members_count = array_length(_squad.get_members()); var _conditions = { squad: _unit.squad, max_wanted: _members_count, @@ -967,6 +967,11 @@ enum eMISSION_SELECT_TYPE { } function group_selection(group, selection_data = {}) { + if (instance_exists(obj_star_select)){ + if (is_struct(obj_star_select.feature)){ + obj_star_select.feature.destroy = true; + } + } try { var _unit, s, unit_location; obj_controller.selection_data = selection_data; diff --git a/scripts/scr_after_combat/scr_after_combat.gml b/scripts/scr_after_combat/scr_after_combat.gml index 7d830c833c..8b35482f1f 100644 --- a/scripts/scr_after_combat/scr_after_combat.gml +++ b/scripts/scr_after_combat/scr_after_combat.gml @@ -151,7 +151,7 @@ function check_for_plasma_bomb_and_tomb(unit) { var _star = obj_ncombat.battle_object; var _planet = obj_ncombat.battle_id; var _necron_strength = _star.p_necrons[_planet]; - if (unit.gear() == "Plasma Bomb" && !string_count("mech_tomb2", obj_ncombat.battle_special)) { + if (unit.gear() == "Plasma Bomb" && obj_ncombat.battle_special != "mech_tomb") { if (obj_ncombat.enemy == eFACTION.NECRONS && awake_tomb_world(_star.p_feature[_planet])) { if (((_necron_strength - 2) < 3 && obj_ncombat.dropping) || (_necron_strength - 1) < 3) { obj_ncombat.plasma_bomb += 1; diff --git a/scripts/scr_chaos_alliance_test/scr_chaos_alliance_test.gml b/scripts/scr_chaos_alliance_test/scr_chaos_alliance_test.gml index 4f38439a66..d027aaab6c 100644 --- a/scripts/scr_chaos_alliance_test/scr_chaos_alliance_test.gml +++ b/scripts/scr_chaos_alliance_test/scr_chaos_alliance_test.gml @@ -93,24 +93,9 @@ function scr_chaos_alliance_test() { diplo_text = "[Error: No WL10 planet feature found.]"; } if (instance_exists(that_star)) { - var meeeting_arranged = false; - if (result == "success_trap") { - meeeting_arranged = add_new_problem(that_planet, "meeting_trap", 36, that_star); - } else { - meeeting_arranged = add_new_problem(that_planet, "meeting", 36, that_star); - } - if (meeeting_arranged) { - var rando, new_event; - rando = choose(1, 2); - if (rando == 1) { - diplo_text += "A proposal that needs further consideration and some negotiation. Meet me at " + string(that_title) + " and we shall resolve this."; - } - if (rando == 2) { - diplo_text += "Interesting. I shall be at " + string(that_title) + " and, if you are sincere, you will come to me and we can take this proposal to its logical conclusion."; - } - scr_event_log("", "Chaos Lord " + string(obj_controller.faction_leader[eFACTION.CHAOS]) + " agrees to meet with you on " + string(that_title) + " to discuss an alliance."); - new_star_event_marker("purple"); - } + var _meeting_arranged = false; + var _p_data = that_star.get_planet_data(that_planet); + _p_data.new_problem(result == "success_trap" ? "meeting_trap" : "meeting", 36); } } if (result == "fail") { diff --git a/scripts/scr_cheatcode/scr_cheatcode.gml b/scripts/scr_cheatcode/scr_cheatcode.gml index 51cf9b2930..25da7efdd3 100644 --- a/scripts/scr_cheatcode/scr_cheatcode.gml +++ b/scripts/scr_cheatcode/scr_cheatcode.gml @@ -128,7 +128,7 @@ function scr_cheatcode(argument0) { } with (obj_star) { for (var i = 1; i <= planets; i++) { - var existing_problem = false; //has_any_problem_planet(i); + var existing_problem = false; if (!existing_problem) { if (p_owner[i] == eFACTION.IMPERIUM) { LOGGER.debug("mission"); @@ -159,24 +159,12 @@ function scr_cheatcode(argument0) { case "planet": scr_inquisition_mission(eEVENT.INQUISITION_PLANET); break; - case "spyrer": - scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.SPYRER); - break; case "artifact": scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.ARTIFACT); break; case "inquisitor": scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.INQUISITOR); break; - case "purge": - scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.PURGE); - break; - case "tomb_world": - scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.TOMB_WORLD); - break; - case "tyranid_organism": - scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.TYRANID_ORGANISM); - break; case "demon": scr_inquisition_mission(eEVENT.INQUISITION_MISSION, eINQUISITION_MISSION.DEMON_WORLD); break; @@ -225,8 +213,6 @@ function scr_cheatcode(argument0) { new_inquisitor_inspection(); } else if (cheat_arguments[0] == "slaughtersong") { create_starship_event(); - } else if (cheat_arguments[0] == "fallen") { - event_fallen(); } else if (cheat_arguments[0] == "surfremove") { var _star_id = scr_random_find(0, true, "", ""); add_event({duration: 2, e_id: "governor_assassination", variant: 2, system: _star_id.name, planet: irandom_range(1, _star_id.planets)}); @@ -396,6 +382,38 @@ function scr_cheatcode(argument0) { } } +/// @self Asset.GMObject.obj_star_select +function draw_system_debug(){ + add_draw_return_values(); + debug_slate.inside_method = function() { + debug_slate.title = localize("DEBUG"); + draw_set_color(c_gray); + var xx = debug_slate.XX; + var yy = debug_slate.YY; + var _base_y = yy + 50; + var _base_x = xx + 75; + var _keys = global.planet_problem_keys; + var _star_missions = [ + "great_crusade", + ] + _base_y += 2; + draw_set_font(fnt_40k_12); + for (var i = 0; i < array_length(_star_missions); i++) { + var _y = _base_y + i * 20; + var _c = draw_unit_buttons([_base_x, _base_y], _star_missions[i]); + if (scr_hit(_c[0], _c[1],_c[2],_c[3])) { + tooltip_draw(mission_name_key(_star_missions[i])); + if (mouse_button_clicked()) { + target.add_problem(_star_missions[i], 3).timer = 3; + } + } + _base_y += _c[3] - _c[1]; + } + }; + debug_slate.draw(350 + main_data_slate.width, 160, 0.6, 0.6); + pop_draw_return_values(); +} + /// @self Asset.GMObject.obj_star_select function draw_planet_debug_options() { try { @@ -471,11 +489,11 @@ function draw_planet_debug_features() { }, ]; - var base_y = 220; - base_y += 2; + var _base_y = 220; + _base_y += 2; for (var i = 0; i < array_length(_addable_features); i++) { - var _y = base_y + i * 20; + var _y = _base_y + i * 20; var _feat = _addable_features[i]; draw_text(38, _y, _feat.name); if (point_and_click([38, _y, 337, _y + 20])) { @@ -487,42 +505,30 @@ function draw_planet_debug_features() { /// @self Asset.GMObject.obj_star_select function draw_planet_debug_problems() { - var base_y = 220; + var _base_y = 220; var _keys = global.planet_problem_keys; - base_y += 2; + _base_y += 2; for (var i = 0; i < array_length(_keys); i++) { - var _y = base_y + i * 20; + var _y = _base_y + i * 20; draw_text(38, _y, _keys[i]); if (scr_hit(38, _y, 337, _y + 20)) { tooltip_draw(mission_name_key(_keys[i])); if (mouse_button_clicked()) { var _p_data = obj_star_select.p_data; + _p_data.new_problem(_keys[i], 3); + /* switch (_keys[i]) { case "inquisitor": mission_inquistion_hunt_inquisitor(target.id); break; - case "necron": - mission_inquisition_tomb_world(target.id); - break; - case "mech_raider": - spawn_mechanicus_mission("mech_raider"); - break; - case "mech_mars": - spawn_mechanicus_mission("mech_mars"); - break; - case "mech_bionics": - spawn_mechanicus_mission("mech_bionics"); - break; case "succession": _p_data.init_war_of_succession(); break; - case "fallen": - _p_data.init_fallen_marines(); - break; default: scr_popup("error", "no specific debug action created please consider helping to make one", ""); break; } + */ } } } @@ -532,9 +538,9 @@ function draw_planet_debug_problems() { function draw_planet_debug_forces() { add_draw_return_values(); var current_planet = obj_controller.selecting_planet; - var base_y = 220; + var _base_y = 220; // Close window if clicked outside - if (!scr_hit([36, base_y, 337, base_y + 281]) && mouse_button_clicked()) { + if (!scr_hit([36, _base_y, 337, _base_y + 281]) && mouse_button_clicked()) { debug = 0; exit; } @@ -562,9 +568,9 @@ function draw_planet_debug_forces() { ]; // Loop through each faction row - base_y += 2; + _base_y += 2; for (var i = 0; i < array_length(faction_names); i++) { - var _y = base_y + i * 20; + var _y = _base_y + i * 20; var key = faction_keys[i]; // Draw faction name and value diff --git a/scripts/scr_choose_weighted/scr_choose_weighted.gml b/scripts/scr_choose_weighted/scr_choose_weighted.gml index fd5e6795ac..e0afe575ba 100644 --- a/scripts/scr_choose_weighted/scr_choose_weighted.gml +++ b/scripts/scr_choose_weighted/scr_choose_weighted.gml @@ -48,7 +48,3 @@ function choose_weighted_range(_choices) { } } } - -function choose_array(choice_array) { - return choice_array[irandom(array_length(choice_array) - 1)]; -} diff --git a/scripts/scr_company_order/scr_company_order.gml b/scripts/scr_company_order/scr_company_order.gml index 3db891da0c..e6a711840b 100644 --- a/scripts/scr_company_order/scr_company_order.gml +++ b/scripts/scr_company_order/scr_company_order.gml @@ -76,7 +76,7 @@ function scr_company_order(company) { for (var i = 0; i < array_length(_squad_ids); i++) { var _squad = fetch_squad(_squad_ids[i]); if (_squad.base_company != co) { - if (!bool(array_length(_squad.members))) { + if (!bool(array_length(_squad.get_members()))) { array_push(_empty_squads, _squad); } continue; diff --git a/scripts/scr_company_struct/scr_company_struct.gml b/scripts/scr_company_struct/scr_company_struct.gml index 0bde49fc2a..ae878a91b8 100644 --- a/scripts/scr_company_struct/scr_company_struct.gml +++ b/scripts/scr_company_struct/scr_company_struct.gml @@ -53,7 +53,7 @@ function CompanyStruct(comp) constructor { continue; } _search_squad.update_fulfilment(); - if (bool(array_length(_search_squad.members))) { + if (bool(array_length(_search_squad.get_members()))) { array_push(company_squads, _search_squad); } } @@ -81,7 +81,7 @@ function CompanyStruct(comp) constructor { var _search_squad = _unit.get_squad(); _search_squad.update_fulfilment(); - if (array_length(_search_squad.members) > 0) { + if (array_length(_search_squad.get_members()) > 0) { array_push(company_squads, _search_squad); array_push(_squad_ids, _unit.squad); } @@ -222,7 +222,7 @@ function CompanyStruct(comp) constructor { if (!is_struct(_cur_squad)) { return; } - var _member_count = array_length(_cur_squad.members); + var _member_count = array_length(_cur_squad.get_members()); var _reset_surface = false; var _member = _member_count > 0 ? _cur_squad.fetch_member(0) : undefined; var _first_uid = is_struct(_member) ? _member.uid : undefined; @@ -235,11 +235,7 @@ function CompanyStruct(comp) constructor { for (var i = 0; i < _member_count; i++) { _member = _cur_squad.fetch_member(i); if (_reset_surface || i >= array_length(squad_draw_surfaces)) { - if (is_struct(_member)) { - array_push(squad_draw_surfaces, [_member.uid, _member.draw_unit_image()]); - } else { - array_push(squad_draw_surfaces, [undefined, undefined]); - } + array_push(squad_draw_surfaces, [_member.uid, _member.draw_unit_image()]); } var _mem_draw_data = squad_draw_surfaces[i]; if (!is_array(_mem_draw_data) || !is_struct(_member)) { diff --git a/scripts/scr_controller_helpers/scr_controller_helpers.gml b/scripts/scr_controller_helpers/scr_controller_helpers.gml index 44494d6d5f..74b6e924ab 100644 --- a/scripts/scr_controller_helpers/scr_controller_helpers.gml +++ b/scripts/scr_controller_helpers/scr_controller_helpers.gml @@ -470,27 +470,27 @@ function scr_end_turn() { turn += 1; with (obj_star) { - present_fleet[20] = 0; + navy_enemy_fleet_enroute = false; } with (obj_p_fleet) { if ((action == "move") && (obj_controller.faction_status[eFACTION.IMPERIUM] == "War")) { - var him = instance_nearest(action_x, action_y, obj_star); - if (point_distance(action_x, action_y, him.x, him.y) < 10) { - him.present_fleet[20] = 1; - } + var _him = instance_nearest(action_x, action_y, obj_star); + _him.navy_enemy_fleet_enroute = (point_distance(action_x, action_y, _him.x, _him.y) == 0); } } with (obj_en_fleet) { if ((action == "move") && (owner > 5)) { - var him = instance_nearest(action_x, action_y, obj_star); - if (point_distance(action_x, action_y, him.x, him.y) < 10) { - him.present_fleet[20] = 1; - } + var _him = instance_nearest(action_x, action_y, obj_star); + _him.navy_enemy_fleet_enroute = (point_distance(action_x, action_y, _him.x, _him.y) == 0); } } if (instance_exists(obj_p_fleet)) { - obj_p_fleet.alarm[1] = 1; + wait_and_execute(1, function(){ + with(obj_p_fleet){ + player_fleet_end_turn(); + } + }); } if (instance_exists(obj_en_fleet)) { obj_en_fleet.alarm[1] = 1; diff --git a/scripts/scr_crusade/scr_crusade.gml b/scripts/scr_crusade/scr_crusade.gml index 5db9b0a878..a6023d33d6 100644 --- a/scripts/scr_crusade/scr_crusade.gml +++ b/scripts/scr_crusade/scr_crusade.gml @@ -1,238 +1,15 @@ -/// @self Id.Instance.obj_fleet -function scr_crusade() { - // Executed to kill the fuck out of the player's marines - // Think it is ran in the obj_p_fleet object when arriving back from crusade - - var _unit; - var co = 0, i = 0, apoth = 0, death_determination = 0, death_determination_2 = 0, roll3 = 0, type = "", artifacts = 0, clean = 0; - seed = 0; - marines_lost = 0; - var heroics_strings = []; - - //index 1: death_determine 1 //index 2: death_determine 2 /index 3: apoth_recovery - //index 3 exp_gains irandom + static - var death_sets = { - normal: [ - 80, - 90, - 40, - [ - 5, - 10, - ], - ], - hard: [ - 60, - 80, - 30, - [ - 20, - 20, - ], - ], - brutal: [ - 20, - 65, - 20, - [ - 40, - 20, - ], - ], - }; - - death_determination = floor(random(100)) + 1; - roll3 = irandom(99) + 1; - - if (death_determination <= 50) { - type = "normal"; - artifacts = choose(0, 0, 0, 0, 0, 1); - } else if (death_determination > 50 && death_determination <= 80) { - type = "hard"; - artifacts = choose(0, 0, 1); - } else if (death_determination > 80) { - type = "brutal"; - artifacts = choose(1, 2, 3); - } - - var death_data = death_sets[$ type]; - - for (co = 0; co <= obj_ini.companies; co++) { - clean[co] = 0; - } - var total_ship_id = array_concat(capital_num, frigate_num, escort_num); - - for (co = 0; co <= obj_ini.companies; co++) { - for (i = 0; i < company_length(co); i++) { - dead = false; - _unit = fetch_unit([co, i]); - if (!is_struct(_unit)) { - continue; - } - if (_unit.ship_location == -1) { - continue; - } - if (array_contains(total_ship_id, _unit.ship_location)) { - death_determination = floor(random(100)) + 1; - //specialist trait greatly reduces death risk - //TODO figure out how to quantify and present these risks so the player knows to protect dudes with trait - if (_unit.has_trait("very_hard_to_kill")) { - death_determination -= 20; - } - death_determination_2 = death_determination; - death_determination -= _unit.experience / 2; - - //more generalised trait bonus mainly linked to chapter advantage of same name - if (_unit.has_trait("slow_and_purposeful")) { - death_determination -= 10; - } - - var _dead = false; - if (death_determination > death_data[0] || death_determination_2 > death_data[1]) { - _dead = true; - if (_unit.role() == obj_ini.player_role_data[eROLE.CAPTAIN].role) { - if (irandom(20) < _unit.luck) { - _dead = false; - } else { - if (irandom(100) < _unit.weapon_skill) { - var heroic_deed = choose("holding a breach in imperial defenses allowing allied forces to regroup,", "slaying the enemy leader in glorious combat, while victorious he ultimately succumbed to his wounds,", "leading an imortant boarding mission,"); - //TODO figure out a blance in reward for captains or high rnaking death on crusade - //adds dynamacism as itt creates reward for the potential loss of men and talent during crusades - //var consolations = ["ship", "req",""] - //var consolation_prize = irandom(2) - var heroic_death = $"{_unit.full_title()} died {heroic_deed} {_unit.name()} dies a hero of the {global.chapter_name}"; - array_push(heroics_strings, heroic_death); - } - } - } else if (_unit.role() == obj_ini.player_role_data[eROLE.ANCIENT].role || _unit.role() == obj_ini.player_role_data[eROLE.CHAPTERMASTER].role) { - _dead = false; - } - } - if (_dead) { - var man_size = 0; - obj_ini.ship_carrying[_unit.ship_location] -= _unit.get_unit_size(); - if (_unit.IsSpecialist(SPECIALISTS_STANDARD, true)) { - obj_controller.command--; - } else { - obj_controller.marines--; - } - - clean[co] = 1; - marines_lost++; - _unit.kill(false, true); - } else { - if (_unit.IsSpecialist(SPECIALISTS_APOTHECARIES) && (_unit.gear() == "Narthecium")) { - apoth++; - } - _unit.add_exp(irandom(death_data[3][0]) + death_data[3][1]); - - if (irandom(99) == 1 && irandom(20) < _unit.luck) { - var heroic_deed = choose("still_standing", "lone_survivor", "beast_slayer"); - _unit.add_trait(heroic_deed); - array_push(heroics_strings, string(global.trait_list[$ heroic_deed].flavour_text, _unit.full_title())); - } - } - } - } - } - - if (obj_ini.doomed == 0) { - if (apoth > 0) { - seed = min(seed, apoth * death_data[2]); - } - if (apoth == 0) { - seed = floor(seed * 0.2); - } - obj_controller.gene_seed += seed; - } - - with (obj_ini) { - for (i = 0; i <= 10; i++) { - scr_company_order(i); - } - } - - if (roll3 <= 10) { - artifacts += 1; - } - if (artifacts > 0) { - repeat (artifacts) { - if (obj_ini.fleet_type == ePLAYER_BASE.HOME_WORLD) { - scr_add_artifact("random", "", 4, obj_ini.home_name, -1); - } - if (obj_ini.fleet_type != ePLAYER_BASE.HOME_WORLD) { - scr_add_artifact("random", "", 4, obj_ini.ship[0], 0); - } - } - } - - var tixt = "Your ships have returned from the Crusade. "; - if (type == "normal") { - tixt += "The combat was as could be expected- "; - } - if (type == "hard") { - tixt += "The combat was fairly grueling- "; - } - if (type == "brutal") { - tixt += "The combat was absolutely brutal- your marines were the first into the fray, and as a result "; - } - - tixt += string(marines_lost) + " of your battle brothers fell in combat."; - - if (obj_ini.doomed == 0) { - if ((apoth > 0) && (seed > 0)) { - tixt += " The " + string(apoth) + " surviving " + string(obj_ini.player_role_data[eROLE.APOTHECARY].role) + " were able to recover " + string(seed) + " Gene-Seed."; - } - if ((apoth == 0) && (seed > 0)) { - tixt += " You had no able-bodied " + string(obj_ini.player_role_data[eROLE.APOTHECARY].role) + ", or all of them perished in the Crusade. Foreign Apothecaries were able to recover " + string(seed) + " of your Gene-Seed."; - } - } - if (obj_ini.doomed == 1) { - tixt += " Due to fatal mutations in your marines none of the fallen Gene-Seed was recoverable."; - } - - if (artifacts > 0) { - tixt += " " + string(artifacts) + " Artifacts were granted to your Chapter or looted."; - } - if ((roll3 <= 10) && (artifacts > 1)) { - tixt += " One of them were given as a bonus for exceptional valor."; - } - - if (array_length(heroics_strings) == 1) { - tixt += " A heroic deed was recorded"; - } else if (array_length(heroics_strings) > 1) { - tixt += " Several deeds were recorded"; - } - // title / text / image / speshul - scr_popup("Crusade Results", tixt, "crusade", ""); - for (i = 0; i < array_length(heroics_strings); i++) { - scr_popup("Heroic Deed", heroics_strings[i], "crusade", ""); - } -} - //TODO never place the star out of reach of a player fleet, eiter increase allowed response time or find nearer planet function launch_crusade() { - var star_id = scr_random_find(2, true, "", ""); - if (star_id == noone) { + var _star_id = scr_random_find(2, true, "", ""); + if (_star_id == noone) { LOGGER.error("RE: Crusade, couldn't find a star for the crusade"); return false; } else { - //TODO decide the target/purpose of the crusade to create more variety and to help with post crusade rewards - var _nearest_player_fleet = get_nearest_player_fleet(star_id.x, star_id.y); + var _nearest_player_fleet = get_nearest_player_fleet(_star_id.x, _star_id.y); if (_nearest_player_fleet == noone) { return false; } - var travel_leeway = 10; - if (_nearest_player_fleet.action == "move") { - travel_leeway += _nearest_player_fleet.action_eta; - } - var _eta = get_viable_travel_time(travel_leeway, _nearest_player_fleet.x, _nearest_player_fleet.y, star_id.x, star_id.y, _nearest_player_fleet, false); - scr_popup("Crusade", $"Fellow Astartes legions are preparing to embark on a Crusade to a nearby sector. Your forces are expected at {star_id.name}; {_eta} months from now your ships there shall begin their journey.", "crusade", ""); - var star_alert = instance_create(star_id.x + 16, star_id.y - 24, obj_star_event); - star_alert.image_alpha = 1; - star_alert.image_speed = 1; - scr_event_log("", $"A Crusade is called; our forces are expected at {star_id.name} in {_eta} months.", star_id.name); - assigned_crusade = add_new_problem(irandom_range(1, star_id.planets), "great_crusade", _eta, star_id); + _star_id.add_problem("great_crusade", {nearest_player_fleet:_nearest_player_fleet}) return true; } } diff --git a/scripts/scr_destroy_planet/scr_destroy_planet.gml b/scripts/scr_destroy_planet/scr_destroy_planet.gml index 2a67d8c8c1..deec228c02 100644 --- a/scripts/scr_destroy_planet/scr_destroy_planet.gml +++ b/scripts/scr_destroy_planet/scr_destroy_planet.gml @@ -164,9 +164,7 @@ function scr_destroy_planet(destruction_method) { p_sisters[baid] = 0; p_necrons[baid] = 0; // - p_problem[baid] = array_create(8, ""); - p_timer[baid] = array_create(8, 0); - p_problem_other_data[baid] = array_create(8, {}); + p_problem[baid] = []; } pip.text += ", scouring all life across the planet. It has been rendered a barren, lifeless chunk of rock."; diff --git a/scripts/scr_diplomacy_helpers/scr_diplomacy_helpers.gml b/scripts/scr_diplomacy_helpers/scr_diplomacy_helpers.gml index 6e2d8155f8..7b8a52319a 100644 --- a/scripts/scr_diplomacy_helpers/scr_diplomacy_helpers.gml +++ b/scripts/scr_diplomacy_helpers/scr_diplomacy_helpers.gml @@ -328,7 +328,7 @@ function scr_emmisary_diplomacy_routes() { var _squad_ids = get_squad_ids(); for (var i = 0; i < array_length(_squad_ids); i++) { kill_squad = fetch_squad(_squad_ids[i]); - if (kill_squad.type == "tactical_squad" && array_length(kill_squad.members) > 4) { + if (kill_squad.type == "tactical_squad" && array_length(kill_squad.get_members()) > 4) { var chapter_master = fetch_unit([0, 1]); chapter_master.add_trait("blood_for_blood"); chapter_master.edit_corruption(20); diff --git a/scripts/scr_draw_planet_features/scr_draw_planet_features.gml b/scripts/scr_draw_planet_features/scr_draw_planet_features.gml index 91eaedfffb..1391878dda 100644 --- a/scripts/scr_draw_planet_features/scr_draw_planet_features.gml +++ b/scripts/scr_draw_planet_features/scr_draw_planet_features.gml @@ -72,7 +72,6 @@ function FeatureSelected(_feature, _system, _planet) constructor { obj_controller.unit_profile = false; obj_controller.view_squad = false; group_selection(techs, {purpose: "Forge Assignment", purpose_code: "forge_assignment", number: worker_capacity, system: planet_data.system, feature: feature, planet: planet_data.planet, selections: []}); - destroy = true; } //TODO move over to using the draw button object ot streamline this var next_position = [ @@ -216,81 +215,12 @@ function FeatureSelected(_feature, _system, _planet) constructor { } break; case eP_FEATURES.MISSION: - var mission_description = $""; - var planet_name = planet_numeral_name(planet_data.planet, obj_star_select.target); - var button_text = "none"; - var button_function = "none"; - var help = "none"; - switch (feature.problem) { - case "provide_garrison": - var reason; - if (feature.reason == "importance") {} - mission_description = $"The governor of {planet_name} has requested a force of marines might stay behind following your departure.\n\n\n assign a squad to garrison to initiate mission, The garrison leeader will need to be capable of conducting himself in a diplomatic manner in order for the garrison duration to be a success"; - - break; - case "join_communion": - mission_description = $"The governor of {planet_name} has Invited a delegate of your forces to take part in ceremony."; - break; - case "hunt_beast": - mission_description = $"The governor of {planet_name} has bemoaned the raiding of huge beasts on the fringes of the planets largest city, the numbers have swelled recently and are causing huge damage to the planets small economy. You could send a force to intervene, it would provide a fine test of metal for any that partake."; - help = "This is a good opportunity to provide experience and training, having at least one marine with experience in such matters would be advisable"; - button_text = "Send Hunters"; - button_function = function() { - var dudes = collect_role_group("all", obj_star_select.target.name); - group_selection(dudes, {purpose: "Beast Hunt", purpose_code: feature.problem, number: 3, system: planet_data.system, feature: obj_star_select.feature, planet: planet_data.planet, array_slot: feature.array_position, selections: []}); - destroy = true; - }; - break; - case "protect_raiders": - mission_description = $"The governor of {planet_name} has sent many requests to the sector commander for help with defending against xenos raids on the populace of the planet, the reports seem to suggest the xenos in question are in fact dark eldar."; - help = "Set a squad to ambush"; - button_text = "Send Squad"; - _button_tooltip = "milage may vary on playability of this mission progress at your own risk"; - button_function = function() { - var dudes = collect_role_group("all", obj_star_select.target.name); - group_selection(dudes, {purpose: "Select Squad for Ambush", purpose_code: feature.problem, number: 1, system: planet_data.system, feature: obj_star_select.feature, planet: planet_data.planet, array_slot: feature.array_position, select_type: eMISSION_SELECT_TYPE.SQUADS, selections: []}); - destroy = true; - }; - break; - case "train_forces": - mission_description = $"The governor of {planet_name} fears the planet will not hold in the case of major incursion, it has not seen war in some time and he fears the ineptitude of the commanders available, he asks for aid in planning a thorough plan for defense and schedule of works for a period of at least 6 months."; - help = $"A task best suited to the more knowledgable or wise of your Commanders"; - button_text = "Assign Officer"; - button_function = function() { - var dudes = collect_role_group(SPECIALISTS_CAPTAIN_CANDIDATES, obj_star_select.target.name); - group_selection(dudes, {purpose: "Select Officer", purpose_code: feature.problem, number: 1, system: planet_data.system, feature: obj_star_select.feature, planet: planet_data.planet, array_slot: feature.array_position, selections: []}); - destroy = true; - }; - break; - case "Purge_enemies": - mission_description = $"The governor of {planet_name} has expressed his distaste of the neighboring governance of {target.name} {feature.target} he has expressed his views that they engage in heretical ways and harbor xenos enemies though in truth it is more likely that he simply wishes his political enemies disposed of, whatever the case his planet has great economic means and he has made bare his plans to compensate the emperors angels for their aid"; - break; + feature.draw_data = { + x1 :xx, + y1 : yy, + w : area_width, } - draw_text_transformed(xx + (area_width / 2), yy + 5, mission_name_key(feature.problem), 2, 2, 0); - draw_set_halign(fa_left); - draw_set_color(c_gray); - draw_text_ext(xx + 10, yy + 40, mission_description, -1, area_width - 20); - var text_body_height = string_height_ext(string_hash_to_newline(mission_description), -1, area_width - 20); - if (help != "none") { - draw_text_ext(xx + 10, yy + 40 + text_body_height + 10, help, -1, area_width - 20); - text_body_height += string_height_ext(string_hash_to_newline(mission_description), -1, area_width - 20) + 10; - } - - if (button_text != "none") { - var _button = draw_unit_buttons([xx + ((area_width / 2) - (string_width(button_text) / 2)), yy + 40 + text_body_height + 10], button_text); - if (_button_tooltip != "" && scr_hit(_button)) { - tooltip_draw(_button_tooltip); - } - if (point_and_click(_button)) { - if (is_callable(button_function)) { - button_function(); - destroy = true; - } else { - tooltip_draw("no implemented function"); - } - } - } - break; + feature.planet_draw_feature_selected(); } if (generic) { draw_text_ext_transformed(xx + (area_width / 2), yy + 5, title, -1, area_width - 20, 2, 2, 0); diff --git a/scripts/scr_drop_select_function/scr_drop_select_function.gml b/scripts/scr_drop_select_function/scr_drop_select_function.gml index eeadcd9840..5adce517df 100644 --- a/scripts/scr_drop_select_function/scr_drop_select_function.gml +++ b/scripts/scr_drop_select_function/scr_drop_select_function.gml @@ -231,6 +231,7 @@ function drop_select_unit_selection() { btn_attack.draw(); if (btn_attack.clicked()) { if (purge == 0) { + var _p_data = p_target.get_planet_data(planet_number); if (formation_current < 0 || formation_current >= array_length(formation_possible)) { exit; } @@ -271,22 +272,20 @@ function drop_select_unit_selection() { if (obj_ncombat.battle_object.space_hulk == 1) { obj_ncombat.battle_special = "space_hulk"; } - if ((planet_feature_bool(_planet, eP_FEATURES.WARLORD6) == 1) && (obj_ncombat.enemy == eFACTION.ELDAR) && (obj_controller.faction_defeated[6] == 0)) { + if ((_p_data.has_feature(eP_FEATURES.WARLORD6)) && (obj_ncombat.enemy == eFACTION.ELDAR) && (obj_controller.faction_defeated[6] == 0)) { obj_ncombat.leader = 1; } - if (obj_ncombat.enemy == eFACTION.ORK && planet_feature_bool(_planet, eP_FEATURES.ORKWARBOSS)) { + if (obj_ncombat.enemy == eFACTION.ORK && _p_data.has_feature(eP_FEATURES.ORKWARBOSS)) { obj_ncombat.leader = 1; obj_ncombat.ork_warboss = _planet[search_planet_features(_planet, eP_FEATURES.ORKWARBOSS)[0]]; } - if ((obj_ncombat.enemy == eFACTION.TYRANIDS) && (obj_ncombat.battle_object.space_hulk == 0)) { - if (has_problem_planet(planet_number, "tyranid_org", p_target)) { - obj_ncombat.battle_special = "tyranid_org"; - } + for (var i=0; i= 2) { + var _p_data = p_target.get_planet_data(planet_number); draw_set_halign(fa_center); draw_set_font(fnt_40k_30b); @@ -431,13 +429,13 @@ function drop_select_draw() { "Selective Purging {0}", "Assassinate Governor ({0})", ]; - var _planet_string = planet_numeral_name(planet_number, p_target); + var _planet_string = _p_data.name(); draw_text_transformed(x2 + 14, y2 + 12, string(_purge_strings[purge - 2], _planet_string), 0.6, 0.6, 0); // Disposition here var pp = planet_number; - var succession = has_problem_planet(pp, "succession", p_target); + var succession = _p_data.has_problem("succession"); if (((p_target.dispo[pp] >= 0) && (p_target.p_owner[pp] <= eFACTION.ECCLESIARCHY) && (p_target.p_population[pp] > 0)) && (!succession)) { var wack = 0; @@ -501,6 +499,7 @@ function collect_local_units() { purge_d = ship_max[500]; if (purge == 1) { + var _p_data = p_target.get_planet_data(planet_number); if (sh_target != noone) { max_ships = sh_target.capital_number + sh_target.frigate_number + sh_target.escort_number; @@ -581,7 +580,7 @@ function collect_local_units() { var pp = planet_number; purge_d = p_target.p_type[pp] != "Dead"; - if (has_problem_planet(pp, "succession", p_target)) { + if (_p_data.has_problem("succession")) { purge_d = 0; } 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 d9847cc0e5..6d80f9259a 100644 --- a/scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml +++ b/scripts/scr_enemy_ai_d/scr_enemy_ai_d.gml @@ -1,16 +1,8 @@ /// @self Asset.GMObject.obj_star function scr_enemy_ai_d() { - if (x < -15000) { + while (x < -15000){ x += 20000; - y += 20000; - } - if (x < -15000) { - x += 20000; - y += 20000; - } - if (x < -15000) { - x += 20000; - y += 20000; + y += 20000; } // Planetary problems here @@ -21,10 +13,6 @@ function scr_enemy_ai_d() { } var wob = 0; - var fallen = find_problem_planet(i, "fallen"); - if (fallen > -1 && storm - 1 > 0) { - p_timer[i][fallen]++; - } // Requesting help here if (((p_halp[i] == 1) || (p_halp[i] == 1.1)) && (p_population[i] > 0) && (p_owner[i] <= eFACTION.ECCLESIARCHY)) { @@ -84,39 +72,16 @@ function scr_enemy_ai_d() { } } } + for (var i = 0; i < array_length(problems); i++){ + problems[i].basic_turn_end(); + } for (var i = 1; i <= planets; i++) { - problem_count_down(i); - if (planet_problemless(i)) { - continue; - } var _pdata = get_planet_data(i); - with (_pdata) { - problem_end_turn_checks(); - } - - mechanicus_missions_end_turn(i); - - var _beast_hunt = has_problem_planet_and_time(i, "hunt_beast", 0); - if (_beast_hunt > -1) { - try { - complete_beast_hunt_mission(i, _beast_hunt); - } catch (_exception) { - ERROR_HANDLER.handle_exception(_exception); - } - } - - var train_forces = has_problem_planet_and_time(i, "train_forces", 0); - if (train_forces > -1) { - try { - complete_train_forces_mission(i, train_forces); - } catch (_exception) { - ERROR_HANDLER.handle_exception(_exception); - } - } + _pdata.problem_count_down(i); if (((p_tyranids[i] == 3) || (p_tyranids[i] == 4)) && (p_population[i] > 0)) { - if (!has_problem_planet(i, "Hive Fleet")) { + if (!_pdata.has_problem("hive_fleet_to_cult")) { var roll = irandom_range(100, 300); var cont = 0; @@ -127,66 +92,17 @@ function scr_enemy_ai_d() { cont = 1; } - var firstest = open_problem_slot(i); - if (cont == 1 && firstest > -1) { - p_problem[i][firstest] = "Hive Fleet"; - p_timer[i][firstest] = irandom_range(60, 120) + 1; - p_timer[i][firstest] += irandom_range(80, 120) + 1; - - var xx = (random_range(room_width * 1.25, room_width * 2) * choose(-1, 1)) + x; - var yy = (random_range(room_height * 1.25, room_height * 2) * choose(-1, 1)) + y; - var fleet = create_enemy_fleet(xx, yy, eFACTION.TYRANIDS); - fleet.sprite_index = spr_fleet_tyranid; - fleet.image_speed = 0; - - fleet.capital_number = choose(7, 8, 9); - fleet.frigate_number = round(random_range(6, 12)); - fleet.escort_number = round(random_range(12, 27)); - - fleet.image_index = floor(fleet.capital_number + (fleet.frigate_number / 2) + (fleet.escort_number / 4)); - fleet.image_alpha = 0; - - fleet.action_x = x; - fleet.action_y = y; - - fleet.action_eta = p_timer[i][firstest]; - fleet.action = "move"; - } - } - } - - if (has_problem_planet_and_time(i, "Hive Fleet", 3) > -1) { - var woop = scr_role_count(obj_ini.player_role_data[eROLE.CHIEFLIBRARIAN].role, ""); - var yep = !scr_has_disadv("Psyker Intolerant"); - - var _head = get_department_head(eCHAPTER_DEPARTMENTS.LIB); - - if ((obj_controller.known[eFACTION.TYRANIDS] == 0) && (woop != 0) && yep && is_struct(_head)) { - scr_popup("Shadow in the Warp", $"Chief {_head.name_role()} reports a disturbance in the warp. He claims it is like a shadow.", "shadow", ""); - scr_event_log("red", $"Chief {obj_ini.player_role_data[eROLE.LIBRARIAN].role} reports a disturbance in the warp. He claims it is like a shadow."); - } - if ((obj_controller.known[eFACTION.TYRANIDS] == 0) && (woop == 0) && yep) { - for (var q = 0; q < array_length(obj_ini.TTRPG[0]); q++) { - var _unit = fetch_unit([0, q]); - if (_unit.role() == obj_ini.player_role_data[eROLE.CHAPTERMASTER].role) { - if (string_count("0", _unit.specials) > 0) { - scr_popup("Shadow in the Warp", "You are distracted and bothered by a nagging sensation in the warp. It feels as though a shadow descends upon your sector.", "shadow", ""); - scr_event_log("red", "You sense a disturbance in the warp. It feels something like a massive shadow."); - } - break; - } + if (cont == 1) { + _pdata.new_problem("hive_fleet_to_cult", irandom_range(60, 120) + irandom_range(80, 120)); } } - - i = 50; - obj_controller.known[eFACTION.TYRANIDS] = 1; } } if (storm > 0) { storm -= 1; if (storm == 0) { - var tr = "Warp Storms over " + string(name) + " dissipate."; + var tr = $"Warp Storms over {name} dissipate."; scr_alert("green", "Warp", tr, x, y); scr_event_log("green", tr); } @@ -194,27 +110,13 @@ function scr_enemy_ai_d() { if (trader > 0) { trader -= 1; if (trader == 0) { - var tr = "Rogue Trader fleet departs from " + string(name) + "."; + var tr = $"Rogue Trader fleet departs from {name}."; scr_alert("green", "Warp", tr, x, y); scr_event_log("green", tr); } } // Colonists Colonize - - with (obj_star) { - if (x < -10000) { - x += 20000; - y += 20000; - } - } - with (obj_star) { - if (x < -10000) { - x += 20000; - y += 20000; - } - } - var already_enroute = false; var cur_star = id; with (obj_en_fleet) { diff --git a/scripts/scr_enemy_ai_e/scr_enemy_ai_e.gml b/scripts/scr_enemy_ai_e/scr_enemy_ai_e.gml index 60020548ae..3aee617381 100644 --- a/scripts/scr_enemy_ai_e/scr_enemy_ai_e.gml +++ b/scripts/scr_enemy_ai_e/scr_enemy_ai_e.gml @@ -513,6 +513,7 @@ function scr_enemy_ai_e() { var chaos_meeting = 0; for (var run = 1; run <= planets; run++) { + var _p_data = get_planet_data(run); var forces_list = []; var force_count = 0; if (p_player[run] > 0 && struct_exists(obj_controller.location_viewer.garrison_log, name)) { @@ -522,51 +523,12 @@ function scr_enemy_ai_e() { if (p_player[run] > 0 && force_count > 0) { if (p_player[run] > 0) { - if (has_problem_planet(run, "meeting")) { + if (_p_data.has_problem( "meeting")) { chaos_meeting = run; - } else if (has_problem_planet(run, "meeting_trap")) { + } else if (_p_data.has_problem( "meeting_trap")) { chaos_meeting = run + 0.1; } } - if (has_problem_planet(run, "spyrer")) { - if (p_player[run] > 20) { - var tixt = "The Spyrer on " + planet_numeral_name(run, id) + " seems to have vanished, presumably gone into hiding."; - scr_popup("Spyrer Rampage", tixt, "spyrer", ""); - } else if (p_player[run] <= 20) { - obj_turn_end.battles += 1; - obj_turn_end.battle[obj_turn_end.battles] = 1; - obj_turn_end.battle_world[obj_turn_end.battles] = run; - obj_turn_end.battle_opponent[obj_turn_end.battles] = 30; - obj_turn_end.battle_location[obj_turn_end.battles] = name; - obj_turn_end.battle_object[obj_turn_end.battles] = id; - obj_turn_end.battle_special[obj_turn_end.battles] = "spyrer"; - } - } - - if ((p_player[run] > 0) && has_problem_planet(run, "fallen")) { - if (choose(true, false)) { - obj_turn_end.battles += 1; - obj_turn_end.battle[obj_turn_end.battles] = 1; - obj_turn_end.battle_world[obj_turn_end.battles] = run; - obj_turn_end.battle_opponent[obj_turn_end.battles] = 10; - obj_turn_end.battle_location[obj_turn_end.battles] = name; - obj_turn_end.battle_object[obj_turn_end.battles] = id; - if (choose(true, false)) { - obj_turn_end.battle_special[obj_turn_end.battles] = "fallen1"; - } else { - obj_turn_end.battle_special[obj_turn_end.battles] = "fallen2"; - } - } else { - if (remove_planet_problem(run, "fallen")) { - var tixt = "Your marines have scoured " + planet_numeral_name(run, id) + " in search of the Fallen. Despite their best efforts, and meticulous searching, none have been found. It appears as though the information was faulty or out of date."; - scr_popup("Hunt the Fallen", tixt, "fallen", ""); - scr_event_log("", $"Mission Successful: No Fallen located upon {planet_numeral_name(run, id)}"); - } - } - } - } - if (p_player[run] > 0 && has_problem_planet(run, "necron")) { - setup_necron_tomb_raid(run); } if ((p_player[run] > 0) && (force_count > 0)) { for (var force = 2; force < 14; force++) { @@ -612,13 +574,13 @@ function scr_enemy_ai_e() { } break; case 10: - pause = has_problem_planet(run, "meeting") || has_problem_planet(run, "meeting_trap"); + pause = _p_data.has_problem( "meeting") || _p_data.has_problem( "meeting_trap"); if (p_guardsmen[run] + p_pdf[run] == 0 && p_player[run] > 0 && p_chaos[run] > 0 && !pause && obj_controller.faction_status[10] == "War") { battle_opponent = 10; } break; case 11: - pause = has_problem_planet(run, "meeting") || has_problem_planet(run, "meeting_trap"); + pause = _p_data.has_problem( "meeting") || _p_data.has_problem( "meeting_trap"); if (p_guardsmen[run] + p_pdf[run] == 0 && p_player[run] > 0 && p_traitors[run] > 0 && !pause && obj_controller.faction_status[10] == "War") { battle_opponent = 11; } @@ -786,7 +748,7 @@ function scr_enemy_ai_e() { } for (var i = 1; i <= planets; i++) { - var existing_problem = has_any_problem_planet(i); + var existing_problem = bool(array_length(p_problem[i])); if (!existing_problem) { if (!irandom(50) && p_owner[i] == eFACTION.IMPERIUM) { if (p_owner[i] == eFACTION.IMPERIUM) { diff --git a/scripts/scr_event_code/scr_event_code.gml b/scripts/scr_event_code/scr_event_code.gml index 2386994d3c..477dce570b 100644 --- a/scripts/scr_event_code/scr_event_code.gml +++ b/scripts/scr_event_code/scr_event_code.gml @@ -89,13 +89,13 @@ function event_end_turn_action() { // Starts chaos invasion if (_event.e_id == "chaos_invasion") { var xx = 0, yy = 0, flee = 0, dirr = 0; - var star_id = scr_random_find(1, true, "", ""); - if (star_id != noone) { - scr_event_log("purple", $"Chaos Fleets exit the warp near the {star_id.name} system.", star_id.name); + var _star_id = scr_random_find(1, true, "", ""); + if (_star_id != noone) { + scr_event_log("purple", $"Chaos Fleets exit the warp near the {_star_id.name} system.", _star_id.name); for (var j = 0; j < 4; j++) { dirr += irandom_range(50, 100); - xx = star_id.x + lengthdir_x(72, dirr); - yy = star_id.y + lengthdir_y(72, dirr); + xx = _star_id.x + lengthdir_x(72, dirr); + yy = _star_id.y + lengthdir_y(72, dirr); flee = create_enemy_fleet(xx, yy, eFACTION.CHAOS); flee.sprite_index = spr_fleet_chaos; flee.image_index = 4; @@ -104,8 +104,8 @@ function event_end_turn_action() { flee.escort_number = choose(4, 5, 6); flee.cargo_data.chaos = true; obj_controller.chaos_fleets += 1; - flee.action_x = star_id.x; - flee.action_y = star_id.y; + flee.action_x = _star_id.x; + flee.action_y = _star_id.y; with (flee) { set_fleet_movement(); } diff --git a/scripts/scr_flavor/scr_flavor.gml b/scripts/scr_flavor/scr_flavor.gml index dd6e558d13..04b851e343 100644 --- a/scripts/scr_flavor/scr_flavor.gml +++ b/scripts/scr_flavor/scr_flavor.gml @@ -517,9 +517,6 @@ function scr_flavor(id_of_attacking_weapons, target, target_type, number_of_shot } } else if (weapon_name == "Webber") { flavoured = true; - if (((target_name == "Termagaunt") || (target_name == "Hormagaunt")) && (casulties > 0)) { - obj_ncombat.captured_gaunt += casulties; - } if ((target.dudes_num[targeh] == 1) && (casulties == 0)) { attack_message = $"{number_of_shots} {weapon_name} spray ooze on the {target_name} but fail to immobilize it."; } diff --git a/scripts/scr_fleet_advisor/scr_fleet_advisor.gml b/scripts/scr_fleet_advisor/scr_fleet_advisor.gml index 136af8d50d..2bdd6ffde0 100644 --- a/scripts/scr_fleet_advisor/scr_fleet_advisor.gml +++ b/scripts/scr_fleet_advisor/scr_fleet_advisor.gml @@ -236,7 +236,7 @@ function scr_fleet_advisor() { tooltip_draw(localize("Carrying ({0}): {1}", [cn.temp[118], cn.temp[119]])); if (_goto_button.click()) { with (obj_p_fleet) { - var _fleet_ships = fleet_full_ship_array(); + var _fleet_ships = full_ship_array(); if (array_contains(_fleet_ships, i)) { cn.x = x; cn.y = y; diff --git a/scripts/scr_fleet_functions/scr_fleet_functions.gml b/scripts/scr_fleet_functions/scr_fleet_functions.gml index 5335ebd13e..552aeafbe6 100644 --- a/scripts/scr_fleet_functions/scr_fleet_functions.gml +++ b/scripts/scr_fleet_functions/scr_fleet_functions.gml @@ -13,6 +13,19 @@ function distribute_strength_to_fleet(strength, fleet) { } } } +/// @{Id.Instance.obj_p_fleet} +function fleet_is_orbiting(){ + orbiting = noone; + if (fleet == "move"){ + return orbiting; + } + var _star = instance_nearest(x, y, obj_star); + if (_star.x == x && _star.y == y){ + orbiting = _star.id + return orbiting; + } + return noone; +} /// @self Id.Instance.obj_en_fleet|Id.Instance.obj_p_fleet /// @param {Id.Instance.obj_en_fleet|Id.Instance.obj_p_fleet} fleet @@ -231,7 +244,7 @@ function set_fleet_movement(_fastest_route = true, _new_action = "move", _minimu /// @param {Struct} unit function load_unit_to_fleet(fleet, unit) { var loaded = false; - var all_ships = fleet_full_ship_array(fleet); + var all_ships = fleet.full_ship_array(); for (var i = 0; i < array_length(all_ships); i++) { var ship_ident = all_ships[i]; @@ -526,39 +539,7 @@ function object_distance(obj_1, obj_2) { return point_distance(obj_1.x, obj_1.y, obj_2.x, obj_2.y); } -/// @function scr_orbiting_player_fleet(system) -/// @description Returns the ID of the nearest player fleet orbiting the given system or star. -/// @param {Id.Instance.obj_star} system -/// The system instance or identifier to check. If `noone`, the function checks the calling star instance. -/// @returns {Id.Instance.obj_p_fleet} The instance ID of the orbiting player fleet, or -1 if none is found. -/// -/// @example -/// ```gml -/// var fleet_id = scr_orbiting_player_fleet(); -/// if (fleet_id != -1) { -/// LOGGER.debug("Fleet orbiting star: " + string(fleet_id)); -/// } -/// ``` -function scr_orbiting_player_fleet(system = noone) { - if (system == noone && !is_struct(self) && object_index == obj_star) { - var _fleet = instance_nearest(x, y, obj_p_fleet); - if (object_distance(self, _fleet) > 0) { - return -1; - } else { - return _fleet.id; - } - } else if (system != noone) { - try { - with (system) { - return scr_orbiting_player_fleet(); - } - } catch (_exception) { - ERROR_HANDLER.handle_exception(_exception); - } - } - return -1; -} function get_orbiting_fleets(faction, system = noone) { var _fleets = []; @@ -677,7 +658,7 @@ function fleet_star_draw_offsets() { } //TODO further split this shite up -/// @self Asset.GMObject.obj_en_fleet|Asset.GMObject.obj_p_fleet +/// @self Asset.GMObject.obj_en_fleet function fleet_arrival_logic() { var _dest_star = instance_nearest(action_x, action_y, obj_star); x = _dest_star.x; @@ -1047,7 +1028,7 @@ function fleet_arrival_logic() { } } - var kay = 0, temp5 = 0, temp6 = 0, temp7 = 0; + var kay = 0, temp5 = 0, temp6 = 0, _final_star = 0; var _nearest_star = instance_nearest(x, y, obj_star); @@ -1076,23 +1057,23 @@ function fleet_arrival_logic() { if (kay == 50) { temp5 = x + choose(random(300), random(300) * -1); temp6 = y + choose(random(300), random(300) * -1); - temp7 = instance_nearest(temp5, temp6, obj_star); + _final_star = instance_nearest(temp5, temp6, obj_star); - if ((owner == eFACTION.ORK) && (temp7.owner != eFACTION.ORK) && (temp7.planets > 0) && (temp7.image_alpha >= 1)) { + if ((owner == eFACTION.ORK) && (_final_star.owner != eFACTION.ORK) && (_final_star.planets > 0) && (_final_star.image_alpha >= 1)) { kay = 55; } - if ((owner == eFACTION.TAU) && (temp7.owner != eFACTION.TAU) && (temp7.planets > 0) && (temp7.image_alpha >= 1)) { + if ((owner == eFACTION.TAU) && (_final_star.owner != eFACTION.TAU) && (_final_star.planets > 0) && (_final_star.image_alpha >= 1)) { kay = 55; } - if ((owner == eFACTION.CHAOS) && (temp7.owner != eFACTION.CHAOS) && (temp7.planets > 0) && (temp7.image_alpha >= 1)) { + if ((owner == eFACTION.CHAOS) && (_final_star.owner != eFACTION.CHAOS) && (_final_star.planets > 0) && (_final_star.image_alpha >= 1)) { kay = 55; } } } - if ((kay == 55) && instance_exists(temp7)) { - action_x = temp7.x; - action_y = temp7.y; + if ((kay == 55) && instance_exists(_final_star)) { + action_x = _final_star.x; + action_y = _final_star.y; set_fleet_movement(); } @@ -1341,6 +1322,15 @@ function fleet_register_at_star(_fleet, _star) { if (_faction == eFACTION.PLAYER && _star.vision == 0) { _star.vision = 1; } + + if (_faction != eFACTION.PLAYER){ + if (obj_controller.known[_faction] == 0){ + var _p_fleet = _star.get_orbiting_player_fleet(); + if (_p_fleet != noone){ + obj_controller.known[_faction] = 1; + } + } + } } /// @desc Unregisters a fleet from its orbiting star (if there is one), clears orbiting and decrements present_fleet. @@ -1396,22 +1386,6 @@ function fleet_register_at_nearest_star(_fleet, _max_distance = undefined) { return noone; } -/// @desc Creates a new player fleet, registering at the nearest star if within 50px. -/// @param {Real} _x -/// @param {Real} _y -/// @param {Array} _ships Optional array of ship IDs to add to the fleet -/// @returns {Id.Instance.obj_p_fleet} -function create_player_fleet(_x, _y, _ships = []) { - var _fleet = instance_create(_x, _y, obj_p_fleet); - _fleet.owner = eFACTION.PLAYER; - fleet_register_at_nearest_star(_fleet); - - for (var _i = 0; _i < array_length(_ships); _i++) { - add_ship_to_fleet(_ships[_i], _fleet); - } - - return _fleet; -} /// @desc Creates a new enemy fleet, registering at the nearest star if within 50px. /// @param {Real} _x diff --git a/scripts/scr_garrison/scr_garrison.gml b/scripts/scr_garrison/scr_garrison.gml index ab7805f1d3..453030a3ff 100644 --- a/scripts/scr_garrison/scr_garrison.gml +++ b/scripts/scr_garrison/scr_garrison.gml @@ -47,7 +47,7 @@ function GarrisonForce(system, planet, type = "garrison") constructor { static evaluate_operative_squad = function(operative_squad) { //marine garrison on planet var _squad = fetch_squad(operative_squad.reference); - if (array_length(_squad.members) > 0) { + if (array_length(_squad.get_members()) > 0) { array_push(garrison_squads, _squad); total_garrison += array_length(_squad.members); garrison_force = true; diff --git a/scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml b/scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml index 9c26be7962..77ee0d481c 100644 --- a/scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml +++ b/scripts/scr_imperial_navy_functions/scr_imperial_navy_functions.gml @@ -7,7 +7,7 @@ function navy_orbiting_planet_end_turn_action() { if (trade_goods == "") { ///basicically if there is a player fleet enroute for this star and the player is at war with the navy it will trigger ///meaning the navy fleet is going to sit and wait fot the player to arrive - if (orbiting.present_fleet[20] > 0) { + if (orbiting.navy_enemy_fleet_enroute) { end_sequence_finished = true; } } diff --git a/scripts/scr_ini_ship_cleanup/scr_ini_ship_cleanup.gml b/scripts/scr_ini_ship_cleanup/scr_ini_ship_cleanup.gml index d6eba64b59..54e3a6771b 100644 --- a/scripts/scr_ini_ship_cleanup/scr_ini_ship_cleanup.gml +++ b/scripts/scr_ini_ship_cleanup/scr_ini_ship_cleanup.gml @@ -40,7 +40,7 @@ function scr_kill_ship(index) { } if (_ship_fleet != noone) { delete_ship_from_fleet(index, _ship_fleet); - _available_ships = fleet_full_ship_array(_ship_fleet); + _available_ships = _ship_fleet.full_ship_array(); } _units_on_ship = array_shuffle(_units_on_ship); for (var i = 0; i < array_length(_available_ships); i++) { diff --git a/scripts/scr_inquisition_inspection/scr_inquisition_inspection.gml b/scripts/scr_inquisition_inspection/scr_inquisition_inspection.gml index 1ba8ea076a..c26d953135 100644 --- a/scripts/scr_inquisition_inspection/scr_inquisition_inspection.gml +++ b/scripts/scr_inquisition_inspection/scr_inquisition_inspection.gml @@ -26,7 +26,7 @@ function check_for_next_inquisitor_inspection() { if (_player_fleets == 1) { //can't inspect if fleet not in room //can't innspect if on other non negotiable action e.g crusading - _inspec = in_room(_player_fleet) && !fleet_engaged(_player_fleet); + _inspec = in_room(_player_fleet) && !_player_fleet.beyond_engagement; } else if (_player_fleets == 0) { _inspec = false; } @@ -551,7 +551,7 @@ function inquisition_inspection_loyalty(inspection_type) { var player_inspection_fleet = instance_nearest(obj_en_fleet.x, obj_en_fleet.y, obj_p_fleet); _inspect_results.star = instance_nearest(player_inspection_fleet.x, player_inspection_fleet.y, obj_star); - _inspect_results.ships = fleet_full_ship_array(player_inspection_fleet); + _inspect_results.ships = player_inspection_fleet.full_ship_array(); _inspect_results.collect_inspection_units(); @@ -569,7 +569,7 @@ function inquisition_inspection_loyalty(inspection_type) { } var ca, ia; - var player_ships = fleet_full_ship_array(player_inspection_fleet); + var player_ships = player_inspection_fleet.full_ship_array(); var _search_units = collect_role_group("all", ["", 0, player_ships]); _inspect_results.inquisitor_inspect_units(_search_units); diff --git a/scripts/scr_inquisition_mission/scr_inquisition_mission.gml b/scripts/scr_inquisition_mission/scr_inquisition_mission.gml index b94e760450..0b3cdeb75c 100644 --- a/scripts/scr_inquisition_mission/scr_inquisition_mission.gml +++ b/scripts/scr_inquisition_mission/scr_inquisition_mission.gml @@ -83,7 +83,7 @@ function scr_inquisition_mission(event, forced_mission = eINQUISITION_MISSION.RA var chosen_mission = forced_mission; if (chosen_mission == eINQUISITION_MISSION.RANDOM) { - chosen_mission = choose_array(inquisition_missions); + chosen_mission = array_random_element(inquisition_missions); } switch (chosen_mission) { case eINQUISITION_MISSION.PURGE: @@ -99,36 +99,43 @@ function scr_inquisition_mission(event, forced_mission = eINQUISITION_MISSION.RA mission_inquisition_artifact(); break; case eINQUISITION_MISSION.TOMB_WORLD: - mission_inquisition_tomb_world(necron_tomb_worlds); + mission_inquisition_necron_world(necron_tomb_worlds); break; case eINQUISITION_MISSION.TYRANID_ORGANISM: - mission_inquisition_tyranid_organism(tyranid_org_worlds); + LOGGER.info("RE: Gaunt Capture"); + var _star = array_random_element(tyranid_org_worlds); + var planet = -1; + for (var i = 1; i <= _star.planets; i++) { + if (_star.p_tyranids[i] > 4) { + planet = i; + break; + } + } + + var _eta = scr_mission_eta(_star.x, _star.y, 1); + _eta = min(max(_eta, 6), 50); + + _star.get_planet_data(planet).new_problem("inquisition_tyranid_org", _eta); break; case eINQUISITION_MISSION.ETHEREAL: mission_inquisition_ethereal(); break; case eINQUISITION_MISSION.DEMON_WORLD: - mission_inquisition_demon_world(demon_worlds); + var _star = array_random_element(demon_worlds); + var _planet = -1; + for (var i = 1; i <= _star.planets; i++) { + if (_star.p_demons[i] > 1) { + _planet = i; + break; + } + } + var _eta = scr_mission_eta(_star.x, _star.y, 25); + _star.get_planet_data(_planet).new_problem("inquisition_demon_world", _eta) break; } } } -function mission_inquisition_demon_world(demon_worlds) { - var _star = choose_array(demon_worlds); - var planet = -1; - for (var i = 1; i <= _star.planets; i++) { - if (_star.p_demons[i] > 1) { - planet = i; - break; - } - } - var eta = scr_mission_eta(_star.x, _star.y, 25); - var text = $"The Inquisitor is trusting you with a special mission. The planet {string(_star.name)} {scr_roman(planet)}"; - text += $" has been uncovered as a Demon World. The taint of chaos must be eradicated from this system. Can your chapter handle this mission?"; - scr_popup("Inquisition Mission", text, "inquisition", $"demon_world|{string(_star.name)}|{string(planet)}|{string(eta + 1)}|"); -} - function mission_inquisition_ethereal() { LOGGER.info("RE: Ethereal Capture"); var stars = scr_get_stars(); @@ -152,33 +159,14 @@ function mission_inquisition_ethereal() { break; } } - var eta = scr_mission_eta(_star.x, _star.y, 1); - eta = min(max(eta, 12), 50); + var _eta = scr_mission_eta(_star.x, _star.y, 1); + _eta = min(max(_eta, 12), 50); var text = $"An Inquisitor is trusting you with a special mission."; - text += $"They require that you capture a Tau Ethereal from the planet {string(_star.name)} {scr_roman(planet)} for research purposes. You have {string(eta)} months to locate and capture one. Can your chapter handle this mission?"; - scr_popup("Inquisition Mission", text, "inquisition", $"ethereal|{string(_star.name)}|{string(planet)}|{string(eta + 1)}|"); + text += $"They require that you capture a Tau Ethereal from the planet {string(_star.name)} {scr_roman(planet)} for research purposes. You have {string(_eta)} months to locate and capture one. Can your chapter handle this mission?"; + scr_popup("Inquisition Mission", text, "inquisition", $"ethereal|{string(_star.name)}|{string(planet)}|{string(_eta + 1)}|"); } -function mission_inquisition_tyranid_organism(worlds) { - LOGGER.info("RE: Gaunt Capture"); - var _star = choose_array(worlds); - var planet = -1; - for (var i = 1; i <= _star.planets; i++) { - if (_star.p_tyranids[i] > 4) { - planet = i; - break; - } - } - - var eta = scr_mission_eta(_star.x, _star.y, 1); - eta = min(max(eta, 6), 50); - - var text = $"An Inquisitor is trusting you with a special mission. The planet {string(_star.name)} {scr_roman(planet)}"; - text += " is ripe with Tyranid organisms. They require that you capture one of the Gaunt species for research purposes. Can your chapter handle this mission?"; - scr_popup("Inquisition Mission", text, "inquisition", $"tyranid_org|{string(_star.name)}|{string(planet)}|{string(eta + 1)}|"); -} - -function mission_inquisition_tomb_world(tomb_worlds) { +function mission_inquisition_necron_world(tomb_worlds) { LOGGER.info("RE: Necron Tomb Bombing"); var _star = noone; if (is_array(tomb_worlds)) { @@ -194,43 +182,21 @@ function mission_inquisition_tomb_world(tomb_worlds) { array_push(_star.p_feature[planet], new NewPlanetFeature(eP_FEATURES.NECRON_TOMB)); } - var eta = scr_mission_eta(_star.x, _star.y, 1); - if (global.cheat_debug) { - LOGGER.debug("mission popup"); - } - var _options = [ - { - str1: "Accept", - choice_func: init_mission_inquisition_tomb_world, - }, - { - str1: "Refuse", - choice_func: popup_default_close, - }, - ]; - var _pop_data = { - system: _star.name, - planet: planet, - estimate: eta, - mission: "necron", - options: _options, - }; - - var text = $"The Inquisition is trusting you with a special mission. They have reason to suspect the Necron Tomb on planet {string(_star.name)} {scr_roman(planet)}"; - - text += $" may become active. You are to send a small group of marines to plant a bomb deep inside, within {string(eta)} months. Can your chapter handle this mission?"; + var _eta = scr_mission_eta(_star.x, _star.y, 1); - scr_popup("Inquisition Mission", text, "inquisition", _pop_data); + var _p_data = _star.get_planet_data(planet); + _p_data.new_problem("inquisition_tomb", _eta, {}); } /// @self Asset.GMObject.obj_popup -function init_mission_inquisition_tomb_world() { - mission_star = find_star_by_name(pop_data.system); - if (mission_star == noone) { +function init_mission_inquisition_necron_world() { + var _mission_star = find_star_by_name(pop_data.system); + var _p_data = _mission_star.get_planet_data(pop_data.planet); + if (_mission_star == noone) { popup_default_close(); exit; } - scr_event_log("", $"Inquisition Mission Accepted: {global.chapter_name} have been given a Bomb to seal the Necron Tomb on {mission_star.name} {scr_roman(pop_data.planet)}.", mission_star.name); + scr_event_log("", $"Inquisition Mission Accepted: {global.chapter_name} have been given a Bomb to seal the Necron Tomb on {_p_data.name()}.", _mission_star.name); image = "necron_cave"; title = "New Equipment"; @@ -239,7 +205,7 @@ function init_mission_inquisition_tomb_world() { text = $"{global.chapter_name} have been provided with 1x Plasma Bomb in order to complete the mission."; if (demand) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty. {global.chapter_name} have been given a Plasma Bomb to seal the Necron Tomb on {mission_star.name} {scr_roman(pop_data.planet)}. It is expected to be completed within {pop_data.estimate} months."; + text = $"The Inquisition demands that your Chapter demonstrate its loyalty. {global.chapter_name} have been given a Plasma Bomb to seal the Necron Tomb on {_p_data.name()}. It is expected to be completed within {pop_data.estimate} months."; } reset_popup_options(); scr_add_item("Plasma Bomb", 1); @@ -247,7 +213,7 @@ function init_mission_inquisition_tomb_world() { if (demand) { demand = 0; } - add_new_inquis_mission(); + _p_data.new_problem("inquisition_tomb", estimate, {}); exit; } @@ -281,11 +247,11 @@ function mission_inquistion_hunt_inquisitor(star_id = noone) { var _name = global.name_generator.GenerateFromSet($"imperial_{string_gender()}"); var planet = irandom_range(1, _star.planets); - var eta = scr_mission_eta(_star.x, _star.y, 1); - eta = max(eta, 8); - var text = $"The Inquisition is trusting you with a special mission. A radical inquisitor named {_name} will be visiting the {_star.name} system in {eta} month's time. They are highly suspect of heresy, and as such, are to be put down. Can your chapter handle this mission?"; + var _eta = scr_mission_eta(_star.x, _star.y, 1); + _eta = max(_eta, 8); + var text = $"The Inquisition is trusting you with a special mission. A radical inquisitor named {_name} will be visiting the {_star.name} system in {_eta} month's time. They are highly suspect of heresy, and as such, are to be put down. Can your chapter handle this mission?"; if (obj_controller.demanding) { - text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. A radical inquisitor is enroute to {_star.name}, expected within {eta} months. They are to be silenced and removed."; + text = $"The Inquisition demands that your Chapter demonstrate its loyalty to the Imperium of Mankind and the Emperor. A radical inquisitor is enroute to {_star.name}, expected within {_eta} months. They are to be silenced and removed."; } var _options = [ { @@ -308,7 +274,7 @@ function mission_inquistion_hunt_inquisitor(star_id = noone) { var _pop_data = { system: _star.name, planet: planet, - estimate: eta, + estimate: _eta, mission: "inquisitor", options: _options, mission_data: _mission_data, @@ -317,43 +283,34 @@ function mission_inquistion_hunt_inquisitor(star_id = noone) { scr_popup("Inquisition Mission", text, "inquisition", _pop_data); } -/// @self Asset.GMObject.obj_popup -function add_new_inquis_mission() { - if (add_new_problem(pop_data.planet, pop_data.mission, pop_data.estimate, mission_star)) { - new_star_event_marker("green"); - } -} - /// @self Asset.GMObject.obj_popup function init_mission_hunt_inquisitor() { - mission_star = find_star_by_name(pop_data.system); - if (mission_star == noone) { + var _mission_star = find_star_by_name(pop_data.system); + if (_mission_star == noone) { popup_default_close(); exit; } - scr_event_log("", $"Inquisition Mission Accepted: The radical Inquisitor {pop_data.mission_data.inquisitor_name} enroute to {mission_star.name} must be removed. Estimated arrival in {pop_data.estimate} months.", mission_star.name); + scr_event_log("", $"Inquisition Mission Accepted: The radical Inquisitor {pop_data.mission_data.inquisitor_name} enroute to {_mission_star.name} must be removed. Estimated arrival in {pop_data.estimate} months.", _mission_star.name); - var _radical_inquisitor_fleet = create_enemy_fleet(mission_star.x - irandom_range(-400, 400), mission_star.y - irandom_range(-400, 400), eFACTION.INQUISITION); + var _radical_inquisitor_fleet = create_enemy_fleet(_mission_star.x - irandom_range(-400, 400), _mission_star.y - irandom_range(-400, 400), eFACTION.INQUISITION); with (_radical_inquisitor_fleet) { base_inquis_fleet(); } fleet_add_cargo("radical_inquisitor", pop_data.mission_data, true, _radical_inquisitor_fleet); - _radical_inquisitor_fleet.action_x = mission_star.x; - _radical_inquisitor_fleet.action_y = mission_star.y; + _radical_inquisitor_fleet.action_x = _mission_star.x; + _radical_inquisitor_fleet.action_y = _mission_star.y; var _est = pop_data.estimate; with (_radical_inquisitor_fleet) { set_fleet_movement(false, "move", _est, _est); } - - if (add_new_problem(pop_data.planet, pop_data.mission, pop_data.estimate, mission_star, pop_data.mission_data)) { - new_star_event_marker("green"); - } + var _p_data = _mission_star.get_planet_data(pop_data.planet); + _p_data.new_problem(pop_data.mission, pop_data.estimate,pop_data.mission_data) title = "Inquisition Mission Accepted"; - text = $"{global.chapter_name} will intercept the radical Inquisitor {pop_data.mission_data.inquisitor_name} at {mission_star.name}, expected within {pop_data.estimate} months."; + text = $"{global.chapter_name} will intercept the radical Inquisitor {pop_data.mission_data.inquisitor_name} at {_mission_star.name}, expected within {pop_data.estimate} months."; reset_popup_options(); } @@ -383,7 +340,7 @@ function resolve_radical_inquisitor_mission(_mission_data) { continue; } - var _stored_data = p_problem_other_data[_planet][i]; + var _stored_data = p_problem[_planet][i].data; if (!is_struct(_stored_data) || !struct_exists(_stored_data, "mission_id")) { continue; } @@ -392,9 +349,7 @@ function resolve_radical_inquisitor_mission(_mission_data) { continue; } - p_problem[_planet][i] = ""; - p_timer[_planet][i] = -1; - p_problem_other_data[_planet][i] = {}; + p_problem[_planet][i].delete_mission = true; _mission_removed = true; break; } @@ -588,14 +543,11 @@ function mission_inquistion_spyrer() { } var _star = array_random_element(_valid_stars); var planet = scr_get_planet_with_type(_star, "Hive"); - var eta = scr_mission_eta(_star.x, _star.y, 1); - eta = min(max(eta, 6), 50); - - var text = $"The Inquisition is trusting you with a special mission. An experienced Spyrer on hive world {string(_star.name)} {scr_roman(planet)}"; - text += $" has began to hunt indiscriminately, and proven impossible to take down by conventional means. If they are not put down within {string(eta)} month's time panic is likely. Can your chapter handle this mission?"; - var mission_params = $"spyrer|{string(_star.name)}|{string(planet)}|{string(eta + 1)}|"; - LOGGER.info($"Starting spyrer mission with params {mission_params}"); - scr_popup("Inquisition Mission", text, "inquisition", mission_params); + var _eta = scr_mission_eta(_star.x, _star.y, 1); + _eta = min(max(_eta, 6), 50); + + var _p_data = _star.get_planet_data(planet); + _p_data.new_problem("inquisition_spyrer", _eta, {}); } function mission_inquistion_purge() { @@ -651,29 +603,24 @@ function mission_inquistion_purge() { exit; } - var eta = infinity; + var _eta = infinity; with (obj_p_fleet) { if (capital_number + frigate_number == 0) { - eta = min(scr_mission_eta(_star.x, _star.y, 1), eta); // this is wrong + _eta = min(scr_mission_eta(_star.x, _star.y, 1), _eta); // this is wrong } } - eta = min(max(eta, 12), 100); + _eta += 10; + _eta = min(max(_eta, 12), 100); var text = "The Inquisition is trusting you with a special mission."; + var _purge_type = eDROP_TYPE.PURGEFIRE; + if (mission_flavour < 3){ + _purge_type = eDROP_TYPE.PURGESELECTIVE; + } - if (mission_flavour == 1) { - text += $" A number of high-ranking nobility on the planet {scr_roman(planet)} are being difficult and harboring heretical thoughts. They are to be selectively purged within {string(eta)} months. Can your chapter handle this mission?"; - } else if (mission_flavour == 2) { - text += $" A powerful crimelord on the planet {scr_roman(planet)} is gaining an unacceptable amount of power and disrupting daily operations. They are to be selectively purged within {string(eta)} months. Can your chapter handle this mission?"; - } else if (mission_flavour == 3) { - text += $" The mutants of hive world {scr_roman(planet)} are growing in numbers and ferocity, rising sporadically from the underhive. They are to be cleansed by promethium within {string(eta)} months. Can your chapter handle this mission?"; - } + var _p_data = _star.get_planet_data(planet); + _p_data.new_problem("inquisition_purge", _eta, {mission_flavour, purge_type:_purge_type}); - if (mission_flavour != 3) { - scr_popup("Inquisition Mission", text, "inquisition", $"purge|{string(_star.name)}|{string(planet)}|{string(real(eta + 1))}|"); - } else { - scr_popup("Inquisition Mission", text, "inquisition", $"cleanse|{string(_star.name)}|{string(planet)}|{string(real(eta + 1))}|"); - } } function mission_investigate_planet() { @@ -700,222 +647,17 @@ function mission_investigate_planet() { LOGGER.error("RE: Investigate Planet, couldn't pick a planet"); exit; } - - var eta = infinity; + var _eta = infinity; with (obj_p_fleet) { if (action != "") { continue; } - eta = min(eta, scr_mission_eta(_star.x, _star.y, 1)); - } - eta = min(max(3, eta), 100); - - var text = $"The Inquisition wishes for you to investigate {string(_star.name)} {scr_roman(planet)}"; - text += $" Boots are expected to be planted on its surface over the course of your investigation."; - text += $" You have {string(eta)} months to complete this task."; - scr_popup("Inquisition Recon", text, "inquisition", $"recon|{string(_star.name)}|{string(planet)}|{string(eta)}|"); -} - -/// @self Asset.GMObject.obj_star -/// @desc Queues the Necron Tomb mission prompt when a Plasma Bomb is present. -/// @param {Real} planet Planet index containing the Necron Tomb. -/// @returns {Undefined} -function setup_necron_tomb_raid(planet) { - LOGGER.info($"player on planet with necron mission {name} planet: {planet}"); - var have_bomb; - have_bomb = scr_check_equip("Plasma Bomb", name, planet, 0); - LOGGER.info($"have bomb? {have_bomb} "); - if (have_bomb > 0) { - var tixt; - tixt = $"Your marines on {planet_numeral_name(planet, id)}"; - tixt += " are prepared and ready to enter the Necron Tombs. A Plasma Bomb is in tow."; - var _number = instance_exists(obj_turn_end) ? 1 : 0; - var _pop_data = { - mission: "necron_tomb_excursion", - loc: name, - planet: planet, - estimate: 999, - number: _number, - mission_stage: 1, - options: [ - { - str1: "Begin the Mission", - choice_func: necron_tomb_mission_start, - }, - { - str1: "Not Yet", - choice_func: popup_default_close, - }, - ], - }; - scr_popup("Necron Tomb Excursion", tixt, $"necron_cave", _pop_data); + _eta = min(_eta, scr_mission_eta(_star.x, _star.y, 1)); } + _eta = min(max(3, _eta), 100); + _star.get_planet_data(planet).new_problem("inquisition_recon", _eta); } -/// @self Asset.GMObject.obj_popup -/// @desc Initializes the popup and choices for a Necron Tomb mission. -/// @returns {Undefined} -function necron_tomb_mission_start() { - mission_star = find_star_by_name(pop_data.loc); - planet = pop_data.planet; - - title = $"Necron Tunnels : {pop_data.mission_stage}"; - replace_options([{str1: "Continue", choice_func: necron_tomb_mission_sequence}, {str1: "Return to the surface", choice_func: popup_default_close}]); - image = "necron_tunnels_1"; - text = "Your marines enter the massive tunnel complex, following the energy readings. At first the walls are cramped and tiny, closing about them, but the tunnels widen at a rapid pace."; -} - -/// @self Asset.GMObject.obj_popup -/// @desc Advances the Necron Tomb mission and renders the resulting popup state. -/// @returns {Bool} Whether the mission reached completion. -function advance_necron_tomb_mission() { - pop_data.mission_stage++; - title = $"Necron Tunnels : {pop_data.mission_stage}"; - - if (pop_data.mission_stage == 2) { - image = "necron_tunnels_2"; - text = "The energy readings are much stronger, now that your marines are deep inside the tunnels. What was once cramped is now luxuriously large, the tunnel ceiling far overhead decorated by stalactites."; - return false; - } - if (pop_data.mission_stage == 3) { - image = "necron_tunnels_3"; - text = "After several hours of descent the entrance to the Necron Tomb finally looms ahead- dancing, sickly green light shining free. Your marine confirms that the Plasma Bomb is ready."; - return false; - } - if (pop_data.mission_stage >= 4) { - image = ""; - title = "Inquisition Mission Completed"; - text = "Your marines finally enter the deepest catacombs of the Necron Tomb. There they place the Plasma Bomb and arm it. All around are signs of increasing Necron activity. With half an hour set, your men escape back to the surface. There is a brief rumble as the charge goes off, your mission a success."; - reset_popup_options(); - - alter_disposition(eFACTION.INQUISITION, obj_controller.demanding ? choose(0, 0, 1) : 1); - - mission_star = find_star_by_name(pop_data.loc); - remove_planet_problem(planet, "necron", mission_star); - seal_tomb_world(mission_star.p_feature[planet]); - - scr_event_log("", $"Inquisition Mission Completed: Your Astartes have sealed the Necron Tomb on {mission_star.name} {scr_roman(planet)}.", mission_star.name); - scr_gov_disp(mission_star.name, planet, irandom_range(3, 7)); - scr_check_equip("Plasma Bomb", pop_data.loc, pop_data.planet, 1); - return true; - } - return false; -} - -/// @self Asset.GMObject.obj_popup -/// @desc Advances the Necron Tomb mission or starts a combat encounter. -/// @returns {Undefined} -function necron_tomb_mission_sequence() { - var battle; - var player_forces = 0; - var penalty = 0; - var roll = roll_dice_chapter(1, 100, "low"); - battle = 0; - instance_activate_all(); - player_forces = mission_star.p_player[planet]; - - // SMALL TEAM OF MARINES - if (player_forces > 6) { - penalty = 10; - } - if (player_forces > 10) { - penalty = 20; - } - if (player_forces >= 20) { - penalty = 30; - } - if (player_forces >= 40) { - penalty = 50; - } - if (player_forces >= 60) { - penalty = 100; - } - roll += penalty; - - // roll=30;if (string_count("3",title)>0) then roll=70; - - // Result - if (roll <= 60) { - advance_necron_tomb_mission(); - exit; - } - if ((roll > 60) && (roll <= 82)) { - // Necron Wraith attack - battle = 1; - } - if ((roll > 82) && (roll <= 92)) { - // Tomb Spyder attack - battle = 2; - } - if ((roll > 92) && (roll <= 97)) { - // Tomb Stalker - battle = 3; - } - if (roll > 97) { - // Tomb World wakes up - if (player_forces <= 30) { - battle = 4; - } - if (player_forces > 30) { - battle = 5; - } - if (player_forces > 100) { - battle = 6; - } - } - - if (battle > 0) { - instance_deactivate_all_safe(); - instance_activate_object(obj_star); - - instance_create(0, 0, obj_ncombat); - _roster = new Roster(); - var _pop_data = pop_data; - with (_roster) { - roster_location = _pop_data.loc; - roster_planet = _pop_data.planet; - determine_full_roster(); - only_locals(); - update_roster(); - if (array_length(selected_units)) { - setup_battle_formations(); - add_to_battle(); - } - } - delete _roster; - - mission_star = find_star_by_name(pop_data.loc); - - obj_ncombat.battle_object = mission_star; - instance_deactivate_object(obj_star); - obj_ncombat.battle_loc = pop_data.loc; - obj_ncombat.battle_id = pop_data.planet; - obj_ncombat.dropping = 0; - obj_ncombat.attacking = 0; - obj_ncombat.enemy = eFACTION.NECRONS; - obj_ncombat.threat = 1; - obj_ncombat.formation_set = 1; - obj_ncombat.battle_mission = "necron_tomb_excursion"; - obj_ncombat.battle_data = pop_data; - if (battle == 1) { - obj_ncombat.battle_special = "wraith_attack"; - } else if (battle == 2) { - obj_ncombat.battle_special = "spyder_attack"; - } else if (battle == 3) { - obj_ncombat.battle_special = "stalker_attack"; - } else if (battle == 4) { - obj_ncombat.battle_special = "wake1_attack"; - } else if (battle == 5) { - obj_ncombat.battle_special = "wake2_attack"; - } else if (battle == 6) { - obj_ncombat.battle_special = "wake2_attack"; - } - - instance_destroy(); - } - - exit; -} function set_gender() { return choose(eGENDER.FEMALE, eGENDER.MALE); diff --git a/scripts/scr_manage_task_selector/scr_manage_task_selector.gml b/scripts/scr_manage_task_selector/scr_manage_task_selector.gml index ef4b8727b8..fac5036bea 100644 --- a/scripts/scr_manage_task_selector/scr_manage_task_selector.gml +++ b/scripts/scr_manage_task_selector/scr_manage_task_selector.gml @@ -19,13 +19,14 @@ function scr_manage_task_selector() { exit; } } + var _man_count; if (selection_data.select_type == eMISSION_SELECT_TYPE.UNITS) { - man_count = array_sum(man_sel); + _man_count = array_sum(man_sel); } else { - man_count = array_length(company_data.selected_squads); + _man_count = array_length(company_data.selected_squads); } if (selection_data.purpose_code != "manage") { - if (man_count == 0 || man_count > selection_data.number) { + if (_man_count == 0 || _man_count > selection_data.number) { proceed_button.draw_shutter(1110, 70, "Proceed", 0.5, false); } else if (proceed_button.draw_shutter(1110, 70, "Proceed", 0.5, true)) { if (selection_data.select_type == eMISSION_SELECT_TYPE.UNITS) { @@ -39,20 +40,26 @@ function scr_manage_task_selector() { /// @self Asset.GMObject.obj_controller function task_selector_squad_manage() { + var _squads = []; for (var i = 0; i < array_length(company_data.selected_squads); i++) { var _squad = fetch_squad(company_data.selected_squads[i]); - switch (selection_data.purpose_code) { - case "protect_raiders": - init_protect_raider_mission(_squad); - break; + /*switch (selection_data.purpose_code) { + + }*/ + array_push(_squads, _squad); + } + if (struct_exists(selection_data , "feature") && array_length(_squads)){ + var _feat = selection_data.feature; + if (is_struct(_feat) && is_instanceof(_feat, PlanetProblem)){ + _feat.data.squads = _squads; + _feat.on_squad_selection(); } } } /// @self Asset.GMObject.obj_controller function task_selector_man_manage() { - man_count = array_sum(man_sel); - selections = []; + var _selections = []; for (var i = 0; i < array_length(display_unit); i++) { if (ma_name[i] == "") { continue; @@ -60,6 +67,7 @@ function task_selector_man_manage() { /// @type {Struct.TTRPG_stats} var _unit = display_unit[i]; if (man_sel[i]) { + array_push(_selections, _unit); switch (selection_data.purpose_code) { case "forge_assignment": var _forge = selection_data.feature; @@ -124,25 +132,6 @@ function task_selector_man_manage() { managing = selection_data.target_company; update_general_manage_view(); exit; - case "hunt_beast": - _unit.job = { - type: selection_data.purpose_code, - planet: selection_data.planet, - location: selection_data.system.name, - }; - _unit.unload(selection_data.planet, selection_data.system); - break; - case "train_forces": - _unit.job = { - type: selection_data.purpose_code, - planet: selection_data.planet, - location: selection_data.system.name, - }; - _unit.unload(selection_data.planet, selection_data.system); - init_train_forces_mission(selection_data.planet, selection_data.system, selection_data.array_slot, _unit); - obj_controller.close_popups = false; - exit_adhoc_manage(); - exit; case "artifact_equip": scr_toggle_lib(); var _arti = fetch_artifact(selection_data.artifact); @@ -167,15 +156,18 @@ function task_selector_man_manage() { } } } + selection_data.selections = _selections; + if (struct_exists(selection_data, "feature")){ + LOGGER.info("feature select call point") + var _feat = selection_data.feature; + if (is_struct(_feat) && is_instanceof(_feat, PlanetProblem)){ + _feat.on_unit_selection(); + } + } switch (selection_data.purpose_code) { case "forge_assignment": specialist_point_handler.calculate_research_points(); break; - case "hunt_beast": - var problem_slot = selection_data.array_slot; - init_beast_hunt_mission(selection_data.planet, selection_data.system, problem_slot); - obj_controller.close_popups = false; - break; } exit_adhoc_manage(); exit; diff --git a/scripts/scr_marine_struct/scr_marine_struct.gml b/scripts/scr_marine_struct/scr_marine_struct.gml index 35c5d536e4..f7f16e6ae7 100644 --- a/scripts/scr_marine_struct/scr_marine_struct.gml +++ b/scripts/scr_marine_struct/scr_marine_struct.gml @@ -1841,7 +1841,8 @@ function TTRPG_stats(faction, comp, mar, class = "marine", other_spawn_data = {} if (squad != "none") { var _squad = get_squad(); - for (var r = 0; r < array_length(_squad.members); r++) { + var _member_count = array_length(_squad.get_members()); + for (var r = 0; r < _member_count; r++) { squad_member = _squad.members[r]; if (squad_member.uid == uid) { array_delete(_squad.members, r, 1); @@ -2440,6 +2441,26 @@ function fetch_unit_uid(uuid) { return undefined; } +function clean_unit_array(array){ + for (var i = array_length(array) - 1; i >= 0; i--){ + var _unit = array[i]; + if (!is_struct(_unit)){ + array_delete(array, i, 1); + continue; + } + if (_unit.marine_number > (company_length(_unit.company) - 1)){ + array_delete(array, i, 1); + continue; + } + var _current_unit = fetch_unit([_unit.company, _unit.marine_number]); + if (!is_struct(_current_unit) || _current_unit.uid != _unit.uid){ + array_delete(array, i, 1); + continue; + } + } + return array; +} + /// @desc Localizes a unit's role and appends its name and first epithet, mirroring /// name_role()'s display order while keeping the role translatable. /// @param {Struct} _unit A marine unit struct. diff --git a/scripts/scr_mechanicus_missions/scr_mechanicus_missions.gml b/scripts/scr_mechanicus_missions/scr_mechanicus_missions.gml index b09d90f32e..c897af06ae 100644 --- a/scripts/scr_mechanicus_missions/scr_mechanicus_missions.gml +++ b/scripts/scr_mechanicus_missions/scr_mechanicus_missions.gml @@ -1,144 +1,3 @@ -function mechanicus_missions_end_turn(planet) { - var _pdata = get_planet_data(planet); - var raider_planet_slot = has_problem_planet_with_time(planet, "mech_raider"); - if (raider_planet_slot > -1) { - var _techs = collect_role_group(SPECIALISTS_TECHS, [name, planet, -1]); - var _lr_count = scr_vehicle_count("Land Raider", [name, planet, -1]); - if ((array_length(_techs) >= 6) && (_lr_count >= 1)) { - var _prob_data = p_problem_other_data[planet][raider_planet_slot]; - var percent_complete = increment_mission_completion(_prob_data); - scr_alert("", $"mission", $"Mechanicus Mission on {planet_numeral_name(planet, id)} is {floor(percent_complete)}% complete.", 0, 0); - if (percent_complete >= 100) { - remove_planet_problem(planet, "mech_raider"); - scr_mission_reward("mech_raider", id, planet); - } - } - } - var bionics_planet_slot = has_problem_planet_with_time(planet, "mech_bionics"); - if (bionics_planet_slot > -1) { - var _units = _pdata.collect_planet_group(); - var _bionics = _units.tally_attr("bionics"); - if (_bionics >= 10) { - var _prob_data = p_problem_other_data[planet][bionics_planet_slot]; - var percent_complete = increment_mission_completion(_prob_data); - scr_alert("", $"mission", $"Mechanicus Mission on {planet_numeral_name(planet, id)} is {floor(percent_complete)}% complete.", 0, 0); - if (percent_complete >= 100) { - remove_planet_problem(planet, "mech_bionics"); - scr_mission_reward("mech_bionics", id, planet); - } - } - } - var tomb2_planet_slot = has_problem_planet_with_time(planet, "mech_tomb2"); - if (tomb2_planet_slot > -1) { - var _mission_data = p_problem_other_data[planet][tomb2_planet_slot]; - _mission_data.turns++; - var battli = 0; - var _roll1 = roll_dice_chapter(1, 100 + _mission_data.turns, "low"); - var completion = _mission_data.completion > 0; - - if (roll1 > 98) { - if ((roll1 >= 90) && (roll1 < 98)) { - battli = 1; - } // oops - if (roll1 >= 98) { - battli = 2; - } // very oops, much necron, wow - - if ((battli > 0) && (p_player[planet] > 0)) { - // Quene the battle - obj_turn_end.battles += 1; - obj_turn_end.battle[obj_turn_end.battles] = 1; - obj_turn_end.battle_world[obj_turn_end.battles] = planet; - obj_turn_end.battle_opponent[obj_turn_end.battles] = 13; - obj_turn_end.battle_location[obj_turn_end.battles] = name; - obj_turn_end.battle_object[obj_turn_end.battles] = id; - if (battli == 1) { - obj_turn_end.battle_special[obj_turn_end.battles] = "study2a"; - } - if (battli == 2) { - obj_turn_end.battle_special[obj_turn_end.battles] = "study2b"; - } - - if (obj_turn_end.battle_opponent[obj_turn_end.battles] == 11) { - if (planet_feature_bool(p_feature[planet], eP_FEATURES.CHAOSWARBAND) == 1) { - obj_turn_end.battle_special[obj_turn_end.battles] = "ChaosWarband"; - } - } - } - if ((battli > 0) && (p_player[planet] <= 0)) { - // XDDDDD - scr_popup("Mechanicus Mission Failed", "The Mechanicus Research team on planet " + string(name) + " " + scr_roman(planet) + " have been killed by Necrons in the absence of your astartes. The Mechanicus are absolutely livid, doubly so because of the promised security they did not recieve.", "", ""); - obj_controller.turns_ignored[3] += choose(8, 10, 12, 14, 16, 18, 20, 22, 24); - obj_controller.disposition[3] -= 25; - remove_planet_problem(planet, "mech_tomb2"); - } - } else { - // Done - if (roll1 > 20) { - scr_alert("", "mission", "Adeptus Mechanicus research within the Necron Tomb of " + string(name) + " " + scr_roman(planet) + " continues.", 0, 0); - } else if (roll1 <= 20) { - // Complete - var text, reward = choose(1, 1, 2); - if (scr_has_adv("Tech-Brothers")) { - reward = choose(1, 2); - } - - if (reward == 1) { - obj_controller.requisition += 400; - text = "The Mechanicus Research team on planet " + string(name) + " " + scr_roman(planet) + " have completed their work without any major setbacks. Pleased with your astartes' work, they have granted you 400 Requisition to be used as you see fit."; - scr_event_log("", "Mechanicus Mission Completed: The Mechanicus research team on " + string(name) + " " + scr_roman(planet) + " have completed their work."); - } else if (reward == 2) { - var last_artifact = scr_add_artifact("random", "", 0); - text = "The Mechanicus Research team on planet " + string(name) + " " + scr_roman(planet) + " have completed their work without any major setbacks. Pleased with your astartes' work, they have granted your Chapter an artifact, to be used as you see fit."; - scr_event_log("", "Mechanicus Mission Completed: The Mechanicus research team on " + string(name) + " " + scr_roman(planet) + " have completed their work."); - scr_event_log("", "Artifact gifted from Mechanicus."); - } - - scr_popup("Mechanicus Mission Completed", text, "mechanicus", ""); - - obj_controller.disposition[3] += 1; - remove_planet_problem(planet, "mech_tomb2"); - } - } - } - var tomb1_planet_slot = has_problem_planet_with_time(planet, "mech_tomb1"); - if (tomb1_planet_slot > -1) { - var _marines = collect_role_group("all", [name, planet, -1]); - if (array_length(_marines) >= 20) { - remove_planet_problem(planet, "mech_tomb1"); - add_new_problem(planet, "mech_tomb2", 999, noone, {turns: 0}); - scr_popup("Mechanicus Research", "The Mechanicus Research team on planet " + string(name) + " " + scr_roman(planet) + " has taken note of your Astartes and are now prepared to begin their research. Your marines are to stay on the planet until further notice.", "necron_cave", ""); - } else {} - } - if (has_problem_planet_and_time(planet, "mech_tomb1", 0) > -1) { - var alert_text = "Mechanicus Mission Failed: Necron Tomb Study at " + string(name) + " " + scr_roman(planet) + "."; - scr_alert("red", "mission_failed", alert_text, 0, 0); - scr_event_log("red", alert_text, name); - alter_disposition(eFACTION.MECHANICUS, -15); - remove_planet_problem(planet, "mech_tomb1"); - } - - var mars_mech_mission = has_problem_planet_and_time(planet, "mech_mars", 0); - if (mars_mech_mission > -1) { - mechanicus_mars_mission_target_time_elapsed(planet); - } - - if (has_problem_planet_and_time(planet, "mech_raider", 0) > -1) { - var alert_text = "Mechanicus Mission Failed: Land Raider testing at " + string(name) + " " + scr_roman(planet) + "."; - scr_alert("red", "mission_failed", alert_text, 0, 0); - scr_event_log("red", alert_text); - alter_disposition(eFACTION.MECHANICUS, -6); - remove_planet_problem(planet, "mech_raider"); - } - if (has_problem_planet_and_time(planet, "mech_bionics", 0) > -1) { - var alert_text = "Mechanicus Mission Failed: bionics testing at " + string(name) + " " + scr_roman(planet) + "."; - scr_alert("red", "mission_failed", alert_text, 0, 0); - scr_event_log("red", alert_text); - alter_disposition(eFACTION.MECHANICUS, -6); - remove_planet_problem(planet, "mech_bionics"); - } -} - function spawn_mechanicus_mission(chosen_mission = "random") { LOGGER.info("RE: Mechanicus Mission"); var mechanicus_missions = []; @@ -148,7 +7,8 @@ function spawn_mechanicus_mission(chosen_mission = "random") { if (array_length(_forge_stars)) { array_push(mechanicus_missions, "mech_bionics"); - if (scr_role_count(obj_ini.player_role_data[eROLE.TECHMARINE].role, "") >= 6) { + var _techs = collect_role_group([SPECIALISTS_TECHMARINES, false, true],"",false,{},true); + if (_techs.number() >= 3) { array_push(mechanicus_missions, "mech_raider"); } } @@ -276,7 +136,7 @@ function spawn_mechanicus_mission(chosen_mission = "random") { function accept_mechanicus_tomb_mission() { var _planet = false; var _star = pop_data.star; - for (var i = 1; i < _star.planets; i++) { + for (var i = 1; i <= _star.planets; i++) { if (awake_tomb_world(_star.p_feature[i]) != 0) { _planet = i; break; @@ -284,16 +144,7 @@ function accept_mechanicus_tomb_mission() { } if (_planet > 0) { _planet = _star.get_planet_data(_planet); - _planet.add_problem("mech_tomb1", 17); - var _name = _planet.name(); - text = $"The Adeptus Mechanicus await your forces at {_name}. They are expecting at least two squads of Astartes and have placed the testing on hold until their arrival. {global.chapter_name} have 16 months to arrive."; - scr_event_log("", "Mechanicus Mission Accepted: At least two squads of marines are expected at {_name} within 16 months.", _star.name); - with (_star) { - new_star_event_marker("green"); - } - title = "Mechanicus Mission Accepted"; - reset_popup_options(); - cooldown = 15; + _planet.new_problem("mech_tomb", scr_mission_eta(_star.x, _star.y), {stage : "awating_player"}); exit; } } @@ -304,18 +155,7 @@ function accept_mechanicus_land_raider_mission() { var _forge_planet = scr_get_planet_with_type(_star, "Forge"); if (_forge_planet > 0) { var _planet = _star.get_planet_data(_forge_planet); - - var _mission_loc = _planet.name(); - var _nearest_fleet = instance_nearest(_star.x, _star.y, obj_p_fleet); - var _mission_time = get_viable_travel_time(5, _nearest_fleet.x, _nearest_fleet.y, _star.x, _star.y, _nearest_fleet, false); - - _planet.add_problem("mech_raider", _mission_time, {completion: 0, required_months: 24}); - text = $"The Adeptus Mechanicus await your forces at {_mission_loc}. They are expecting six {obj_ini.player_role_data[eROLE.TECHMARINE].role}s and a Land Raider."; - scr_event_log("", $"Mechanicus Mission Accepted: Six of your {obj_ini.player_role_data[eROLE.TECHMARINE].role}s and a Land Raider are to be stationed at {_mission_loc} for {_mission_time} months.", _star.name); - with (_star) { - new_star_event_marker("green"); - } - title = "Mechanicus Mission Accepted"; + _planet.new_problem("mech_raider", 1, {}); } else { text = $"Error valid forge planet not found please open a bug report if seen"; } @@ -333,7 +173,7 @@ function accept_mechanicus_bionics_mission() { var _nearest_fleet = instance_nearest(_star.x, _star.y, obj_p_fleet); var _mission_time = get_viable_travel_time(5, _nearest_fleet.x, _nearest_fleet.y, _star.x, _star.y, _nearest_fleet, false); - _planet.add_problem("mech_bionics", _mission_time, {completion: 0, required_months: 24}); + _planet.new_problem("mech_bionics", _mission_time, {completion: 0, required_months: 24}); text = $"The Adeptus Mechanicus await your forces at {_mission_loc}. They are expecting ten Astartes with bionics. (Beneficial traits: Weakness of Flesh )"; scr_event_log("", $"Mechanicus Mission Accepted: Ten Astartes with bionics are to be stationed at {_mission_loc} for 24 months for testing purposes.", _star.name); with (_star) { @@ -357,8 +197,7 @@ function accept_mechanicus_mars_mission() { var _nearest_fleet = instance_nearest(_star.x, _star.y, obj_p_fleet); var _mission_time = get_viable_travel_time(5, _nearest_fleet.x, _nearest_fleet.y, _star.x, _star.y, _nearest_fleet, false); - _planet.add_problem("mech_bionics", _mission_time, {completion: 0, required_months: 24}); - _planet.add_problem("mech_mars", _mission_time); + _planet.new_problem("mech_mars", _mission_time); text = $"The Adeptus Mechanicus await your {obj_ini.player_role_data[eROLE.TECHMARINE].role}s at {_mission_loc}. They are willing to hold on the voyage for up to {_mission_time} months."; scr_event_log("", $"Mechanicus Mission Accepted: {obj_ini.player_role_data[eROLE.TECHMARINE].role}s are expected at {_mission_loc} within 30 months, for the voyage to Mars.", _star.name); with (_star) { @@ -371,74 +210,3 @@ function accept_mechanicus_mars_mission() { } reset_popup_options(); } - -/// @self Asset.GMObject.obj_star -function mechanicus_mars_mission_target_time_elapsed(planet) { - var techs_taken, com, ide, ship_planet, _unit; - techs_taken = 0; - com = -1; - ide = 0; - ship_planet = ""; - for (com = 0; com <= 10; com++) { - for (ide = 0; ide < array_length(obj_ini.TTRPG[com]); ide++) { - _unit = fetch_unit([com, ide]); - if (!is_struct(_unit)) { - continue; - } - if (_unit.role() == obj_ini.player_role_data[eROLE.TECHMARINE].role) { - // Case 1: on planet - if ((_unit.location_string == name) && (_unit.planet_location == planet)) { - p_player[planet] -= _unit.get_unit_size(); - _unit.location_string = "Mechanicus Vessel"; - _unit.planet_location = 0; - _unit.ship_location = -1; - _unit.job = { - type: "mechanicus mission", - }; - techs_taken += 1; - } - if (_unit.ship_location > -1) { - ship_planet = obj_ini.ship_location[_unit.ship_location]; - if (ship_planet == name) { - obj_ini.ship_carrying[_unit.ship_location] -= _unit.get_unit_size(); - _unit.location_string = "Mechanicus Vessel"; - _unit.planet_location = 0; - _unit.ship_location = -1; - _unit.job = { - type: "mechanicus mission", - }; - techs_taken += 1; - } - } - } - } - } - if (techs_taken == 0) { - var alert_text = $"Mechanicus Mission Failed: Journey to Mars Catacombs at {planet_numeral_name(planet, id)}."; - scr_alert("red", "mission_failed", alert_text, 0, 0); - scr_event_log("red", alert_text); - obj_controller.disposition[3] -= 10; - remove_planet_problem(planet, "mech_mars"); - } else if (techs_taken > 0) { - if (techs_taken >= 5) { - obj_controller.disposition[3] += max(techs_taken, 4); - } - var _text = $"Mechanicus Ship departs for the Mars catacombs. Onboard are {techs_taken} of your {obj_ini.player_role_data[eROLE.TECHMARINE].role}s."; - scr_alert("", "mission", _text, 0, 0); - scr_event_log("green", _text); - var flit = create_enemy_fleet(x, y, eFACTION.MECHANICUS); - - with (flit) { - sprite_index = spr_fleet_mechanicus; - capital_number = 1; - image_index = 0; - image_speed = 0; - trade_goods = "mars_spelunk1"; - home_x = x; - home_y = y; - action_x = x + lengthdir_x(3000, obj_controller.terra_direction); - action_y = y + lengthdir_y(3000, obj_controller.terra_direction); - set_fleet_movement(false, "move", 48, 48); - } - } -} diff --git a/scripts/scr_mission_functions/scr_mission_functions.gml b/scripts/scr_mission_functions/scr_mission_functions.gml index 2c675f797f..05e270a406 100644 --- a/scripts/scr_mission_functions/scr_mission_functions.gml +++ b/scripts/scr_mission_functions/scr_mission_functions.gml @@ -1,4 +1,65 @@ -function MissionHandler(planet, system) : PlanetData(planet, system) constructor {} +/// @param {string} _name +/// @param {Real} _timer +/// @param {struct} _data +function Problem(_name, _timer, _data) constructor { + p_id = _name; + timer = _timer; + data = _data; + uid = scr_uuid_generate(); + delete_mission = false; + f_type = eP_FEATURES.MISSION; + stage_id = ""; + if (struct_exists(data, "stage")){ + stage_id = data.stage; + } + if (struct_exists(data, "members")){ + members = data.members; + } + static has_data = function(key){ + return struct_exists(data, key); + } + static description = function(){ + var _n = mission_name_key(p_id); + _n = _n == "" ? p_id : _n; + return _n; + } + static __popup_delete = function(){ + with(obj_popup){ + popup_default_close(); + } + __check_delete(); + } + + static find_func_ref = function(trigger_string){ + var _func_string = "__" + p_id + "_" + trigger_string; + return _func_string; + } + + static has_func = function(trigger_string){ + var _func_string = find_func_ref(trigger_string); + return struct_exists(self,_func_string); + } + static find_func = function(trigger_string){ + var _func_string = find_func_ref(trigger_string); + if (struct_exists(self,_func_string)){ + return self[$ _func_string] + } + return undefined; + } + static __handle_triggered_mission_func = function(func){ + if (!is_undefined(func)){ + __refresh_data(); + try { + func(); + } catch (_exception) { + delete_mission = true; + ERROR_HANDLER.handle_exception(_exception); + } + } + __check_delete(); + obj_controller.location_viewer.update_mission_log(); + } +} function location_out_of_player_control(unit_loc) { static _locs = [ @@ -17,8 +78,8 @@ global.planet_problem_keys = [ "mech_raider", "mech_bionics", "mech_mars", - "mech_tomb1", - "fallen", + "mech_tomb", + "hunt_fallen", "great_crusade", "harlequins", "fund_elder", @@ -29,28 +90,29 @@ global.planet_problem_keys = [ "join_parade", "recover_artifacts", "train_forces", - "spyrer", + "inquisition_spyrer", "inquisitor", - "recon", + "inquisition_recon", "cleanse", "purge", - "tyranid_org", + "inquisition_tyranid_org", "artifact_loan", - "necron", + "inquisition_tomb", "ethereal", "demon_world", + "governor_purge_enemies" ]; function mission_name_key(mission) { - var mission_key = { + static mission_key = { "meeting_trap": "Chaos Lord Meeting", "meeting": "Chaos Lord Meeting", "succession": "War of succession", "mech_raider": "Provide Land Raider to Mechanicus", "mech_bionics": "Provide Bionic Augmented marines to study", "mech_mars": "Send Techmarines to mars", - "mech_tomb1": "Explore Mechanicus Tomb", - "fallen": "Find Chapter Fallen", + "mech_tomb": "Explore Mechanicus Tomb", + "hunt_fallen": "Find Chapter Fallen", "great_crusade": "Answer Crusade Muster Call", "harlequins": "Harlequin presence Report", "fund_elder": "provide assistance to Eldar", @@ -62,200 +124,22 @@ function mission_name_key(mission) { "recover_artifacts": "Recover Artifacts", "train_forces": "Train Planet Forces", // Inquisition missions - "spyrer": "Kill Spyrer for Inquisitor", + "inquisition_spyrer": "Kill Spyrer for Inquisitor", "inquisitor": "Radical Inquisitor Arriving", - "recon": "Recon Mission for Inquisitor", + "inquisition_recon": "Recon Mission for Inquisitor", "cleanse": "Cleanse Planet for Inquisitor", "purge": "Purge Leadership for Inquisitor", - "tyranid_org": "Capture Tyranid for Inquisitor", + "inquisition_tyranid_org": "Capture Tyranid for Inquisitor", // "bomb" : "Bombard World for Inquisitor", "artifact_loan": "Safeguard Artifact for the Inquisition", - "necron": "Bomb Necron Tomb for Inquisitor", + "inquisition_tomb": "Bomb Necron Tomb for Inquisitor", "ethereal": "Capture Ethereal for Inquisitor", "demon_world": "Clear Demon World for Inquisitor", }; if (struct_exists(mission_key, mission)) { return mission_key[$ mission]; } else { - return "none"; - } -} - -/// @self Struct.PlanetData -function problem_end_turn_checks() { - /// @self Struct.PlanetData - static problem_functions = { - "succession": function(problem_index) { - if (problem_timers[problem_index] > 0) { - return; - } - var result, _alert_text; - var dice1 = roll_dice(1, 100); - var dice2 = roll_dice(1, 100); - - result = eFACTION.IMPERIUM; - _alert_text = ""; - if (dice1 <= (corruption * 2)) { - result = eFACTION.CHAOS; - } - if (dice2 <= (population_influences[eFACTION.TAU] * 2)) { - result = eFACTION.TAU; - } - - if (current_owner == eFACTION.IMPERIUM && result != eFACTION.IMPERIUM) { - edit_pdf(guardsmen); - edit_guardsmen(-guardsmen); - set_new_owner(result); - } - - _alert_text = $"War of Succession on {name()} has ended"; - - if (result == eFACTION.CHAOS) { - _alert_text += " with Chaos in control."; - set_player_disposition(0); - scr_alert("red", "succession", _alert_text, x, y); - scr_event_log("purple", _alert_text); - } else if (result == eFACTION.TAU) { - _alert_text += " with a Tau sympathizer in control."; - set_player_disposition(10 + choose(1, 2, 3, 4, 5, 6)); - add_forces(eFACTION.TAU, 2); - scr_alert("red", "succession", _alert_text, x, y); - scr_event_log("red", _alert_text); - } else if (result == eFACTION.IMPERIUM) { - _alert_text += " The resultant governor is the most staunch pillar of the imperium."; - _alert_text += "."; - scr_alert("green", "succession", _alert_text, x, y); - scr_event_log("", _alert_text); - } else { - //At the moment does not fire but a worty flavour option for down the line - _alert_text += " Word is the new Governor has Heretical leanings and sympathises with xenos."; - } - - delete_feature(eP_FEATURES.SUCCESSION_WAR); - remove_problem("succession"); - }, - "recon": function(problem_index) { - if (problem_timers[problem_index] > 0) { - return; - } - var _alert_text = "Inquisition Mission Failed: Investigate "; - alter_disposition(eFACTION.INQUISITION, -5); - _alert_text += $"{name()}."; - scr_alert("red", "mission_failed", _alert_text, 0, 0); - scr_event_log("red", _alert_text); - remove_problem("recon"); - }, - "great_crusade": function(problem_index) { - if (problem_timers[problem_index] > 0) { - return; - } - var _crusade_direction; - var _join_crusade = false; - var _player_fleet = instance_nearest(system.x, system.y, obj_p_fleet); - - if (_player_fleet.action == "") { - if (point_distance(system.x, system.y, _player_fleet.x, _player_fleet.y) < 10) { - _join_crusade = true; - } - } - - if (_join_crusade) { - _crusade_direction = point_direction(room_width / 2, room_height / 2, x, y); - with (_player_fleet) { - action_x = x + lengthdir_x(1200, _crusade_direction); - action_y = y + lengthdir_y(1200, _crusade_direction); - set_fleet_movement(false, "crusade1"); - } - - scr_alert("green", "crusade", "Fleet embarks upon Crusade.", x, y); - scr_event_log("", "Fleet embarks upon Crusade."); - } else { - // hit loyalty here - alter_dispositions([[eFACTION.INQUISITION, -10], [eFACTION.IMPERIUM, -5]]); - var _string = $"No ships designated for Crusade."; - if (obj_controller.penitent == 1) { - obj_controller.penitent_current = 0; - _string += "Your penitence crusade has been lengthened for your failings"; - } - - scr_alert("red", "crusade", _string, system.x, system.y); - scr_loyalty("Refusing to Crusade", "+"); - scr_event_log("red", "No ships designated for Crusade."); - } - remove_problem("great_crusade"); - }, - "necron": function(problem_index) { - if (problem_timers[problem_index] > 0) { - return; - } - - alter_disposition(eFACTION.INQUISITION, -8); - var _alert_text = $"The Necron Tomb of planet {name()} has not been deactivated in time. It has awakened, rank upon rank of Necrons pouring out to the planet's surface. The Inquisition is not pleased with your failure."; - scr_popup("Inquisition Mission Failed", _alert_text, "necron_army", ""); - scr_event_log("red", $"Inquisition Mission Failed: Bombing run failed; the Necron Tomb on {name()} has become active."); - - add_forces(eFACTION.NECRONS, 4); - if (awake_tomb_world(features) == 0) { - awaken_tomb_world(features); - } - remove_problem("necron"); - }, - "spyrer": function(problem_index) { - if (problem_timers[problem_index] > 0) { - return; - } - var _planet_name = name(); - alter_disposition(eFACTION.INQUISITION, -3); - var _alert_text = $"The Spyrer on {_planet_name} has been left unchecked. In the ensuing carnage some high-ranking officials have been killed, along with several Nobles. Panic is running amock in several parts of the hives and the Inquisition is less than pleased."; - var _text = "Inquisition Mission Failed: The Spyrer on {_planet_name} was not removed."; - scr_popup("Inquisition Mission Failed", _alert_text, "spyrer", ""); - scr_event_log("red", _text); - remove_problem("spyrer"); - }, - "fallen": function(problem_index) { - //TODO marker point for cohesion mechanics - if (problem_timers[problem_index] > 0) { - return; - } - var alert_text = ""; - if (irandom(100) > 33) { - // Give all marines +3d6 corruption and reduce loyalty by 20*/ - for (var co = 0; co <= obj_ini.companies; co++) { - for (var me = 0; me < company_length(co); me++) { - var _unit = fetch_unit([co, me]); - if (_unit.base_group != "astartes") { - continue; - } - _unit.edit_corruption(irandom_range(3, 6)); - _unit.alter_loyalty(-10); - } - } - } - alert_text = $"Any Fallen that may have been on {name()} "; - alert_text += "have been given sufficient time to escape. Morale within your chapter has plummeted; some of your battle brothers have become restless and speak among eachother in hushed tones."; - scr_popup("Hunt the Fallen Failed", alert_text + "\n\n(Chapter wide loyalty: -10)\nChaplains note marked changes in behaviour of some brothers", "fallen", ""); - obj_controller.loyalty -= 10; - obj_controller.loyalty_hidden -= 10; - remove_problem("fallen"); - scr_event_log("red", $"Mission Failed: Any Fallen within the {system.name} system have been given time to escape."); - }, - "provide_garrison": complete_garrison_mission, - }; - - for (var i = 0; i < array_length(problems); i++) { - var _problem = problems[i]; - if (_problem == "") { - continue; - } - - if (struct_exists(problem_functions, _problem)) { - try { - var _problem_action = method(self, problem_functions[$ _problem]); - _problem_action(i); - } catch (_exception) { - ERROR_HANDLER.handle_exception(_exception); - } - } + return ""; } } @@ -264,25 +148,25 @@ function scr_new_governor_mission(planet, problem = "") { if (p_owner[planet] != eFACTION.IMPERIUM) { exit; } - var planet_type = p_type[planet]; + var _planet_type = p_type[planet]; if (problem == "") { - if (planet_type == "Death") { + if (_planet_type == "Death") { problem = choose("hunt_beast", "provide_garrison"); - } else if (planet_type == "Hive") { - problem = choose("show_of_power", "provide_garrison", "purge_enemies", "raid_black_market"); - } else if (planet_type == "Temperate") { + } else if (_planet_type == "Hive") { + problem = choose("show_of_power", "provide_garrison", "governor_purge_enemies", "raid_black_market"); + } else if (_planet_type == "Temperate") { problem = choose("provide_garrison", "train_forces", "join_parade"); - } else if (planet_type == "Shrine") { + } else if (_planet_type == "Shrine") { problem = choose("provide_garrison", "join_communion"); - } else if (planet_type == "Ice") { + } else if (_planet_type == "Ice") { problem = choose("provide_garrison", "hunt_beast"); - } else if (planet_type == "Lava") { + } else if (_planet_type == "Lava") { problem = choose("provide_garrison", "protect_raiders"); - } else if (planet_type == "Agri") { + } else if (_planet_type == "Agri") { problem = choose("provide_garrison", "protect_raiders", "recover_artifacts"); - } else if (planet_type == "Desert") { + } else if (_planet_type == "Desert") { problem = choose("provide_garrison", "protect_raiders", "recover_artifacts"); - } else if (planet_type == "Feudal") { + } else if (_planet_type == "Feudal") { problem = choose("hunt_beast", "protect_raiders"); } } @@ -291,30 +175,8 @@ function scr_new_governor_mission(planet, problem = "") { applicant: "Governor", }; if (problem != "") { - if (problem == "provide_garrison") { - if (get_garrison(planet).garrison_force) { - exit; - } - mission_data.reason = choose("stability", "importance"); - } else if (problem == "purge_enemies") { - var enemy = 0; - if (planets > 1) { - for (var i = 1; i <= planets; i++) { - if (i == planet) { - continue; - } - if (p_owner[i] == eFACTION.IMPERIUM) { - enemy = i; - break; - } - } - } - mission_data.target = enemy; - if (!enemy) { - exit; - } - } - add_new_problem(planet, problem, 20 + irandom(20),, mission_data); + var _p_data = get_planet_data(planet); + _p_data.new_problem(problem, 20 + irandom(20),mission_data); } } @@ -325,135 +187,19 @@ function init_marine_acting_strange() { exit; } - var unit = fetch_unit(marine_and_company); - if (!is_struct(unit)) { + var _unit = fetch_unit(marine_and_company); + if (!is_struct(_unit)) { exit; } - var role = unit.role(); - var text = unit.name_role(); - var company_text = scr_convert_company_to_string(unit.company); - if (company_text != "") { - company_text = $"({company_text})"; - text += company_text; - } - text += " is behaving strangely."; - scr_alert("color", "lol", text, 0, 0); - scr_event_log("color", text); -} - -function init_garrison_mission(planet, star, mission_slot) { - var problems_data = star.p_problem_other_data[planet]; - var mission_data = problems_data[mission_slot]; - if (mission_data.stage == "preliminary") { - var numeral_name = planet_numeral_name(planet, star); - mission_data.stage = "active"; - var garrison_length = 10 + irandom(6); - star.p_timer[planet][mission_slot] = garrison_length; - var gar_pop = instance_create(0, 0, obj_popup); - //TODO some new universal methods for popups - gar_pop.title = $"Requested Garrison Provided to {numeral_name}"; - gar_pop.text = $"The governor of {numeral_name} Thanks you for considering his request for a garrison, you agree that the garrison will remain for at least {garrison_length} months."; - gar_pop.add_option("Commence Garrison"); - gar_pop.image = ""; - gar_pop.cooldown = 8; - obj_controller.cooldown = 8; - scr_event_log("", $"Garrison committed to {numeral_name} for {garrison_length} months.", star.name); - } -} - -function init_beast_hunt_mission(planet, star, mission_slot) { - var problems_data = star.p_problem_other_data[planet]; - var mission_data = problems_data[mission_slot]; - if (mission_data.stage == "preliminary") { - var numeral_name = planet_numeral_name(planet, star); - mission_data.stage = "active"; - var _mission_length = irandom_range(2, 5); - star.p_timer[planet][mission_slot] = _mission_length; - var gar_pop = instance_create(0, 0, obj_popup); - //TODO some new universal methods for popups - gar_pop.title = $"Marines assigned to hunt beasts around {numeral_name}"; - gar_pop.text = $"The govornor of {numeral_name} Thanks you for the participation of your elite warriors in your execution of such a menial task."; - gar_pop.add_option("Happy Hunting"); - gar_pop.image = ""; - gar_pop.cooldown = 8; - obj_controller.cooldown = 20; - scr_event_log("", $"Beast hunters deployed to {numeral_name} for {_mission_length} months.", star.name); - } -} - -function init_protect_raider_mission(squad) { - var _squad_units = squad.members; - var _squad_wisdom = stat_average(_squad_units, "wisdom"); - var _squad_dex = stat_average(_squad_units, "dexterity"); - var _tester = global.character_tester; - - var _pdata = selection_data.system.get_planet_data(selection_data.planet); - var _mod = _squad_wisdom + _squad_dex / 20; - if (scr_has_adv("Ambushers")) { - _mod += 10; - } - - var _leader = squad.determine_leader(); - if (!is_struct(_leader)) { - return; - } - var _wis_test = _tester.standard_test(_leader, "wisdom", _mod, ["ambush"]); - - if (!_wis_test[0]) { - if (_wis_test[1] < -25) { - scr_toggle_manage(); - var gar_pop = instance_create(0, 0, obj_popup); - gar_pop.title = $"Strange Disappearance"; - gar_pop.pdata = _pdata; - gar_pop.text = $"Your Marines make planet fall and are directed to report to the governor for the duration of the operation after a period of reconnaissance dig in for their ambush. After a two weeks have passed A message from the governor reaches your astropaths that your marines have not been heard of for some time, The raiders also were not noted to have arrived onor left the planet"; - var _dead_marine = array_random_index(_squad_units); - for (var i = 0; i < array_length(_dead_marine); i++) { - if (i == _dead_marine) { - continue; - } - - var _marine = _dead_marine[i]; - - _marine.location_string = "Lost"; - _marine.ship_location = -1; - _marine.planet_location = 0; - } - gar_pop.text += $"After eventual investigation it appears the eldar anticipated the would be ambushers and turned the tides. {_squad_units[_dead_marine].name_role()}s body is eventually discovered some way off from the main battle his rent armour and body showing the extent of combat that must have occured"; - - gar_pop.text += "\nThe total loss of a squad in what was meant to be a routine operation is bad for moral and your chapters reputation you must now decide how to proceed"; - - gar_pop.add_option({str1: "Suppress the Information", choice_func: protect_raiders_suppress_information}); - - gar_pop.add_option({str1: "Hold a Memorial", choice_func: protect_raiders_hold_memorial}); - } else { - scr_toggle_manage(); - var gar_pop = instance_create(0, 0, obj_popup); - gar_pop.title = $"Ineffective Ambush"; - gar_pop.text = $"Your Marines Are ineffective at setting up an ambush the assailants clearly got wind of the operation or the plan was otherwise so ill thought out that by the time your forces arrived there was little that could be done to intercept them"; - gar_pop.text += $""; - gar_pop.pathway = "protect_raiders_ineffective"; - gar_pop.pdata = _pdata; - _pdata.add_disposition(-10); - gar_pop.text += "\nThe governor is unhappy and it has done little to improve your reputation with the planets populace but otherwise very little harm has been done. It is likely the raiders will choose better targets without the possible threat of space marine presence for the foreseeable future\nGovernor Disposition : -10"; - - gar_pop.add_option("continue"); - } - } else { - instance_create(0, 0, obj_ncombat); - obj_ncombat.enemy = eFACTION.ELDAR; - obj_ncombat.battle_object = selection_data.system; - obj_ncombat.battle_loc = selection_data.system.name; - obj_ncombat.battle_id = selection_data.planet; - obj_ncombat.battle_special = "protect_raiders"; - _roster = new Roster(); - with (_roster) { - selected_units = _squad_units; - setup_battle_formations(); - add_to_battle(); - } - exit_adhoc_manage(); - delete _roster; + var _text = _unit.name_role(); + var _company_text = scr_convert_company_to_string(_unit.company); + if (_company_text != "") { + _company_text = $"({_company_text})"; + _text += _company_text; } + _text += " is behaving strangely."; + scr_alert("color", "lol", _text, 0, 0); + scr_event_log("color", _text); } /// @self Asset.GMObject.obj_popup @@ -490,303 +236,6 @@ function protect_raiders_hold_memorial() { text = $"You prepare to have a large public memorial for your fallen marines on the planet surface as a show of defiance. The chapter are pleased by such an act and the population of the planet are mesmerized by the spectacle. The governor is furious not only has his incompetence to deal with the planets xenos issue been made public in such a way that the sector commander has now heard about it but he perceives his failures are being paraded in font of him\n nGovernor Disposition : -30"; } -function init_train_forces_mission(planet, star, mission_slot, marine) { - var _pdata = star.get_planet_data(planet); - var mission_data = _pdata.problems_data[mission_slot]; - if (mission_data.stage == "preliminary") { - var numeral_name = _pdata.name(); - mission_data.stage = "active"; - var _mission_length = irandom_range(3, 12); - star.p_timer[planet][mission_slot] = _mission_length; - //pop.image="ancient_ruins"; - var gar_pop = instance_create(0, 0, obj_popup); - //TODO some new universal methods for popups - gar_pop.title = $"Training forces on {numeral_name} begins"; - gar_pop.text = $"{marine.name_role()} Has taken leave of his current post in order to aid the governor of {numeral_name} and his pdf commanders with training local forces and bolstering defences."; - var _is_cap = marine.has_role(eROLE.CAPTAIN); - - if (_is_cap) { - gar_pop.text += "the governor seems to be impressed that such a high ranking officer has been assigned to his request (disp +3)"; - _pdata.add_disposition(3); - } - - //pip.image="event_march" - gar_pop.add_option($"Good luck {marine.name()}"); - gar_pop.image = ""; - gar_pop.cooldown = 500; - obj_controller.cooldown = 500; - scr_event_log("", $"{marine.name_role()} deployed to {numeral_name} for {_mission_length} months.", star.name); - } -} - -/// @self Asset.GMObject.obj_star -function complete_garrison_mission(problem_index) { - if (problem_timers[problem_index] > 0) { - return; - } - var _problem_data = problems_data[problem_index]; - if (!struct_has_value(_problem_data, "stage", "active")) { - remove_problem("provide_garrison"); - return; - } - - garrisons.update(); - if (current_owner != eFACTION.IMPERIUM || !garrisons.garrison_force) { - remove_problem("provide_garrison"); - add_disposition(-20); - scr_popup($"Agreed Garrison of {name()}", $"your agreed garrison of {name()} was cut short by your chapter the planetary governor has expressed his displeasure (disposition -20)", "", ""); - return; - } - - var _mission_string = $"The garrison on {name()} has finished the period of garrison support agreed with the planetary governor."; - var _result = garrisons.garrison_disposition_change(); - if (!garrisons.garrison_leader) { - garrisons.find_leader(); - } - - var _effect = 0; - if (_result == "none") { - //TODO make a dedicated plus minus string function if there isn't one already - } else if (_result < 0) { - _effect = _result * irandom_range(1, 5); - _mission_string += $"A number of diplomatic incidents occured over the period which had considerable negative effects on our disposition with the planetary governor (disposition -{_effect})"; - } else { - _effect = _result * irandom_range(1, 5); - _mission_string += $"As a diplomatic mission the duration of the stay was a success with our political position with the planet being enhanced greatly (disposition +{_effect})"; - } - - add_disposition(_effect); - var tester = global.character_tester; - var widom_test = tester.standard_test(garrisons.garrison_leader, "wisdom", 0, ["siege"]); - - if (widom_test[0]) { - alter_fortification(1); - _mission_string += $"while stationed {garrisons.garrison_leader.name_role()} makes several notable observations and is able to instruct the planets defense core leaving the world better defended (fortifications+1)."; - } - //TODO just generall apply this each turn with a garrison to see if a cult is found - if (has_feature(eP_FEATURES.GENE_STEALER_CULT)) { - var cult = get_features(eP_FEATURES.GENE_STEALER_CULT)[0]; - if (cult.hiding) { - widom_test = tester.standard_test(garrisons.garrison_leader, "wisdom", 0, ["tyranids"]); - if (widom_test[0]) { - cult.hiding = false; - _mission_string += "Most alarmingly signs of a genestealer cult are noted by the garrison. how far the rot has gone will now need to be investigated and the xenos taint purged."; - } - } - } - scr_popup($"Agreed Garrison of {name()} complete", _mission_string, "", ""); - - remove_problem("provide_garrison"); -} - -function complete_train_forces_mission(targ_planet, problem_index) { - var planet = get_planet_data(targ_planet); - if (problem_has_key_and_value(targ_planet, problem_index, "stage", "active")) { - var man_conditions = { - "job": "train_forces", - "max": 1, - }; - var _mission_string = ""; - var _trainer = collect_role_group("all", [planet.system.name, targ_planet, 0], false, man_conditions); - if (array_length(_trainer)) { - var _unit_report_string = ""; - var _tester = global.character_tester; - var _wis_test_difficulty = -20; - _trainer = _trainer[0]; - var _tyannic_vet = _trainer.has_trait("tyrannic_vet"); - if (_tyannic_vet) { - _wis_test_difficulty += 10; - if (planet.has_feature(eP_FEATURES.GENE_STEALER_CULT)) { - var _cult = planet.get_features(eP_FEATURES.GENE_STEALER_CULT)[0]; - if (_cult.hiding) { - planet.delete_feature(eP_FEATURES.GENE_STEALER_CULT); - _mission_string += $"Fortune has smiled on this mission, {_trainer.name_role()}'s abilities as a Veteran of dealing with the Tyranids came in handy and in a short period was able to discern the existencee of a cult. He was able to organise those he considered to be still loyal to rally an extermiation of the cult, reeports suggest he was so successful as to have completely wiped the genestealer presence from the planet"; - } - } - } - var _siege_master = _trainer.has_trait("siege_master"); - if (_siege_master) { - _wis_test_difficulty += 10; - } - var _brute = _trainer.has_trait("brute"); - if (_brute) { - _wis_test_difficulty -= 10; - } - - var _leader = _trainer.has_trait("natural_leader"); - if (_leader) { - _wis_test_difficulty += 10; - } - - var _unit_pass = _tester.standard_test(_trainer, "wisdom", _wis_test_difficulty); - if (_unit_pass[0]) { - var _new_pdf = planet.recruit_pdf((_unit_pass[1] / 10)); //this will approximate podf improvement for the time being - _mission_string += $"Training of the Pdf went well and improved the quality of the pdf as well as providing sizeable big recruitment improvement for the planet {_new_pdf} new pdf were recruited"; - if (_leader) { - var _disp_gain = 10; - planet.add_disposition(_disp_gain); - _mission_string += $"\n{_trainer.name_role()}s reputation a natural and confident leader proved well earned as he also made excellent diplomatic headway with the governor and his generals (disposition +{_disp_gain})"; - } - if (_siege_master) { - _mission_string += $"{_trainer.name()}s trained eye as a Siege Master also allowed him to make several improvements to the planets fortifications (fortification +1)"; - planet.alter_fortification(1); - } else { - if (roll_dice(1, 100) > 75 && _trainer.intelligence > 45) { - _mission_string += $"{_trainer.name()} has proven themselves a great strategist when it comes to defensive structures beyond previousy known "; - var _start_stats = variable_clone(_trainer.get_stat_line()); - _trainer.add_trait("siege_master"); - var end_stat = _trainer.get_stat_line(); - var _stat_diff = compare_stats(end_stat, _start_stats); - _unit_report_string += $"{_trainer.name_role()} Has gained the trait {global.trait_list.siege_master.display_name}, {print_stat_diffs(_stat_diff)}\n"; - _mission_string += "The new insights have allowed for minor improvements to planetary fortifications (fortification +1)"; - planet.alter_fortification(1); - } - } - } else { - disp_loss = -5; - _mission_string += "The orgional training mission was a failiure"; - if (_brute) { - _mission_string += "in no short part due to his brutish nature"; - } - _mission_string += "."; - - _mission_string += "He failed to work effectively with the existing chain of command"; - - if (_unit_pass[1] < -20) { - var _hard_loss_traits = [ - "harshborn", - "feral", - "zealous_faith", - "blood_for_blood", - "blunt", - "brute", - "brawler", - ]; - var _hard_loss = false; - for (var i = 0; i < array_length(_hard_loss_traits); i++) { - if (array_contains(_trainer.traits, _hard_loss_traits[i])) { - _hard_loss = true; - } - } - if (_hard_loss) { - _mission_string += $"His particularly grueling regimes and standards imposed upon the senior officers of the pdf caused friction with physical injury being caused to one officer"; - disp_loss = -25; - _mission_string += "(disposition -25)"; - } - } - planet.add_disposition(disp_loss); - } - _mission_string += $"\n{_unit_report_string}"; - scr_popup($"Training Forces on {planet.name()}", _mission_string, "", ""); - remove_planet_problem(targ_planet, "train_forces"); - _trainer.job = "none"; - } - } -} - -function complete_beast_hunt_mission(targ_planet, problem_index) { - var planet = get_planet_data(targ_planet); - if (problem_has_key_and_value(targ_planet, problem_index, "stage", "active")) { - var _mission_string = ""; - var man_conditions = { - "job": "hunt_beast", - "max": 3, - }; - var _hunters = collect_role_group("all", [planet.system.name, targ_planet, 0], false, man_conditions); - var _success = false; - var _tester = global.character_tester; - var _unit_pass; - var _unit; - var _unit_report_string = ""; - var _deaths = 0; - var _successful_hunters = []; - if (!array_length(_hunters)) { - remove_planet_problem(targ_planet, "hunt_beast"); - return; - } - for (var i = 0; i < array_length(_hunters); i++) { - _unit = _hunters[i]; - _unit_pass = _tester.standard_test(_unit, "weapon_skill", 10, ["beast"]); - if (_unit_pass[0]) { - if (!_success) { - _success = true; - } - } - if (_unit_pass[0]) { - _unit_report_string += _unit.add_trait("beast_slayer", true, true); - array_push(_successful_hunters, _unit); - } else { - var _tough_check = _tester.standard_test(_unit, "constitution", _unit.luck); - if (!_tough_check[0]) { - if (_tough_check[1] < -10) { - _unit_report_string += $"{_unit.name_role()} Was mauled to death\n"; - _unit.kill(true, false); - _deaths++; - } else if (_tough_check[1] >= -10) { - if (irandom(100) < _unit.luck) { - _unit.add_or_sub_health(-100); - _unit_report_string += $"{_unit.name_role()} Was injured (health - 100)\n"; - } else { - _unit.add_or_sub_health(-250); - _unit_report_string += $"{_unit.name_role()} Was Badly injured, it is unknown if he will recover (health - 250)\n"; - } - } - } - } - _unit.job = "none"; - } - if (_success) { - _mission_string = $"The mission was a success and a great number of beasts rounded up and slain, your marines were able to gain great skills and the prestige of your chapter has increased greatly across the planets populace."; - if (_deaths) { - _mission_string += $"Unfortunatly {_deaths} of your marines died."; - } - _mission_string += $"\n{_unit_report_string}"; - } else { - _mission_string = $"The mission was a failiure. The governor is disapointed and the legend of your chapter has undoubtedly been diminished"; - _mission_string += $"\n{_unit_report_string}"; - } - scr_popup($"Beast Hunt on {planet_numeral_name(i, id)}", _mission_string, "", ""); - remove_planet_problem(targ_planet, "hunt_beast"); - } else { - remove_planet_problem(targ_planet, "hunt_beast"); - } -} - -//TODO allow most of these functions to be condensed and allow arrays of problems or planets and maybe increase filtering options -//filtering options could be done via universal methods that all the filters to be passed to many other game systems -/// @self Asset.GMObject.obj_star -function has_any_problem_planet(planet, star = noone) { - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] != "") { - return true; - } - } - } else { - with (star) { - return has_any_problem_planet(planet); - } - } - return false; -} - -/// @self Asset.GMObject.obj_star -function planet_problemless(planet, star = noone) { - var _problemless = true; - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] != "") { - _problemless = false; - break; - } - } - } else { - with (star) { - _problemless = planet_problemless(planet); - } - } - return _problemless; -} // returns a bool for if any planet on a given star has the given problem /// @self Asset.GMObject.obj_star @@ -794,7 +243,7 @@ function has_problem_star(problem, star = noone) { var has_problem = false; if (star == noone) { for (var i = 1; i <= planets; i++) { - has_problem = has_problem_planet(i, problem); + has_problem = get_planet_data(i).has_problem(problem); if (has_problem) { has_problem = true; break; @@ -808,74 +257,6 @@ function has_problem_star(problem, star = noone) { return has_problem; } -//returns a bool for if a planet has a given problem -/// @self Asset.GMObject.obj_star -function has_problem_planet(planet, problem, star = noone) { - if (star == noone) { - return array_contains(p_problem[planet], problem); - } else { - with (star) { - return has_problem_planet(planet, problem); - } - } -} - -//returns the array position of a given problem on a given planet if the specfied time is given -/// @self Asset.GMObject.obj_star -function has_problem_planet_and_time(planet, problem, time, star = noone) { - var _had_problem = -1; - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] == problem) { - if (p_timer[planet][i] == time) { - _had_problem = i; - } - } - } - } else { - with (star) { - _had_problem = has_problem_planet_and_time(planet, problem, time); - } - } - return _had_problem; -} - -//returns the array position of a given problem on a given planet if the specfied time is above 0 -/// @self Asset.GMObject.obj_star -function has_problem_planet_with_time(planet, problem, star = noone) { - var _had_problem = -1; - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] == problem) { - if (p_timer[planet][i] > 0) { - _had_problem = i; - } - } - } - } else { - with (star) { - _had_problem = has_problem_planet_with_time(planet, problem); - } - } - return _had_problem; -} - -//returns the array position of a gien problem on a given planet -/// @self Asset.GMObject.obj_star -function find_problem_planet(planet, problem, star = noone) { - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] == problem) { - return i; - } - } - } else { - with (star) { - return find_problem_planet(planet, problem); - } - } - return -1; -} ///removie all of a given problem from a planet /// @self Asset.GMObject.obj_star @@ -883,10 +264,8 @@ function remove_planet_problem(planet, problem, star = noone) { var _had_problem = false; if (star == noone) { for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] == problem) { - p_problem[planet][i] = ""; - p_timer[planet][i] = -1; - p_problem_other_data[planet][i] = {}; + if (p_problem[planet][i].p_id == problem) { + array_delete(p_problem[planet],i, 1); _had_problem = true; } } @@ -898,23 +277,6 @@ function remove_planet_problem(planet, problem, star = noone) { return _had_problem; } -//find an open problem slot on a given planet -/// @self Asset.GMObject.obj_star -function open_problem_slot(planet, star = noone) { - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] == "") { - return i; - } - } - } else { - with (star) { - return open_problem_slot(planet); - } - } - return -1; -} - //remove all of a given problem types from a star /// @self Asset.GMObject.obj_star function remove_star_problem(problem, star = noone) { @@ -929,75 +291,30 @@ function remove_star_problem(problem, star = noone) { } } -//count donw the p_timer on a given planet -/// @self Asset.GMObject.obj_star -function problem_count_down(planet, count_change = 1) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] != "") { - p_timer[planet][i] -= count_change; - if (p_timer[planet][i] == -5) { - p_problem[planet][i] = ""; - p_timer[planet][i] = -1; - } - } - } -} +/// @self struct.PlanetData | Asset.GMObject.obj_star +function generic_problems_to_mission_log (){ + var _logs = []; + for (var p = 0; p < array_length(problems); p++) { + var _problem = problems[p]; -//add a new problem -/// @self Asset.GMObject.obj_star -function add_new_problem(planet, problem, timer, star = noone, other_data = {}) { - var problem_added = false; - if (star == noone) { - for (var i = 0; i < array_length(p_problem[planet]); i++) { - if (p_problem[planet][i] == "") { - p_problem[planet][i] = problem; - p_problem_other_data[planet][i] = other_data; - p_timer[planet][i] = timer; - problem_added = true; - break; - } - } - } else { - with (star) { - problem_added = add_new_problem(planet, problem, timer, noone, other_data); + if (_problem.stage_id == "preliminary") { + continue; } - } - return problem_added; -} + var _mission_explain = _problem.description(); + var _data = { + system: is_callable(name) ? name() : name, + mission: _mission_explain, + time: _problem.timer, + problem : _problem, + }; -/// @self Asset.GMObject.obj_star -function increment_mission_completion(mission_data) { - if (!struct_exists(mission_data, "completion")) { - mission_data.completion = 0; - } - mission_data.completion++; - if (!struct_exists(mission_data, "required_months") || mission_data.required_months <= 0) { - LOGGER.error("Invalid required_months in mission_data"); - return 0; - } - return (mission_data.completion / mission_data.required_months) * 100; -} + _data.click_left = method(_data, function() { + set_map_pan_to_loc(problem.system); + }); -//search problem data for a given and key and iff applicable value on that key -//TODO increase filtering and search options -/// @self Asset.GMObject.obj_star -function problem_has_key_and_value(planet, problem, key, value = "", star = noone) { - var has_data = false; - if (star == noone) { - var problem_data = p_problem_other_data[planet][problem]; - if (struct_exists(problem_data, key)) { - if (value == "") { - has_data = true; - } else if (problem_data[$ key] == value) { - has_data = true; - } - } - } else { - with (star) { - has_data = problem_has_key_and_value(planet, problem, key, value); - } + array_push(_logs, _data); } - return has_data; + return _logs; } /// @desc Compares two location arrays to determine if they represent the same place. diff --git a/scripts/scr_mission_reward/scr_mission_reward.gml b/scripts/scr_mission_reward/scr_mission_reward.gml index c673ffb77d..93fed9e8ef 100644 --- a/scripts/scr_mission_reward/scr_mission_reward.gml +++ b/scripts/scr_mission_reward/scr_mission_reward.gml @@ -99,143 +99,5 @@ function scr_mission_reward(mission, star, planet) { sort_all_companies_to_map(cleanup); } - if (mission == "mech_raider") { - var roll1 = roll_dice_chapter(1, 100, "low"); - var result = ""; - - if (roll1 <= 33) { - result = "New"; - } - if ((roll1 > 33) && (roll1 <= 66)) { - result = "Land Raider"; - } - if (roll1 > 66) { - result = "Requisition"; - } - - if (result == "New") { - scr_popup("Mechanicus Mission Completed", $"Your {obj_ini.player_role_data[eROLE.TECHMARINE].role} have worked with the Adeptus Mechanicus in a satisfactory manor. The testing and training went well, but your Land Raider was ultimately lost. 300 Requisition has been given to your Chapter and relations are better than before.", "mechanicus", ""); - obj_controller.requisition += 300; - obj_controller.disposition[3] += 2; - var onceh = 0; - for (var com = 0; com <= 10; com++) { - if (onceh == 0) { - for (var i = 1; i <= 100; i++) { - if ((obj_ini.veh_role[com][i] == "Land Raider") && (obj_ini.veh_loc[com][i] == star.name) && (obj_ini.veh_wid[com][i] == planet)) { - onceh = 1; - obj_ini.veh_race[com][i] = 0; - obj_ini.veh_loc[com][i] = ""; - obj_ini.veh_role[com][i] = ""; - obj_ini.veh_lid[com][i] = -1; - obj_ini.veh_wid[com][i] = 0; - obj_ini.veh_wep1[com][i] = ""; - obj_ini.veh_wep2[com][i] = ""; - obj_ini.veh_wep3[com][i] = ""; - obj_ini.veh_upgrade[com][i] = ""; - obj_ini.veh_acc[com][i] = ""; - obj_ini.veh_hp[com][i] = 0; - obj_ini.veh_chaos[com][i] = 0; - obj_ini.veh_uid[com][i] = 0; - cleanup[com] = 1; - star.p_player[planet] -= 20; - } - } - } else { - break; - } - } - } - if (result == "Land Raider") { - scr_popup("Mechanicus Mission Completed", "Your " + string(obj_ini.player_role_data[eROLE.TECHMARINE].role) + " have worked with the Adeptus Mechanicus in a satisfactory manor. The testing and training went well, but your Land Raider was ultimately lost. A new Land Raider has been provided in return.", "mechanicus", ""); - var onceh = 0; - obj_controller.disposition[3] += 1; - for (var com = 0; com <= 10; com++) { - if (onceh == 0) { - for (var i = 1; i <= 100; i++) { - if ((obj_ini.veh_role[com][i] == "Land Raider") && (obj_ini.veh_loc[com][i] == star.name) && (obj_ini.veh_wid[com][i] == planet)) { - onceh = 1; - obj_ini.veh_hp[com][i] = 100; - } - } - } else { - break; - } - } - } - if (result == "Requisition") { - scr_popup("Mechanicus Mission Completed", "Your " + string(obj_ini.player_role_data[eROLE.TECHMARINE].role) + " have worked with the Adeptus Mechanicus in a satisfactory manor. The testing and training went well, but your Land Raider was ultimately lost. 600 Requisition has been given to your Chapter as compensation.", "mechanicus", ""); - obj_controller.requisition += 600; - obj_controller.disposition[3] += 1; - } - - for (var i = 0; i <= 10; i++) { - if (cleanup[i] == 1) { - obj_controller.temp[3000] = real(i); - with (obj_ini) { - scr_vehicle_order(obj_controller.temp[3000]); - } - } - } - } - cleanup = array_create(11, 0); - - if (mission == "mech_bionics") { - var roll1 = roll_dice_chapter(1, 100, "low"); - var result = ""; - - if (roll1 <= 33) { - result = "Requisition"; - } - if ((roll1 > 33) && (roll1 <= 66)) { - result = "Bionics"; - } - if (roll1 > 66) { - result = "Marines Lost"; - } - mech_disp_change = 0; - var _text = "The Adeptus Mechanicus have finished experimenting on your marines"; - var _marines = collect_role_group("all", [star.name, planet, -1], false, {}, true); - if (result == "Marines Lost") { - _text += "- unfortunantly none of them have survived. 150 Requisition has provided as weregild for each Astartes lost."; - mech_disp_change = 2; - obj_controller.requisition += 150 * _marines.number(); - _marines.kill_percent(100); - } else if (result == "Bionics" || result == "Requisition") { - obj_controller.disposition[3] += 1; - mech_disp_change = 1; - - if (result == "Bionics") { - var _new_bionics = irandom_range(40, 100); - scr_add_item("Bionics", _new_bionics); - _text += $" A large amount of additional Bionics have been provided by the Mechanicus as a reward ( X{_new_bionics} Bionics added to stocks)"; - } else if (result == "Requisition") { - req_gain = irandom_range(200, 650); - _text += $"{req_gain} Requisition has been provided by the Mechanicus as a reward."; - obj_controller.requisition += req_gain; - } - var _limit = 0; - for (var i = 0; i < array_length(_marines.units); i++) { - var _unit = _marines.units[i]; - if (_unit.bionics > 0) { - _unit.update_health(irandom_range(2, 80)); - - if (!_unit.has_trait("flesh_is_weak")) { - _unit.update_loyalty(-20); - } - - repeat (choose(2, 3, 4)) { - _unit.add_bionics(); - } - _limit++; - } - if (_limit >= 10) { - break; - } - } - } - _text += $"\n mechanics Disposition {mech_disp_change > 0 ? "+" : "-"}{mech_disp_change}"; - scr_popup("Mechanicus Mission Completed", _text, "mechanicus"); - sort_all_companies_to_map(cleanup); - } } diff --git a/scripts/scr_player_fleet_combat_functions/scr_player_fleet_combat_functions.gml b/scripts/scr_player_fleet_combat_functions/scr_player_fleet_combat_functions.gml index 5fc48549c2..ca3d2d46a0 100644 --- a/scripts/scr_player_fleet_combat_functions/scr_player_fleet_combat_functions.gml +++ b/scripts/scr_player_fleet_combat_functions/scr_player_fleet_combat_functions.gml @@ -3,7 +3,7 @@ function add_fleet_ships_to_combat(fleet, combat) { var capital_count = array_length(fleet.capital); var _ship_id; - var _ships = fleet_full_ship_array(fleet); + var _ships = fleet.full_ship_array(); var _ship_array_length = array_length(_ships); for (var i = 0; i < _ship_array_length; i++) { try { diff --git a/scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml b/scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml index b432dced29..b1b6acd3fc 100644 --- a/scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml +++ b/scripts/scr_player_fleet_functions/scr_player_fleet_functions.gml @@ -1,5 +1,5 @@ function fleet_has_roles(fleet, roles = []) { - var all_ships = fleet_full_ship_array(fleet); + var all_ships = fleet.full_ship_array(); for (var i = 0; i <= 10; i++) { for (var s = 0; s < array_length(obj_ini.TTRPG[i]); s++) { var unit = fetch_unit([i, s]); @@ -17,17 +17,21 @@ function fleet_has_roles(fleet, roles = []) { } } -function fleet_engaged(fleet) { - var _engaged = false; - var _fleet_action = fleet.action; - if (_fleet_action != "" && _fleet_action != "move") { - //don't inspect if engaged in non negotiable actions - if (array_contains(global.fleet_move_options, _fleet_action)) { - _engaged = true; - } + +/// @desc Creates a new player fleet, registering at the nearest star if within 50px. +/// @param {Real} _x +/// @param {Real} _y +/// @param {Array} _ships Optional array of ship IDs to add to the fleet +/// @returns {Id.Instance.obj_p_fleet} +function create_player_fleet(_x, _y, _ships = []) { + var _fleet = instance_create(_x, _y, obj_p_fleet); + _fleet.owner = eFACTION.PLAYER; + fleet_register_at_nearest_star(_fleet); + for (var _i = 0; _i < array_length(_ships); _i++) { + add_ship_to_fleet(_ships[_i], _fleet); } - return _engaged; + return _fleet; } function split_selected_into_new_fleet(start_fleet) { @@ -137,7 +141,7 @@ function find_and_move_ship_between_fleets(out_fleet, in_fleet, index) { } function merge_player_fleets(main_fleet, merge_fleet) { - var _merge_ships = fleet_full_ship_array(merge_fleet); + var _merge_ships = merge_fleet.full_ship_array(); for (var i = 0; i < array_length(_merge_ships); i++) { if (_merge_ships[i] < array_length(obj_ini.ship)) { @@ -451,41 +455,8 @@ function player_retreat_from_fleet_combat(destination_star = noone) { } } -function fleet_full_ship_array(fleet = noone, exclude_capitals = false, exclude_frigates = false, exclude_escorts = false) { - var all_ships = []; - var _ship_count = array_length(obj_ini.ship); - if (fleet == noone) { - if (!exclude_capitals) { - for (var i = 0; i < array_length(capital_num); i++) { - if (capital_num[i] < _ship_count) { - array_push(all_ships, capital_num[i]); - } - } - } - if (!exclude_frigates) { - for (var i = 0; i < array_length(frigate_num); i++) { - if (frigate_num[i] < _ship_count) { - array_push(all_ships, frigate_num[i]); - } - } - } - if (!exclude_escorts) { - for (var i = 0; i < array_length(escort_num); i++) { - if (escort_num[i] < _ship_count) { - array_push(all_ships, escort_num[i]); - } - } - } - } else { - with (fleet) { - all_ships = fleet_full_ship_array(); - } - } - return all_ships; -} - function set_fleet_location(location) { - var fleet_ships = fleet_full_ship_array(); + var fleet_ships = full_ship_array(); for (var i = 0; i < array_length(fleet_ships); i++) { var temp = fleet_ships[i]; if (temp >= 0 && temp < array_length(obj_ini.ship_location)) { @@ -605,9 +576,7 @@ function get_nearest_player_fleet(nearest_x, nearest_y, is_static = false, is_mo } } if (stop_complex_actions) { - if (string_count("crusade", action) || action == "Lost") { - viable = false; - } + viable = !beyond_engagement; } if (!viable) { continue; @@ -625,17 +594,6 @@ function get_nearest_player_fleet(nearest_x, nearest_y, is_static = false, is_mo return chosen_fleet; } -/// @self Asset.GMObject.obj_star -function has_orbiting_player_fleet() { - if (instance_exists(obj_p_fleet)) { - var _nearest = instance_nearest(x, y, obj_p_fleet); - if (point_distance(_nearest.x, _nearest.y, x, y) == 0) { - return true; - } - } - return false; -} - function calculate_fleet_content_size(ship_array) { var total_content = 0; for (var i = 0; i < array_length(ship_array); i++) { @@ -657,3 +615,73 @@ function calculate_fleet_bombard_score(ship_array) { } return bomb_score; } + +function player_fleet_end_turn(){ +try { + + for (var i = 0; i < array_length(problems); i++){ + problems[i].basic_turn_end(); + } + acted = 0; + if (action == "Lost") { + set_fleet_location("Lost"); + exit; + } else if (action == "") { + var spid = instance_nearest(x, y, obj_star); + fleet_register_at_star(self, spid); + + if (instance_exists(orbiting)) { + if (orbiting.visited == 0) { + 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); + } + } + } + orbiting.visited = 1; + } + + meet_system_governors(orbiting); + } + } else if (action == "move") { + set_fleet_location("Warp"); + + if (instance_nearest(action_x, action_y, obj_star).storm > 0) { + exit; + } + + var spid = point_distance(x, y, action_x, action_y); + spid = spid / action_eta; + var dir = point_direction(x, y, action_x, action_y); + + x = x + lengthdir_x(spid, dir); + y = y + lengthdir_y(spid, dir); + + action_eta -= 1; + just_left = false; + + if (action_eta == 0){ + action = ""; + x = action_x; + y = action_y; + fleet_is_orbiting(); + if (orbiting != noone){ + arrived_at_star(); + } else { + set_fleet_location("Near " + instance_nearest(x, y,obj_star).name); + } + + if (array_length(complex_route) > 0) { + arrive_at_waypoint(); + } else { + for (var i = 0; i < array_length(problems); i++){ + problems[i].on_final_arrival(); + } + } + } + } +} catch (_exception) { + ERROR_HANDLER.handle_exception(_exception); +} +} diff --git a/scripts/scr_player_ship_functions/scr_player_ship_functions.gml b/scripts/scr_player_ship_functions/scr_player_ship_functions.gml index 831be96c1f..56b05da108 100644 --- a/scripts/scr_player_ship_functions/scr_player_ship_functions.gml +++ b/scripts/scr_player_ship_functions/scr_player_ship_functions.gml @@ -180,7 +180,7 @@ function loose_ship_to_warp_event() { } var _fleet = array_random_element(eligible_fleets); - var _ships = fleet_full_ship_array(_fleet); + var _ships = _fleet.full_ship_array(); var _ship_index = array_random_element(_ships); var text = "The "; @@ -226,6 +226,7 @@ function loose_ship_to_warp_event() { } _lost_ship_fleet.action = "Lost"; + _lost_ship_fleet.beyond_engagement = false; fleet_unregister_from_star(_lost_ship_fleet); _lost_ship_fleet.alarm[1] = 2; diff --git a/scripts/scr_popup_functions/scr_popup_functions.gml b/scripts/scr_popup_functions/scr_popup_functions.gml index b0e896894e..04bfe66533 100644 --- a/scripts/scr_popup_functions/scr_popup_functions.gml +++ b/scripts/scr_popup_functions/scr_popup_functions.gml @@ -9,6 +9,7 @@ enum ePOPUP_TYPE { ITEM_GIFT = 9, ADD_TAGS = 12, SYSTEM_DEBUG = 13, + PLAYER_FLEETDEBUG = 14, BATTLE_OPTIONS = 98, FLEET_MOVE = 99, } @@ -495,7 +496,7 @@ function default_popup_image_index() { _img = 21; } else if (image == "webber") { _img = 22; - } else if (image == "spyrer") { + } else if (image == "inquisition_spyrer") { _img = 23; } else if (image == "fortress") { _img = 24; diff --git a/scripts/scr_post_battle_events/scr_post_battle_events.gml b/scripts/scr_post_battle_events/scr_post_battle_events.gml index 6969acb2d6..f5e94e1aac 100644 --- a/scripts/scr_post_battle_events/scr_post_battle_events.gml +++ b/scripts/scr_post_battle_events/scr_post_battle_events.gml @@ -1,118 +1,10 @@ -/// @self Asset.GMObject.obj_ncombat -/// @desc Resolves Necron Tomb combat and resumes or completes the mission. -/// @returns {Undefined} -function necron_tomb_raid_post_battle_sequence() { - if (!string_count("wake", battle_special)) { - if (defeat == 1) { - obj_controller.combat = 0; - obj_controller.cooldown = 10; - obj_turn_end.alarm[1] = 4; - } else if (defeat == 0) { - obj_controller.combat = 0; - var pip = instance_create(0, 0, obj_popup); - pip.pop_data = battle_data; - - with (pip) { - necron_tomb_mission_start(); - var _completed = advance_necron_tomb_mission(); - if (_completed) { - keyboard_clear(vk_enter); - } else { - text = "The last of the attackers is cut down. Your marines regroup in the tunnel and ready themselves to press deeper into the complex.\n\n" + text; - } - number = pop_data.number; - } - } - } else { - var pip = instance_create(0, 0, obj_popup); - with (pip) { - title = "Necron Tomb Awakens"; - image = "necron_army"; - if (obj_ncombat.defeat == 0) { - text = "Your marines make a tactical retreat back to the surface, hounded by Necrons all the way. The Inquisition mission is a failure- you were to blow up the Necron Tomb World stealthily, not wake it up. The Inquisition is not pleased with your conduct."; - } else { - text = "Your marines are killed down to the last man. The Inquisition mission is a failure- you were to blow up the Necron Tomb World stealthily, not wake it up. The Inquisition is not pleased with your conduct."; - } - } - - var _star_obj = find_star_by_name(battle_loc); - if (_star_obj != noone) { - with (_star_obj) { - var planet = obj_ncombat.battle_id; - if (remove_planet_problem(planet, "necron")) { - p_necrons[planet] = 4; - } - if (awake_tomb_world(p_feature[planet]) == 0) { - awaken_tomb_world(p_feature[planet]); - } - } - } - - pip.pop_data = battle_data; - - alter_disposition(eFACTION.INQUISITION, -5); - obj_controller.combat = 0; - - with (pip) { - number = pop_data.number; - } - } -} - -/// @self Asset.GMObject.obj_ncombat -function protect_raiders_battle_aftermath() { - instance_activate_object(obj_star); - // show_message(obj_turn_end.current_battle); - // show_message(obj_turn_end.battle_world[obj_turn_end.current_battle]); - // title / text / image / speshul - var cur_star = battle_object; - var planet = battle_id; - var _planet = cur_star.get_planet_data(planet); - var _planet_string = _planet.name(); - _planet.remove_problem("protect_raiders"); - if (!defeat) { - _planet.add_disposition(15); - var tixt = $"The Raiding forces on {_planet_string} have been removed. The citizens and craftsman may sleep more soundly. (planet disp +15)"; - - scr_popup("Planet Protected", tixt, "protect_raiders", ""); - scr_event_log("", $"Governor Request completed: Raiding forces on {_planet_string} have been eliminated.", cur_star.name); - } else { - _planet.add_disposition(-15); - var tixt = $"The Raiding forces on {_planet_string} dispatched with your forces and will continue with their bloody practices. The citizens remain unsafe and the governor is unimpressed. (planet disp -15)"; - scr_popup("Planet Protected", tixt, "protect_raiders", ""); - - scr_event_log("", $"Governor Request failed: Raiding forces on {_planet_string} continue to harrass population.", cur_star.name); - } - instance_deactivate_object(obj_star); -} - -/// @self Asset.GMObject.obj_ncombat -function hunt_fallen_battle_aftermath() { - if (!defeat) { - with (obj_turn_end) { - remove_planet_problem(battle_world[current_battle], "fallen", battle_object[current_battle]); - var tixt = "The Fallen on " + battle_object[current_battle].name; - tixt += scr_roman(battle_world[current_battle]); - scr_event_log("", $"Mission Succesful: {tixt} have been captured or purged."); - tixt += $" have been captured or purged. They shall be brought to the Chapter {obj_ini.player_role_data[eROLE.CHAPLAIN].role}s posthaste, in order to account for their sins. "; - var _tex_options = [ - "Suffering is the beginning to penance.", - "Their screams shall be the harbringer of their contrition.", - "The shame they inflicted upon us shall be written in their flesh.", - ]; - tixt += _tex_options[choose(0, 0, 1, 2)]; - scr_popup("Hunt the Fallen Completed", tixt, "fallen", ""); - } - } -} - function space_hulk_explore_battle_aftermath() { if (!defeat && hulk_treasure > 0) { var shi = 0, loc = ""; var shiyp = instance_nearest(battle_object.x, battle_object.y, obj_p_fleet); if (shiyp.x == battle_object.x && shiyp.y == battle_object.y) { - shi = fleet_full_ship_array(shiyp)[0]; + shi = shiyp.full_ship_array()[0]; loc = obj_ini.ship[shi]; } diff --git a/scripts/scr_purge_world/scr_purge_world.gml b/scripts/scr_purge_world/scr_purge_world.gml index d1f7bdeef7..03627ba505 100644 --- a/scripts/scr_purge_world/scr_purge_world.gml +++ b/scripts/scr_purge_world/scr_purge_world.gml @@ -132,13 +132,43 @@ function PlayerPurge(action_type, action_score, planet_data) constructor { }; } +function log_ship_effort_purge(){ + if (instance_exists(obj_drop_select)) { + with (obj_drop_select) { + if (instance_exists(sh_target)) { + sh_target.acted = 5; + } + instance_destroy(); + } + } +} + /// @self Struct.PlanetData function scr_purge_world(action_type, action_score) { - var _purge = new PlayerPurge(action_type, action_score, self); - var _isquest = 0; - var _thequest = ""; - var _questnum = 0; + var _mission_override = false; + for (var i = 0; i < array_length(problems); i++){ + var _prob = problems[i]; + if (!_prob.has_func("on_purge")){ + continue; + } + if (!_prob.has_data("purge_type")){ + continue; + } + if (_prob.data.purge_type == action_type){ + _prob.purge_data = { + action_type, + action_score, + } + _mission_override = true; + _prob.on_purge(); + } + } + if (_mission_override){ + log_ship_effort_purge(); + exit; + } + var _purge = new PlayerPurge(action_type, action_score, self); var _popup_text = ""; _purge.pop_before = population_as_small(); @@ -215,109 +245,59 @@ function scr_purge_world(action_type, action_score) { if (action_type == eDROP_TYPE.PURGEFIRE) { // Burn baby burn - var i = 0; - if (has_problem("cleanse")) { - _isquest = true; - _thequest = "cleanse"; - _questnum = i; - } + // TODO add more variation, with planets, features, marine equipment perhaps? + _popup_text = choose($"Timing their visits right, Your forces scour {name()} burning down whatever the local heretic communities call their homes. Their screams were quickly extinguished by fire, turning whatever it was before, into ash.", $"Your forces scour {name()}, burning homes and towns that reek of heresy. The screams and wails of the damned carry through the air."); - if (_isquest) { - if (_thequest == "cleanse" && action_score >= 20) { - remove_problem(_thequest); - - alter_disposition(eFACTION.INQUISITION, obj_controller.demanding ? choose(0, 0, 1) : 1); - - _popup_text = $"Your marines scour the underhive of {name()}, spraying mutants down with promethium as they go. It takes several days but a sizeable dent is put in their numbers."; - scr_event_log("", $"Inquisition Mission Completed: The mutants of {name()} have been cleansed by promethium."); - add_disposition(choose(1, 2, 3)); - } + var _nid_influence = population_influences[eFACTION.TYRANIDS]; + if (has_feature(eP_FEATURES.GENE_STEALER_CULT)) { + var cult = get_features(eP_FEATURES.GENE_STEALER_CULT)[0]; + if (cult.hiding) {} } else { - // TODO add more variation, with planets, features, marine equipment perhaps? - _popup_text = choose($"Timing their visits right, Your forces scour {name()} burning down whatever the local heretic communities call their homes. Their screams were quickly extinguished by fire, turning whatever it was before, into ash.", $"Your forces scour {name()}, burning homes and towns that reek of heresy. The screams and wails of the damned carry through the air."); - - var nid_influence = population_influences[eFACTION.TYRANIDS]; - if (has_feature(eP_FEATURES.GENE_STEALER_CULT)) { - var cult = get_features(eP_FEATURES.GENE_STEALER_CULT)[0]; - if (cult.hiding) {} - } else { - if (nid_influence > 25) { - _popup_text += " Scores of mutant offspring from a genestealer infestation are burnt, while we have damaged their influence over this world, the mutants appear to lack the organisation of a true cult"; - adjust_influence(eFACTION.TYRANIDS, -10, planet, system); - } else if (nid_influence > 0) { - _popup_text += " There are signs of a genestealer infestation but the cultists are too unorganized to do any real damage to their influence on this world"; - } + if (_nid_influence > 25) { + _popup_text += " Scores of mutant offspring from a genestealer infestation are burnt, while we have damaged their influence over this world, the mutants appear to lack the organisation of a true cult"; + adjust_influence(eFACTION.TYRANIDS, -10, planet, system); + } else if (_nid_influence > 0) { + _popup_text += " There are signs of a genestealer infestation but the cultists are too unorganized to do any real damage to their influence on this world"; } - - _popup_text += _purge.population_death_string(); } - } - if (action_type == eDROP_TYPE.PURGESELECTIVE) { - // Blam! - var i = 0; - if (has_problem("purge")) { - _isquest = 1; - _thequest = "purge"; - _questnum = i; - } + _popup_text += _purge.population_death_string(); - if (_isquest == 1) { - if (_thequest == "purge" && action_score >= 10) { - remove_problem("purge"); + } - alter_disposition(eFACTION.INQUISITION, obj_controller.demanding ? choose(0, 0, 1) : 1); + if (action_type == eDROP_TYPE.PURGESELECTIVE) { + // TODO add more variation, with planets, features, possibly marine equipment + _popup_text = $"Your marines move across {name()},"; + _popup_text += choose($"searching for high profile targets. Once found, they are dragged outside from their lairs. Their execution would soon follow.", $"rooting out sources of corruption. Heretics are dragged from their lairs and executed in the streets."); - _popup_text = "Your marines drop fast and hard, blowing through guards and mercenaries with minimal resistance. Before ten minutes have passed all your targets are executed."; - scr_event_log("", $"Inquisition Mission Completed: The unruly Nobles of {name()} have been purged."); - add_disposition(choose(1, 2, 3)); - } - } else if (_isquest == 0) { - // TODO add more variation, with planets, features, possibly marine equipment - _popup_text = $"Your marines move across {name()},"; - _popup_text += choose($"searching for high profile targets. Once found, they are dragged outside from their lairs. Their execution would soon follow.", $"rooting out sources of corruption. Heretics are dragged from their lairs and executed in the streets."); + _popup_text += _purge.population_death_string(); - _popup_text += _purge.population_death_string(); - } } if (action_type == eDROP_TYPE.PURGEASSASSINATE) { assasinate_governor_setup(action_score); } else if (action_type != eDROP_TYPE.PURGEASSASSINATE) { - if (_isquest == 0) { - // DO EET - var _txt2 = _popup_text; - switch (_purge.heres_target) { - case "corruption": - alter_corruption(-_purge.influence_reduction); - break; - case "tau": - alter_influence(eFACTION.TAU, -_purge.influence_reduction); - break; - case "genestealers": - alter_influence(eFACTION.TYRANIDS, -_purge.influence_reduction); - break; - } - set_population(population_large_conversion(_purge.pop_after)); - - var pip = instance_create(0, 0, obj_popup); - pip.title = "Purge Results"; - pip.text = _txt2; - } - if (_isquest) { - // DO EET - var pip = instance_create(0, 0, obj_popup); - scr_popup("Inquisition Mission Completed", _popup_text, "inquisition"); + // DO EET + var _txt2 = _popup_text; + switch (_purge.heres_target) { + case "corruption": + alter_corruption(-_purge.influence_reduction); + break; + case "tau": + alter_influence(eFACTION.TAU, -_purge.influence_reduction); + break; + case "genestealers": + alter_influence(eFACTION.TYRANIDS, -_purge.influence_reduction); + break; } - } - if (instance_exists(obj_drop_select)) { - with (obj_drop_select) { - if (instance_exists(sh_target)) { - sh_target.acted = 5; - } - instance_destroy(); - } + set_population(population_large_conversion(_purge.pop_after)); + + var _pip = instance_create(0, 0, obj_popup); + _pip.title = "Purge Results"; + _pip.text = _txt2; + } + log_ship_effort_purge(); } diff --git a/scripts/scr_random_event/scr_random_event.gml b/scripts/scr_random_event/scr_random_event.gml index f0cd21c6a8..e19a9badfa 100644 --- a/scripts/scr_random_event/scr_random_event.gml +++ b/scripts/scr_random_event/scr_random_event.gml @@ -219,18 +219,18 @@ function scr_random_event(execute_now) { LOGGER.info("RE: Space Hulk"); var own = choose(1, 1, 2); - var star_id = scr_random_find(own, true, "", ""); - if (star_id == noone && own == 1) { + var _star_id = scr_random_find(own, true, "", ""); + if (_star_id == noone && own == 1) { // find the nearest star to a player fleet and user that one, dukecode did that // we could also try to find to find another star but this one is owned by the imperium and not the player, this code is doing that own = 2; - star_id = scr_random_find(own, true, "", ""); + _star_id = scr_random_find(own, true, "", ""); } - if (star_id == noone && own == 2) { - star_id = scr_random_find(0, true, "", ""); // try for litteraly any star + if (_star_id == noone && own == 2) { + _star_id = scr_random_find(0, true, "", ""); // try for litteraly any star } - if (star_id == noone) { + if (_star_id == noone) { LOGGER.error("RE: Space Hulk, couldn't find a star for the spacehulk"); exit; } else { @@ -238,26 +238,26 @@ function scr_random_event(execute_now) { var spaceHulkX, spaceHulkY, tries_to_place_space_hulk; tries_to_place_space_hulk = 0; while (!positionFound && tries_to_place_space_hulk < 50) { - spaceHulkX = star_id.x + (choose(-1, 1) * irandom_range(50, 60)); - spaceHulkY = star_id.y + (choose(-1, 1) * irandom_range(50, 80)); + spaceHulkX = _star_id.x + (choose(-1, 1) * irandom_range(50, 60)); + spaceHulkY = _star_id.y + (choose(-1, 1) * irandom_range(50, 80)); spaceHulkY = max(spaceHulkY, 40); - var distanceToNearestStarOk = point_distance(spaceHulkX, spaceHulkY, instance_nearest(spaceHulkX, spaceHulkY, obj_star).x, instance_nearest(spaceHulkX, spaceHulkY, obj_star).y) >= 70; - if (distanceToNearestStarOk) { + var _distanceToNearestStarOk = point_distance(spaceHulkX, spaceHulkY, instance_nearest(spaceHulkX, spaceHulkY, obj_star).x, instance_nearest(spaceHulkX, spaceHulkY, obj_star).y) >= 70; + if (_distanceToNearestStarOk) { positionFound = true; } tries_to_place_space_hulk++; } if (tries_to_place_space_hulk >= 50) { // its possible for there to be no good spot for the space hulk at a star, if there are too many stars in close proximity - LOGGER.error($"RE: Space Hulk, couldn't find a spot for the spacehulk at the {star_id.name} system"); + LOGGER.error($"RE: Space Hulk, couldn't find a spot for the spacehulk at the {_star_id.name} system"); exit; } try { var spaceHulk = scr_create_space_hulk(spaceHulkX, spaceHulkY); - scr_alert(own ? "red" : "green", "space_hulk", $"The Space Hulk {spaceHulk.name} appears near the {star_id.name} system.", spaceHulkX, spaceHulkY); + scr_alert(own ? "red" : "green", "space_hulk", $"The Space Hulk {spaceHulk.name} appears near the {_star_id.name} system.", spaceHulkX, spaceHulkY); - scr_event_log("", $"The Space Hulk {spaceHulk.name} appears near the {star_id.name} system.", star_id.name); + scr_event_log("", $"The Space Hulk {spaceHulk.name} appears near the {_star_id.name} system.", _star_id.name); _evented = true; } catch (_exception) { ERROR_HANDLER.handle_exception(_exception); @@ -277,15 +277,10 @@ function scr_random_event(execute_now) { LOGGER.error("RE: Promotion, couldn't pick a space marine"); exit; } - var role = _unit.role(); - var text = _unit.name_role(); - var company_text = scr_convert_company_to_string(company); - //var company_text = scr_company_string(company); - if (company_text != "") { - company_text = "(" + company_text + ")"; - } - text += company_text; - text += " has distinguished himself.##He åis up for review to be promoted."; + var _text = _unit.name_role(); + var _company_text = $"({scr_convert_company_to_string(company)})"; + _text += _company_text; + _text += " has distinguished himself.##He åis up for review to be promoted."; if (company != 10) { _unit.add_exp(10); @@ -293,8 +288,8 @@ function scr_random_event(execute_now) { _unit.add_exp(max(20, _unit.experience)); } - scr_popup("Promotions!", text, "distinguished", ""); - scr_event_log("green", text); + scr_popup("Promotions!", _text, "distinguished", ""); + scr_event_log("green", _text); _evented = true; } else if (chosen_event == eEVENT.STRANGE_BUILDING) { _evented = strange_build_event(); @@ -302,36 +297,36 @@ function scr_random_event(execute_now) { LOGGER.info("RE: Sororitas Company"); var own; own = choose(1, 2); - var star_id = scr_random_find(own, true, "", ""); + var _star_id = scr_random_find(own, true, "", ""); - if (star_id == noone && own == 1) { + if (_star_id == noone && own == 1) { own = 2; - star_id = scr_random_find(own, true, "", ""); + _star_id = scr_random_find(own, true, "", ""); } - if (star_id == noone) { + if (_star_id == noone) { LOGGER.error("RE: Sororitas Company, couldn't find a star for the company"); exit; } else { var eligible_planets = []; - for (var i = 1; i <= star_id.planets; i++) { - if (star_id.p_type[i] != "Dead") { + for (var i = 1; i <= _star_id.planets; i++) { + if (_star_id.p_type[i] != "Dead") { array_push(eligible_planets, i); } } if (array_length(eligible_planets) == 0) { - LOGGER.error("RE: Sororitas Company, couldn't find a planet on the " + star_id.name + " system for the company"); + LOGGER.error("RE: Sororitas Company, couldn't find a planet on the " + _star_id.name + " system for the company"); exit; } - var planet = eligible_planets[irandom(array_length(eligible_planets) - 1)]; - ++star_id.p_sisters[planet]; + var _planet = _star_id.get_planet_data(array_random_element(eligible_planets)); + _planet.add_forces(eFACTION.ECCLESIARCHY, 1); _evented = true; - if ((own != 1) && (star_id.p_player[planet] <= 0) && (star_id.present_fleet[1] == 0)) { - scr_alert("green", "sororitas", "Sororitas place a company of sisters on " + string(star_id.name) + " " + string(planet) + ".", star_id.x, star_id.y); + if ((own != 1) && (_planet.player_forces <= 0) && (_star_id.present_fleet[1] == 0)) { + scr_alert("green", "sororitas", $"Sororitas place a company of sisters on {_planet.name()}.", _star_id.x, _star_id.y); } else { - scr_popup("Sororitas", "The Ecclesiarchy have placed a company of sisters on " + string(star_id.name) + " " + string(planet) + ".", "sororitas", ""); + scr_popup("Sororitas", $"The Ecclesiarchy have placed a company of sisters on {_planet.name()}.", "sororitas", ""); if (known[eFACTION.ECCLESIARCHY] == 0) { known[eFACTION.ECCLESIARCHY] = 1; // this seesms like a thing another part of code already does, not sure tho } @@ -433,26 +428,22 @@ function scr_random_event(execute_now) { } } else if (chosen_event == eEVENT.HARLEQUINS) { LOGGER.info("RE: Harlequins"); - var owner = choose(1, 2, 2, 2, 3); - var star = scr_random_find(owner, true, "", ""); - if (!instance_exists(star) && owner != 2) { - owner = 2; - star = scr_random_find(owner, true, "", ""); + var _owner = choose(1, 2, 2, 2, 3); + var _star = scr_random_find(_owner, true, "", ""); + if (!instance_exists(_star) && _owner != 2) { + _owner = 2; + _star = scr_random_find(_owner, true, "", ""); } - if (!instance_exists(star)) { + if (!instance_exists(_star)) { LOGGER.error("RE: Harlequins, couldn't find star"); exit; } - var planet = irandom_range(1, star.planets); - if (add_new_problem(planet, "harlequins", irandom_range(2, 5), star)) { - var text = "Eldar Harlequins have been seen on planet " + string(star.name) + " " + scr_roman(planet) + ". Their purposes are unknown."; - scr_popup("Harlequin Troupe", text, "harlequin", ""); - var star_alert = instance_create(star.x + 16, star.y - 24, obj_star_event); - star_alert.image_alpha = 1; - star_alert.image_speed = 1; - star_alert.col = "green"; - } + var _planet = irandom_range(1, _star.planets); + var _pdata = _star.get_planet_data(_planet); + _pdata.new_problem("harlequins", irandom_range(2, 5)); + + } else if (chosen_event == eEVENT.SUCCESSION_WAR) { LOGGER.info("RE: Succession War"); var eligible_stars = []; @@ -557,25 +548,25 @@ function scr_random_event(execute_now) { own = choose(1, 1, 2, 0, 0); } - var star_id = scr_random_find(own, true, "", ""); - if (star_id == noone && own == 1) { + var _star_id = scr_random_find(own, true, "", ""); + if (_star_id == noone && own == 1) { own = 2; - star_id = scr_random_find(own, true, "", ""); + _star_id = scr_random_find(own, true, "", ""); } - if (star_id == noone && own == 2) { + if (_star_id == noone && own == 2) { own = 0; - star_id = scr_random_find(own, true, "", ""); + _star_id = scr_random_find(own, true, "", ""); } - if (star_id == noone) { + if (_star_id == noone) { LOGGER.error("RE: Warp Storm, couldn't pick a star for the warp storm"); exit; } else { - star_id.storm += time; + _star_id.storm += time; _evented = true; var _col = own == 1 ? "red" : "green"; - scr_alert(_col, "Warp", $"Warp Storms rage across the {star_id.name} system.", star_id.x, star_id.y); - scr_event_log(_col, $"Warp Storms rage across the {star_id.name} system."); + scr_alert(_col, "Warp", $"Warp Storms rage across the {_star_id.name} system.", _star_id.x, _star_id.y); + scr_event_log(_col, $"Warp Storms rage across the {_star_id.name} system."); } } else if (chosen_event == eEVENT.ENEMY_FORCES) { LOGGER.info("RE: Enemy Forces"); @@ -588,67 +579,67 @@ function scr_random_event(execute_now) { own = choose(1, 1, 1, 2, 2, 3); } - var star_id = scr_random_find(own, true, "", ""); - if (star_id == noone && own == 1) { + var _star_id = scr_random_find(own, true, "", ""); + if (_star_id == noone && own == 1) { own = 2; - star_id = scr_random_find(own, true, "", ""); + _star_id = scr_random_find(own, true, "", ""); } - if (star_id == noone && own == 2) { + if (_star_id == noone && own == 2) { own = 3; - star_id = scr_random_find(own, true, "", ""); + _star_id = scr_random_find(own, true, "", ""); } - if (star_id == noone) { + if (_star_id == noone) { LOGGER.error("RE: Enemy Forces, couldn't find a star for the enemy"); exit; } else { var eligible_planets = []; - for (var i = 1; i <= star_id.planets; i++) { - if (star_id.p_type[i] != "Dead") { + for (var i = 1; i <= _star_id.planets; i++) { + if (_star_id.p_type[i] != "Dead") { array_push(eligible_planets, i); } } if (array_length(eligible_planets) == 0) { - LOGGER.error("RE: Enemy Forces, couldn't find a planet in the " + star_id.name + " system for the enemy"); + LOGGER.error("RE: Enemy Forces, couldn't find a planet in the " + _star_id.name + " system for the enemy"); exit; } var planet = eligible_planets[irandom(array_length(eligible_planets) - 1)]; //var enemy = choose(7,8,9,10,13); var enemy = choose(7, 8, 9); var text; - var max_enemies_on_planet = 5; // I don't know the actual value, i need to change it; + var max_enemies_on_planet = 6; // I don't know the actual value, i need to change it; switch (enemy) { case 7: text = "Orks"; - star_id.p_orks[planet] += 4; - star_id.p_orks[planet] = min(star_id.p_orks[planet], max_enemies_on_planet); + _star_id.p_orks[planet] += 4; + _star_id.p_orks[planet] = min(_star_id.p_orks[planet], max_enemies_on_planet); break; case 8: text = "Tau"; - star_id.p_tau[planet] += 4; - star_id.p_tau[planet] = min(star_id.p_tau[planet], max_enemies_on_planet); + _star_id.p_tau[planet] += 4; + _star_id.p_tau[planet] = min(_star_id.p_tau[planet], max_enemies_on_planet); break; case 9: text = "Tyranids"; - star_id.p_tyranids[planet] += 5; - star_id.p_tyranids[planet] = min(star_id.p_tyranids[planet], max_enemies_on_planet); + _star_id.p_tyranids[planet] += 5; + _star_id.p_tyranids[planet] = min(_star_id.p_tyranids[planet], max_enemies_on_planet); break; //case 10: this doesn't work // text = "Heretics"; - // star_id.p_heretics[planet] = 4; - // star_id.p_heretics[planet] = min(star_id.p_heretics[planet], max_enemies_on_planet); + // _star_id.p_heretics[planet] = 4; + // _star_id.p_heretics[planet] = min(_star_id.p_heretics[planet], max_enemies_on_planet); // break; //case 13: // text = "Necron"; // I don't know if its a good idea to spawn necrons from this event, leaving it in for now - // star_id.p_necron[planet] = 4; - // star_id.p_necron[planet] = min(star_id.p_necron[planet], max_enemies_on_planet); + // _star_id.p_necron[planet] = 4; + // _star_id.p_necron[planet] = min(_star_id.p_necron[planet], max_enemies_on_planet); // break; default: LOGGER.error("RE: Enemy Forces, couldn't pick an enemy faction"); exit; } - scr_alert("red", "enemy", $"{text} forces suddenly appear at {star_id.name} {planet}!", star_id.x, star_id.y); - scr_event_log("red", $"{text} forces suddenly appear at {star_id.name} {planet}!"); + scr_alert("red", "enemy", $"{text} forces suddenly appear at {_star_id.name} {planet}!", _star_id.x, _star_id.y); + scr_event_log("red", $"{text} forces suddenly appear at {_star_id.name} {planet}!"); _evented = true; } } else if (chosen_event == eEVENT.CRUSADE) { @@ -719,7 +710,24 @@ function scr_random_event(execute_now) { } else if (chosen_event == eEVENT.NECRON_AWAKEN) { _evented = awaken_tomb_event(); } else if (chosen_event == eEVENT.FALLEN) { - event_fallen(); + LOGGER.info("RE: Hunt the Fallen"); + var stars = scr_get_stars(); + var valid_stars = scr_get_stars(false, [eFACTION.IMPERIUM]); + + if (array_length(valid_stars) == 0) { + LOGGER.error("RE: Hunt the Fallen, coulnd't find a star"); + exit; + } + LOGGER.info($"Fallen: valid_stars {valid_stars}"); + + var star = array_random_element(stars); + var planet = scr_get_planet_with_owner(star, eFACTION.IMPERIUM); + + if (planet > 0 && instance_exists(star)) { + var _p_data = star.get_planet_data(planet); + var _eta = scr_mission_eta(star.x, star.y, 1); + _p_data.new_problem("hunt_fallen",_eta); + } _evented = true; } @@ -740,23 +748,3 @@ function scr_random_event(execute_now) { //with(obj_en_fleet){if (x<-10000){x+=20000;y+=20000;}} //with(obj_star){if (x<-10000){x+=20000;y+=20000;}} } - -function event_fallen() { - LOGGER.info("RE: Hunt the Fallen"); - var stars = scr_get_stars(); - var valid_stars = scr_get_stars(false, [eFACTION.IMPERIUM]); - - if (array_length(valid_stars) == 0) { - LOGGER.error("RE: Hunt the Fallen, coulnd't find a star"); - exit; - } - LOGGER.info($"Fallen: valid_stars {valid_stars}"); - - var star = choose_array(stars); - var planet = scr_get_planet_with_owner(star, eFACTION.IMPERIUM); - - if (planet > 0 && instance_exists(star)) { - var _p_data = star.get_planet_data(planet); - _p_data.init_fallen_marines(); - } -} diff --git a/scripts/scr_ruins_reward/scr_ruins_reward.gml b/scripts/scr_ruins_reward/scr_ruins_reward.gml index 4bd29b9e58..edef963171 100644 --- a/scripts/scr_ruins_reward/scr_ruins_reward.gml +++ b/scripts/scr_ruins_reward/scr_ruins_reward.gml @@ -112,10 +112,10 @@ function scr_ruins_reward(_star_system, _pid_idx, _ruins) { /// @param {Id.Instance.obj_popup} _popup static _process_artifact_reward = function(_star, _pidx, _popup) { var _chosen_ship = -1; - var _fleet = scr_orbiting_player_fleet(_star); + var _fleet = _star.get_orbiting_player_fleet(); if (instance_exists(_fleet)) { - var _ships = fleet_full_ship_array(_fleet); + var _ships = _fleet.full_ship_array(); if (array_length(_ships) > 0) { _chosen_ship = _ships[0]; } diff --git a/scripts/scr_shoot/scr_shoot.gml b/scripts/scr_shoot/scr_shoot.gml index 4ba3f2a3d0..79c9123a6d 100644 --- a/scripts/scr_shoot/scr_shoot.gml +++ b/scripts/scr_shoot/scr_shoot.gml @@ -495,6 +495,13 @@ function scr_shoot(weapon_index_position, target_object, target_type, damage_dat target_object.dudes_num[target_type] -= casualties; obj_ncombat.enemy_forces -= casualties; } + + obj_ncombat.register_kills_to_missions({ + number : casualties, + target : target_object, + target_type, + weapon : weapon_index_position < 0 ? "defences" : wep_title[weapon_index_position], + }); } } diff --git a/scripts/scr_squads/scr_squads.gml b/scripts/scr_squads/scr_squads.gml index 157e00bb1f..aa7cfcae0b 100644 --- a/scripts/scr_squads/scr_squads.gml +++ b/scripts/scr_squads/scr_squads.gml @@ -665,8 +665,13 @@ function UnitSquad(squad_type = undefined, company = 0) constructor { return data_pack; }; + static clean_members = function(){ + members = clean_unit_array(members); + }; + static get_members = function(as_UnitGroup = false) { var mems = []; + clean_members(); for (var i = 0; i < array_length(members); i++) { array_push(mems, fetch_member(i)); } diff --git a/scripts/scr_start_load/scr_start_load.gml b/scripts/scr_start_load/scr_start_load.gml index ed2d67ced5..7a31f65c53 100644 --- a/scripts/scr_start_load/scr_start_load.gml +++ b/scripts/scr_start_load/scr_start_load.gml @@ -108,7 +108,7 @@ function scr_start_load(fleet, load_from_star, load_options) { var company_squad_dist = total_distribute_squads[_comp - 2]; for (var squad = 0; squad < array_length(company_squad_dist); squad++) { var _squad = company_squad_dist[squad]; - var _members = _squad.members; + var _members = _squad.get_members(); for (var squad_member = 0; squad_member < array_length(_members); squad_member++) { var _marine = _members[squad_member]; var marine_size = _marine.get_unit_size(); diff --git a/scripts/scr_unit_quick_find_pane/scr_unit_quick_find_pane.gml b/scripts/scr_unit_quick_find_pane/scr_unit_quick_find_pane.gml index d9d45fa041..ed6786ea44 100644 --- a/scripts/scr_unit_quick_find_pane/scr_unit_quick_find_pane.gml +++ b/scripts/scr_unit_quick_find_pane/scr_unit_quick_find_pane.gml @@ -264,82 +264,14 @@ function UnitQuickFindPanel() constructor { update_mission_log = function() { mission_log = []; - var temp_log = []; + var _temp_log = []; with (obj_star) { - for (var i = 1; i <= planets; i++) { - var problems = p_problem[i]; - for (var p = 0; p < array_length(problems); p++) { - if (problems[p] == "") { - continue; - } - if (problem_has_key_and_value(i, p, "stage", "preliminary")) { - continue; - } - var mission_explain = mission_name_key(problems[p]); - if (mission_explain != "none") { - var _data = { - system: name, - mission: mission_explain, - time: p_timer[i][p], - planet: i, - system_id: id, - }; - - _data.click_left = method(_data, function() { - set_map_pan_to_loc(system_id); - }); - - array_push(temp_log, _data); - } - } - } + _temp_log = array_concat(_temp_log, problems_to_mission_log()); } - with (obj_en_fleet) { - if (array_length(events)) { - for (var i = 0; i < array_length(events); i++) { - var _event = events[i]; - if (struct_exists(_event, "turn_end")) { - switch (_event.turn_end) { - //this is being pre seeded for a later coming feature set - case "deliver_trophy_end_turn_check": - var _mission = localize("Deliver Trophy Guard"); - var _sys = fleets_next_location(); - var _mission_data = { - mission: _mission, - system: _sys.name, - system_id: _sys.id, - target: id, - important_person: _event.fleetevent_data.trophy_owner, - person_name: _event.fleetevent_data.delivering_marine, - planet: 0, - start_system: _event.fleetevent_data.system, - time: _event.timer, - }; - - _mission_data.click_left = method(_mission_data, function() { - set_map_pan_to_loc(system_id); - }); - - _mission_data.hover = method(_mission_data, function() { - tooltip_draw(localize("You are to have {0} deliver trophy hunted on {1} to the {1} regiments\n\nLeft click to see target fleet intercept system right click to view the trophy bearing marine {0}", [person_name, start_system])); - }); - - _mission_data.click_right = method(_mission_data, function() { - var _unit = fetch_unit_uid(important_person); - if (is_struct(_unit)) { - var _unit_l = [_unit]; - group_selection(_unit_l); - } - }); - - array_push(temp_log, _mission_data); - break; - } - } - } - } + with (obj_p_fleet) { + _temp_log = array_concat(_temp_log, problems_to_mission_log()); } - mission_log = temp_log; + mission_log = _temp_log; var xx = main_panel.XX; var yy = main_panel.YY; var _data = {