Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 168 additions & 144 deletions objects/obj_enunit/Alarm_0.gml
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
var __b__;
__b__ = action_if_number(obj_pnunit, 0, 2);
if __b__
{
{



if (!instance_exists(obj_pnunit)) {
exit;
}

var leftest,charge=0,enemy2=0,chapter_fuck=1,unit;
var leftest,charge=0,enemy2=0,target_unit_index=0,unit;

// with(obj_pnunit){if (x<-4000) or (defenses=1) then instance_deactivate_object(id);}

Expand Down Expand Up @@ -41,174 +36,205 @@ else if (flank=1){
}

//In melee check
engaged = point_distance(x,0,enemy.x,0)<=10 || !position_empty(x+flank?10:-10,y);
engaged = collision_point(x-10, y, obj_pnunit, 0, 1) || collision_point(x+10, y, obj_pnunit, 0, 1);

//show_debug_message($"enemy is in melee {engaged}")
// show_debug_message($"enemy is in melee {engaged}")

if (!engaged){ // Shooting

if (!engaged){// Shooting
var i=0,dist=999,block=0;
dist=get_block_distance(enemy);

var wall_exists=0;
if (instance_exists(obj_nfort)){
wall_exists=1;
dist=2;
}
/*with(obj_pnunit){if (veh_type[1]="Defenses") then instance_create(x,y,obj_temp_inq);}
if (instance_exists(obj_temp_inq)){
enemy=instance_nearest(obj_temp_inq.x,obj_temp_inq.y,obj_pnunit);
with(obj_temp_inq){instance_destroy();}
}*/
if (!instance_exists(obj_pnunit)) then exit;

for (var i=0;i<array_length(wep);i++){
if (wep[i]=="" || wep_num[i]==0) then continue;
chapter_fuck=1;
if (!instance_exists(obj_pnunit)) then exit;

if (wep[i]=="" || wep_num[i]==0) {
continue;
}

if ((range[i]==1) || (ammo[i]==0)) {
// show_debug_message($"A melee or no ammo weapon was found! Weapon: {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}; Range: {range[i]}; Ammo: {ammo[i]}");
continue;
}

if ((range[i]==0)) {
log_error($"{wep[i]} has broken range! This shouldn't happen! Range: {range[i]}; Ammo: {ammo[i]}; Owner: {wep_owner[i]}");
// show_debug_message($"A broken weapon was found! i:{i}; Weapon: {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}; Range: {range[i]}; Ammo: {ammo[i]}");
continue;
}

if (!target_block_is_valid(enemy,obj_pnunit)){
if (flank=0){
enemy=get_rightmost();
enemy2=enemy;
if (enemy=="none"){
exit;
}
dist=get_block_distance(enemy);
enemy = flank == 0 ? get_rightmost() : get_leftmost();
if (!target_block_is_valid(enemy,obj_pnunit)){
exit;
}
else if (flank=1){
enemy=get_leftmost();
enemy2=enemy;
if (enemy=="none"){
exit;
}
dist=get_block_distance(enemy);
}
}

if (target_block_is_valid(enemy,obj_pnunit)){
block=0;

if (instance_exists(obj_nfort)) and (obj_nfort.hp[1]>0){// Give the wall the melee D
enemy=instance_nearest(x,y,obj_nfort);
var bug1=instance_nearest(40,y,obj_enunit);
if (range[i]=1) and (bug1.id=self.id) then range[i]=2;
enemy2=enemy;
dist=2;
}

dist=get_block_distance(enemy);
target_unit_index=0;

if (range[i] >= dist) { // The weapon is in range;
var _target_vehicles = apa[i] > 0 ? true : false; // AP weapons target vehicles

// if (string_count("Gauss",wep[i])>0) then _target_vehicles=true;
// if (wep[i]="Missile Launcher") or (wep[i]="Rokkit Launcha") or (wep[i]="Kannon") then _target_vehicles=true;
// if (wep[i]="Big Shoota") then _target_vehicles=false;
// if (wep[i]="Devourer") then _target_vehicles=false;
// if (wep[i]="Gauss Particle Cannon") or (wep[i]="Overcharged Gauss Cannon") or (wep[i]="Particle Whip") then _target_vehicles=true;

if (wep_num[i]>0) and (range[i]>=dist) and (range[i]!=1) and (combi[i]<2) and (ammo[i]!=0){// Weapon meets preliminary checks

var _armour_piercing=0;
if (apa[i]>0) then _armour_piercing=1;// Determines if it is _armour_piercing or not
// if (string_count("Gauss",wep[i])>0) then _armour_piercing=1;

// show_message(string(wep[i])+" is in range and _armour_piercing:"+string(_armour_piercing));
// Weird alpha strike mechanic, that changes target unit index to CM;
if ((wep[i]="Power Fist") or (wep[i]="Bolter")) and (obj_ncombat.alpha_strike>0) and (wep_num[i]>5){
obj_ncombat.alpha_strike-=0.5;

if (wep[i]="Missile Launcher") or (wep[i]="Rokkit Launcha") or (wep[i]="Kannon") then _armour_piercing=1;
if (wep[i]="Big Shoota") then _armour_piercing=0;
if (wep[i]="Devourer") then _armour_piercing=0;
if (wep[i]="Gauss Particle Cannon") or (wep[i]="Overcharged Gauss Cannon") or (wep[i]="Particle Whip") then _armour_piercing=1;



if ((wep[i]="Power Fist") or (wep[i]="Bolter")) and (obj_ncombat.alpha_strike>0) and (wep_num[i]>5){
obj_ncombat.alpha_strike-=0.5;

var cm_present = false;
var cm_index = -1;
var cm_block = false;
with(obj_pnunit){
for (var u=0;u<array_length(unit_struct);u++){
if (marine_type[u]="Chapter Master"){
cm_present=true;
cm_index = u;
cm_block=id
}
var cm_present = false;
var cm_index = -1;
var cm_block = false;
with(obj_pnunit){
for (var u=0;u<array_length(unit_struct);u++){
if (marine_type[u]="Chapter Master"){
cm_present=true;
cm_index = u;
cm_block=id
}
}
if (cm_present){
enemy=cm_block;
chapter_fuck=cm_index;
}
}



if (_armour_piercing) and ((!instance_exists(obj_nfort)) or (flank)){// Check for vehicles
var enemy2,g=0,good=0;

if (cm_present){
enemy=cm_block;
target_unit_index=cm_index;
}
}


// AP weapons attacking vehicles and forts;
var _no_vehicles_present = false;
if (_target_vehicles) {
var _shot = false;
if (!instance_exists(obj_nfort)) or (flank) {
if (block_has_armour(enemy)) or (enemy.veh_type[1]=="Defenses"){
// good=scr_target(enemy,"veh");// First target has vehicles, blow it to hell
scr_shoot(i,enemy,chapter_fuck,"arp","ranged");
}
if (!good) and (instance_number(obj_pnunit)>1) and (obj_ncombat.enemy!=7){// First target does not have vehicles, cycle through objects to find one that has vehicles
scr_shoot(i,enemy,target_unit_index,"arp","ranged");
// show_debug_message($"I'm shooting at a vehicle! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
continue;
} else if (instance_number(obj_pnunit)>1) and (obj_ncombat.enemy!=7) {
var x2=enemy.x;
repeat(instance_number(obj_pnunit)-1){
if (good=0){
if (flank=0) then x2-=10;
if (flank=1) then x2+=10;
enemy2=instance_nearest(x2,y,obj_pnunit);
if (enemy2.veh+enemy2.dreads>0) and (good=0){
// good=scr_target(enemy2,"veh");// This target has vehicles, blow it to hell
scr_shoot(i,enemy2,chapter_fuck,"arp","ranged");
}
x2 += flank == 0 ? -10 : 10;
var enemy2=instance_nearest(x2,y,obj_pnunit);
if (!target_block_is_valid(enemy2, obj_pnunit)) {
continue;
}
if (range[i] < get_block_distance(enemy2)) {
break;
}
if (block_has_armour(enemy2)) {
scr_shoot(i,enemy2,target_unit_index,"arp","ranged");
// show_debug_message($"I'm shooting at a vehicle in another row! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
_shot = true;
break;
}
}
if (!_shot) {
_no_vehicles_present = true;
_target_vehicles = false;
}
}
if (good=0) then _armour_piercing=false;// Fuck it, shoot at infantry
}
if (_armour_piercing) and (instance_exists(obj_nfort)) and (!flank){// Huff and puff and blow the wall down
} else {
enemy=instance_nearest(x,y,obj_nfort);

scr_shoot(i,enemy,1,"arp","wall");
if (range[i] >= get_block_distance(enemy)) {
scr_shoot(i,enemy,1,"arp","wall");
// show_debug_message($"I'm shooting at the fort! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
continue;
}
}

// if (wall_exists=0) or (flank=1)


if (string_count("Gauss",wep[i])) then _armour_piercing=false;

// Shooting normal marines;
if ((!_armour_piercing) && ((!instance_exists(obj_nfort)) || flank) && instance_exists(obj_pnunit) && instance_exists(enemy)) {
if (enemy.men > 0) {
// There are marines in the first column;
if (target_block_is_valid(enemy, obj_pnunit)) {
scr_shoot(i, enemy, chapter_fuck, "att", "ranged");
}

// Non-AP weapons attacking normal units;
if ((!_target_vehicles) && ((!instance_exists(obj_nfort)) || flank)) {
var _shot = false;
if (enemy.men > 0) {
// There are marines in the first column;
scr_shoot(i, enemy, target_unit_index, "att", "ranged");
// show_debug_message($"I'm shooting at a normal unit! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
continue;
} else if (instance_number(obj_pnunit) > 1) {
// There were no marines in the first column, looking behind;
var _column_size_value = (enemy.veh * 2.5) + (enemy.dreads * 2) + (enemy.men * 0.5);
var x2 = enemy.x;

repeat (instance_number(obj_pnunit) - 1) {
x2 += !flank ? 10 : -10;
var enemy2 = instance_nearest(x2, y, obj_pnunit);
if (!target_block_is_valid(enemy2, obj_pnunit)) {
// show_debug_message($"The block is invalid!");
continue;
}
} else if (instance_number(obj_pnunit) > 1) {
if (enemy2.men > 0) {

if (range[i] < get_block_distance(enemy2)) {
// show_debug_message($"The range is bad!");
break;
}

var _back_column_size_value = (enemy2.veh * 2.5) + (enemy2.dreads * 2) + (enemy2.men * 0.5);
if (_back_column_size_value < _column_size_value) {
// show_debug_message($"Protection value is too big!");
continue;
} else {
// Calculate chance of shots passing through to back row
// Higher ratio of back column size to front column size increases pass-through chance
// Maximum chance capped at 40% to ensure some protection remains
var _pass_chance = ((_back_column_size_value / _column_size_value) - 1) * 100;
if (irandom_range(1, 100) < min(_pass_chance, 80)) {
// show_debug_message($"I failed the protection check!");
continue;
}
}
scr_shoot(i, enemy2, target_unit_index, "att", "ranged");
// show_debug_message($"I'm shooting at a normal unit in another row! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
_shot = true;
break;
}
}

// There were no marines in the first column, looking behind;
var enemy2;

var _column_size_value = (enemy.veh * 2.5) + (enemy.dreads * 2) + (enemy.men * 0.5);
var x2 = enemy.x;
x2 += !flank ? 10 : -10;

repeat (instance_number(obj_pnunit) - 1) {
enemy2 = instance_nearest(x2, y, obj_pnunit);

var _back_column_size_value = (enemy2.veh * 2.5) + (enemy2.dreads * 2) + (enemy2.men * 0.5);
if (_back_column_size_value < _column_size_value) {
continue;
} else {
// Calculate chance of shots passing through to back row
// Higher ratio of back column size to front column size increases pass-through chance
// Maximum chance capped at 60% to ensure some protection remains
var _pass_chance = ((_back_column_size_value / _column_size_value) - 1) * 100;
if (irandom_range(1, 100) > min(_pass_chance, 60)) {
// We failed to find normal units to attack, attacking vehicles with a non-AP weapon;
//TODO: All of these code blocks should be functions instead;
if (!_shot && !_no_vehicles_present) {
if (!instance_exists(obj_nfort)) or (flank) {
if (block_has_armour(enemy)) or (enemy.veh_type[1]=="Defenses"){
scr_shoot(i,enemy,target_unit_index,"att","ranged");
// show_debug_message($"I'm shooting at a vehicle, because I can't find a normal unit! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
continue;
} else if (instance_number(obj_pnunit)>1) and (obj_ncombat.enemy!=7) {
var x2=enemy.x;
repeat(instance_number(obj_pnunit)-1){
x2 += flank == 0 ? -10 : 10;
var enemy2=instance_nearest(x2,y,obj_pnunit);
if (!target_block_is_valid(enemy2, obj_pnunit)) {
continue;
}
if (range[i] < get_block_distance(enemy2)) {
break;
}
if (block_has_armour(enemy2)) {
scr_shoot(i,enemy2,target_unit_index,"att","ranged");
// show_debug_message($"I'm shooting at a vehicle in another row, because I can't find a normal unit! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
break;
}
}

scr_shoot(i, enemy2, chapter_fuck, "att", "ranged");
}
} else {
enemy=instance_nearest(x,y,obj_nfort);
if (range[i] >= get_block_distance(enemy)) {
scr_shoot(i,enemy,1,"att","wall");
// show_debug_message($"I'm shooting at a fort, because I can't find a normal unit! {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
continue;
}
}
}
}
} else {
// show_debug_message($"I can't shoot, my range is too small! Weapon: {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}; Range: {range[i]}");
continue;
}
log_error($"{wep[i]} didn't find a valid target! This shouldn't happen!");
// show_debug_message($"We didn't find a valid target! Weapon: {wep[i]}; Column ID: {id}; Enemy Unit: {wep_owner[i]}");
}
}

Expand Down Expand Up @@ -398,6 +424,4 @@ instance_activate_object(obj_pnunit);

/* */
}
}
}
/* */
1 change: 0 additions & 1 deletion objects/obj_enunit/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ i=0;
repeat(1001){i+=1;
wep[i]="";
wep_num[i]=0;
combi[i]=0;
range[i]=0;
att[i]=0;
apa[i]=0;
Expand Down
1 change: 0 additions & 1 deletion objects/obj_pnunit/Create_0.gml
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ repeat(71){i+=1;
wep[i]="";
wep_num[i]=0;
wep_rnum[i]=0;
combi[i]=0;
range[i]=0;
att[i]=0;
apa[i]=0;
Expand Down
Loading