@@ -431,6 +431,28 @@ function scr_efleet_arrive_at_trade_loc(){
431431}
432432
433433
434+ // / @function scr_orbiting_fleet(faction, system)
435+ // / @description Returns the ID of a fleet orbiting the given system/star that matches the specified faction.
436+ // / @param {any|array} faction
437+ // / The faction identifier to check against. Can be a single faction ID or an array of multiple factions.
438+ // / @param {any} [system="none"]
439+ // / The system instance or star to check. If `"none"`, the function uses the calling instance's position.
440+ // / @returns {real|string} The ID of the matching fleet instance, or `"none"` if no valid fleet is found.
441+ // /
442+ // / @example
443+ // / ```gml
444+ // / // Find a fleet orbiting this star that belongs to faction 3
445+ // / var fleet_id = scr_orbiting_fleet(3);
446+ // / if (fleet_id != "none") {
447+ // / show_debug_message("Faction fleet found: " + string(fleet_id));
448+ // / }
449+ // /
450+ // / // Find fleets from multiple factions
451+ // / var factions = [1, 2, 5];
452+ // / var fleet_id = scr_orbiting_fleet(factions, some_system);
453+ // / ```
454+ // /
455+
434456function scr_orbiting_fleet (faction, system=" none" ){
435457 var _found_fleet = " none" ;
436458 var _faction_list = is_array (faction);
@@ -455,19 +477,50 @@ function scr_orbiting_fleet(faction, system="none"){
455477 return _found_fleet;
456478}
457479
480+
481+ // / @function object_distance(obj_1, obj_2)
482+ // / @description Returns the distance in pixels between two instances or objects based on their `x` and `y` coordinates.
483+ // / @param {instance} obj_1 The first object or instance.
484+ // / @param {instance} obj_2 The second object or instance.
485+ // / @returns {real} The distance in pixels between `obj_1` and `obj_2`.
486+ // /
487+ // / @example
488+ // / ```gml
489+ // / var dist = object_distance(player, enemy);
490+ // / if (dist < 100) {
491+ // / show_debug_message("Enemy is within range!");
492+ // / }
493+ // / ```
494+ // /
495+
458496function object_distance (obj_1, obj_2){
459497 return (point_distance (obj_1.x , obj_1.y ,obj_2.x , obj_2.y ))
460498}
461499
500+
501+ // / @function scr_orbiting_player_fleet(system)
502+ // / @description Returns the ID of the nearest player fleet orbiting the given system or star.
503+ // / @param {any} [system="none"]
504+ // / The system instance or identifier to check. If `"none"`, the function checks the calling star instance.
505+ // / @returns {real} The instance ID of the orbiting player fleet, or -1 if none is found.
506+ // /
507+ // / @example
508+ // / ```gml
509+ // / var fleet_id = scr_orbiting_player_fleet();
510+ // / if (fleet_id != -1) {
511+ // / show_debug_message("Fleet orbiting star: " + string(fleet_id));
512+ // / }
513+ // / ```
514+ // /
462515function scr_orbiting_player_fleet (system = " none" ){
463- if (object_index == obj_star){
516+ if (system == " none " && !( is_struct (self)) && object_index == obj_star){
464517 var _fleet = instance_nearest (x, y, obj_p_fleet);
465- if (object_distance (self, _fleet) > 0 ){
518+ if (object_distance (self, _fleet) > 0 ){s
466519 return -1
467520 } else {
468521 return _fleet.id ;
469522 }
470- } else {
523+ } else if system != " none " {
471524 try {
472525 with (system){
473526 return scr_orbiting_player_fleet ();
@@ -477,6 +530,8 @@ function scr_orbiting_player_fleet(system = "none"){
477530 }
478531 }
479532
533+ return -1 ;
534+
480535}
481536
482537function get_orbiting_fleets (faction,system=" none" ){
0 commit comments