Skip to content

Commit 38c150b

Browse files
authored
fix: Make dungeon battles and local battles run on modern roster system (Adeptus-Dominus#459)
1 parent 59e623c commit 38c150b

File tree

11 files changed

+177
-74
lines changed

11 files changed

+177
-74
lines changed

objects/obj_ncombat/Create_0.gml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@ if (instance_number(obj_ncombat)>1) then instance_destroy();
22

33
set_zoom_to_default();
44
var co,i;co=-1;
5-
repeat(15){co+=1;i=-1;
6-
repeat(401){i+=1;
7-
fighting[co][i]=0;
8-
if (i<=150){veh_fighting[co][i]=0;}
9-
}
10-
}co=0;i=0;hue=0;
5+
co=0;i=0;hue=0;
116

127
turn_count = 0;
138
debugl("Ground Combat Started");

objects/obj_popup/Alarm_0.gml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,23 @@ if (battle_special=3.1){
2424
instance_activate_object(obj_controller);
2525
instance_activate_object(obj_ncombat);
2626

27-
scr_battle_roster(loc,planet,true);
27+
_roster = new Roster();
28+
with (_roster){
29+
roster_location = obj_ncombat.battle_loc;
30+
roster_planet = obj_ncombat.battle_id;
31+
determine_full_roster();
32+
only_locals();
33+
update_roster();
34+
if (array_length(selected_units)){
35+
setup_battle_formations();
36+
add_to_battle();
37+
} else {
38+
instance_destroy(obj_ncombat);
39+
instance_activate_all();
40+
delete _roster
41+
}
42+
}
43+
delete _roster
2844
}
2945
instance_destroy();exit;
3046

objects/obj_popup/Destroy_0.gml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,12 @@ if (instance_exists(obj_controller)){
8282

8383
obj_controller.useful_info+="CHTRP|";
8484

85-
var v;v=0;
85+
var v=0;
8686
repeat(obj_temp_meeting.dudes){v+=1;
8787
if (obj_temp_meeting.present[v]=1){
88-
obj_ncombat.fighting[obj_temp_meeting.co[v],obj_temp_meeting.ide[v]]=1;
88+
var _unit_array = [obj_temp_meeting.co[v],obj_temp_meeting.ide[v]];
89+
add_unit_to_battle(_unit_array)
90+
8991
}
9092
}
9193

objects/obj_popup/Step_0.gml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,20 @@ try {
12801280
instance_activate_object(obj_temp8);
12811281

12821282
instance_create(0, 0, obj_ncombat);
1283-
scr_battle_roster(obj_temp8.loc, obj_temp8.wid, true);
1283+
_roster = new Roster();
1284+
with (_roster){
1285+
roster_location = obj_temp8.loc;
1286+
roster_planet = obj_temp8.wid;
1287+
determine_full_roster();
1288+
only_locals();
1289+
update_roster();
1290+
if (array_length(selected_units)){
1291+
setup_battle_formations();
1292+
add_to_battle();
1293+
}
1294+
}
1295+
delete _roster
1296+
12841297

12851298
instance_activate_object(obj_star);
12861299
with (obj_star) {

objects/obj_turn_end/Mouse_56.gml

Lines changed: 56 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ __b__ = action_if_number(obj_popup, 0, 0);
119119

120120

121121

122-
if (tip!=""){ // Fight fight fight, ground
122+
if (tip!=""){
123+
var _loc = battle_location[current_battle]
124+
var _planet = battle_world[current_battle] // Fight fight fight, ground
123125
obj_controller.cooldown=8;
124126

125127
// Start battle here
@@ -130,27 +132,40 @@ __b__ = action_if_number(obj_popup, 0, 0);
130132
instance_activate_object(obj_controller);
131133
instance_activate_object(obj_ini);
132134
instance_activate_object(battle_object[current_battle]);
133-
135+
136+
var _battle_obj = battle_object[current_battle];
137+
134138
instance_create(0,0,obj_ncombat);
135139
obj_ncombat.enemy=battle_opponent[current_battle];
136-
obj_ncombat.battle_object=battle_object[current_battle];
137-
obj_ncombat.battle_loc=battle_location[current_battle];
138-
obj_ncombat.battle_id=battle_world[current_battle];
139-
140-
if (tip="offensive") then obj_ncombat.formation_set=1;
141-
if (tip="defensive") then obj_ncombat.formation_set=2;
142-
143-
144-
var yeah;yeah=false;
145-
if (battle_object[current_battle].p_owner[battle_world[current_battle]]=1) then yeah=true;
146-
if (battle_object[current_battle].p_owner[battle_world[current_battle]]=7) then yeah=true;
147-
if (battle_object[current_battle].p_owner[battle_world[current_battle]]=9) then yeah=true;
148-
if (obj_controller.faction_status[battle_object[current_battle].p_owner[battle_world[current_battle]]]!="War") then yeah=true;
149-
if (yeah=true) then obj_ncombat.fortified=battle_object[current_battle].p_fortified[battle_world[current_battle]];
150-
if (obj_ncombat.enemy=13) then obj_ncombat.fortified=0;
140+
obj_ncombat.battle_object=_battle_obj;
141+
obj_ncombat.battle_loc=_loc;
142+
obj_ncombat.battle_id=_planet;
143+
144+
var _enemy = obj_ncombat.enemy;
145+
146+
var _planet_data = new PlanetData(_planet, _battle_obj);
147+
if (tip="offensive"){
148+
obj_ncombat.formation_set=1;
149+
} else if (tip="defensive"){
150+
obj_ncombat.formation_set=2;
151+
}
152+
153+
154+
var _allow_fortifications=false;
155+
var _fort_factions = [eFACTION.Player, eFACTION.Tyranids,eFACTION.Ork];
156+
_allow_fortifications = (array_contains(_fort_factions, _planet_data.current_owner))
157+
158+
if (!_allow_fortifications){
159+
var owner_fac_status
160+
_allow_fortifications = (_planet_data.owner_status() != "War");
161+
}
162+
163+
if (_allow_fortifications) then obj_ncombat.fortified=_planet_data.fortification_level;
164+
165+
if (obj_ncombat.enemy==13) then obj_ncombat.fortified=0;
151166

152167
obj_ncombat.battle_special=battle_special[current_battle];
153-
obj_ncombat.battle_climate=battle_object[current_battle].p_type[battle_world[current_battle]];
168+
obj_ncombat.battle_climate=_planet_data.planet_type;
154169

155170
// show_message(string(battle_object[current_battle].p_feature[battle_world[current_battle]]));
156171
/*if (scr_planetary_feature.plant_feature_bool(battle_object[current_battle].p_feature[battle_world[current_battle]], P_features.Monastery)==1){
@@ -160,20 +175,29 @@ __b__ = action_if_number(obj_popup, 0, 0);
160175
obj_ncombat.player_silos+=battle_object[current_battle].p_silo[battle_world[current_battle]];
161176
}*/
162177

163-
if (obj_ncombat.enemy = eFACTION.Imperium){obj_ncombat.threat=min(1000000,battle_object[current_battle].p_guardsmen[battle_world[current_battle]]);}
164-
if (obj_ncombat.enemy = eFACTION.Eldar) then obj_ncombat.threat=battle_object[current_battle].p_eldar[battle_world[current_battle]];
165-
if (obj_ncombat.enemy = eFACTION.Ork) then obj_ncombat.threat=battle_object[current_battle].p_orks[battle_world[current_battle]];
166-
if (obj_ncombat.enemy = eFACTION.Tau) then obj_ncombat.threat=battle_object[current_battle].p_tau[battle_world[current_battle]];
167-
if (obj_ncombat.enemy = eFACTION.Tyranids) then obj_ncombat.threat=battle_object[current_battle].p_tyranids[battle_world[current_battle]];
168-
if (obj_ncombat.enemy = eFACTION.Chaos) then obj_ncombat.threat=battle_object[current_battle].p_traitors[battle_world[current_battle]];
169-
if (obj_ncombat.enemy = eFACTION.Heretics) then obj_ncombat.threat=battle_object[current_battle].p_chaos[battle_world[current_battle]];
170-
if (obj_ncombat.enemy = eFACTION.Necrons) then obj_ncombat.threat=battle_object[current_battle].p_necrons[battle_world[current_battle]];
171-
if (obj_ncombat.enemy=30) then obj_ncombat.threat=1;
172-
173-
//
174-
175-
scr_battle_roster(string(battle_location[current_battle]),battle_world[current_battle],true);
176-
178+
if (_enemy == eFACTION.Imperium){
179+
obj_ncombat.threat=min(1000000,_planet_data.guardsmen);
180+
} else if (obj_ncombat.enemy<14 && _enemy>5){
181+
obj_ncombat.threat = _planet_data.planet_forces[_enemy];
182+
}
183+
else if (_enemy=30){
184+
obj_ncombat.threat=1;
185+
}
186+
187+
//
188+
_roster = new Roster();
189+
with (_roster){
190+
roster_location = _loc;
191+
roster_planet = _planet;
192+
determine_full_roster();
193+
only_locals();
194+
update_roster();
195+
if (array_length(selected_units)){
196+
setup_battle_formations();
197+
add_to_battle();
198+
}
199+
}
200+
delete _roster
177201
instance_deactivate_object(battle_object[current_battle]);
178202
}
179203
}

scripts/scr_PlanetData/scr_PlanetData.gml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ function PlanetData(planet, system) constructor{
3434
return _at_war;
3535
}
3636

37+
static owner_status = function(){
38+
return obj_controller.faction_status[current_owner];
39+
}
3740
guardsmen = system.p_guardsmen[planet];
3841
pdf = system.p_pdf[planet];
3942
fortification_level = system.p_fortified[planet];

scripts/scr_ancient_ruins/scr_ancient_ruins.gml

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,32 @@ function scr_ruins_suprise_attack_player(){
2525
instance_activate_object(obj_ground_mission);
2626
var _star = star_by_name(obj_ground_mission.loc);
2727
var _planet = obj_ground_mission.num;
28+
var _units = obj_ground_mission.display_unit;
2829

2930
instance_create(0,0,obj_ncombat);
3031

3132
obj_ncombat.man_size_limit = man_size_limit;
3233

3334
//that_one=instance_nearest(0,0,obj_star);
3435
// instance_activate_object(obj_star);
35-
scr_battle_roster(obj_ground_mission.loc ,_planet,true);
36-
obj_controller.cooldown=10;
36+
_roster = new Roster();
37+
with (_roster){
38+
roster_location = obj_ground_mission.loc;
39+
roster_planet = _planet;
40+
selected_units = _units;
41+
if (array_length(selected_units)){
42+
setup_battle_formations();
43+
add_to_battle();
44+
} else {
45+
instance_destroy(obj_ncombat);
46+
instance_destroy(obj_pnunit);
47+
instance_destroy(obj_enunit);
48+
instance_activate_all();
49+
scr_ruins_reward(_star,_planet,self);
50+
}
51+
}
52+
53+
3754
obj_ncombat.battle_object=_star;
3855
obj_ncombat.battle_loc=_star.name;
3956
instance_deactivate_object(obj_star);
@@ -202,7 +219,7 @@ function scr_check_for_ruins_exploration(select_planet, star){
202219
var _ruins_list = search_planet_features( _planet_features, P_features.Ancient_Ruins)
203220
var _explore_ruins=0;
204221
if (array_length(_ruins_list) > 0){
205-
for (var _ruin= 0; _ruin < array_length(_ruins_list); _ruin++){
222+
for (var _ruin = 0; _ruin < array_length(_ruins_list); _ruin++){
206223
var _specific_ruins = _ruins_list[_ruin];
207224
var _cur_ruins = _planet_features[_specific_ruins];
208225
if ( _cur_ruins.exploration_complete == false){

scripts/scr_battle_roster/scr_battle_roster.gml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ function scr_battle_roster(required_location, _target_location, _is_planet, over
6262
if (_spyrer_mission > 0) {
6363
if (okay == 1) and(array_length(new_combat.unit_struct)) then okay = -1;
6464
}
65-
if (okay <= -1) then new_combat.fighting[company][v] = 0;
6665

6766
//Normal and other battle cases checks go here
6867
else if (okay >= 0) {
@@ -83,9 +82,8 @@ function scr_battle_roster(required_location, _target_location, _is_planet, over
8382
}
8483
} else if (instance_exists(obj_drop_select)) { // When attacking, normal battle
8584
//If not fighting (obj_drop_select pre-check), we skip the unit
86-
if (obj_drop_select.fighting[company][v] == 0) then okay = 0;
8785

88-
else if (obj_drop_select.attack == 1) {
86+
if (obj_drop_select.attack == 1) {
8987
if (_is_planet) and(obj_ini.loc[company][v] == required_location) and(unit.planet_location == _target_location) then okay = 1;
9088
else if (!_is_planet) and(unit.ship_location == _target_location) then okay = 1;
9189
} else if (obj_drop_select.attack != 1) {

scripts/scr_clean/scr_clean.gml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,26 @@ function scr_clean(target_object, target_is_infantry, hostile_shots, hostile_dam
9898

9999
// Apply damage for each shot
100100
for (var shot = 0; shot < man_hits; shot++) {
101-
if (array_length(valid_marines) == 0) break; // No valid targets left
101+
if (array_length(valid_marines) == 0){
102+
break; // No valid targets left
103+
}
102104

103105
// Select a random marine from the valid list
104106
var random_index = array_random_index(valid_marines);
105107
var marine_index = valid_marines[random_index];
106108
var marine = unit_struct[marine_index];
107109

108110
// Apply damage
109-
var minus = hostile_damage - (2 * marine_ac[marine_index]);
111+
var _shot_luck = d100_roll();
112+
if (_shot_luck<1){
113+
var minus = hostile_damage;
114+
} else if (_shot_luck<5){
115+
var minus = hostile_damage - marine_ac[marine_index];
116+
} else {
117+
var minus = hostile_damage - (2 * marine_ac[marine_index]);
118+
}
119+
120+
110121
if (minus > 0) {
111122
var damage_resistance = (marine.damage_resistance() / 100);
112123
if (marine_mshield[marine_index] > 0) damage_resistance += 0.1;

scripts/scr_drop_select_function/scr_drop_select_function.gml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ function drop_select_draw(){
337337
combating = 0;
338338
instance_activate_all();
339339
exit;
340+
340341
}
341342
if (obj_controller.known[eFACTION.Chaos] >= 2 && obj_controller.faction_gender[10] = 1){
342343
with(obj_drop_select) {

0 commit comments

Comments
 (0)