diff options
author | Tor Andersson <tor@ccxvii.net> | 2024-01-04 01:03:28 +0100 |
---|---|---|
committer | Tor Andersson <tor@ccxvii.net> | 2024-01-04 01:05:42 +0100 |
commit | 06abc605b0e1e32585ec72e410dae5bc2e407d73 (patch) | |
tree | 5978e6d9e1f2e951163d0ad8fcb43ce7b991affd | |
parent | fb54e6b4b0df7b90ffd68124400fefda0af89d09 (diff) | |
download | rommel-in-the-desert-06abc605b0e1e32585ec72e410dae5bc2e407d73.tar.gz |
More optimizations.
-rw-r--r-- | data.js | 3 | ||||
-rw-r--r-- | rules.js | 31 | ||||
-rw-r--r-- | tools/gendata.js | 8 |
3 files changed, 34 insertions, 8 deletions
@@ -2,6 +2,7 @@ const all_hexes = [7,8,9,10,30,31,32,33,34,35,36,37,38,39,40,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,123,128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144,147,148,151,152,153,154,155,156,157,158,159,160,161,162,163,164,165,166,167,175,176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191,203,204,205,213] const hex_exists = [0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1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,2,2,2,2,2,0,2,2,0,0,2,2,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,0,1,0,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,2,0,0,2,0,0,2,2,0,2,0,0,2,0,0,2,0,2,2,0,0,2,0,0,2,0,0,2,0,0,2,0,0,2,0,0,2,2,0,2,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,2,2,2,2,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] const hex_name = {"4":"Malta","7":"El Garib","8":"Cyrene","9":"El Gubba","10":"Derna","30":"Tocra","31":"Barce","32":"Marawa","33":"Wadi Cuff","34":"Derna SW","35":"Gazala","36":"Acroma","37":"Tobruk","38":"Belhamed","39":"Gambut","40":"Bardia","47":"Exited","48":"Return for Refit","49":"Alexandria Queue","53":"Exited","54":"Benghazi","55":"Er Regima","56":"Charruba","57":"Mechili W","58":"Mechili","59":"Rotonda Segnali","60":"Sidi Mufta","61":"Bir Harmat","62":"El Adem","63":"Sidi Rezegh","64":"Ft. Capuzzo","65":"Sollum","66":"Buq Buq","67":"Sidi Barrani","68":"Mersa Matruh W","69":"Mersa Matruh","70":"Fuka","71":"El Daba","72":"El Alamein","73":"El Hamam","74":"Alexandria","78":"Ghemines","79":"Skeleidima","80":"Msus","81":"Msus E","82":"Mechili SW","83":"Tengeder","84":"Tengeder E","85":"Bir Hacheim","86":"Retma","87":"Bir Gubi","88":"Gabr Saleh","89":"Sidi Omar","90":"Bir Habata","91":"Sofafi","92":"Bir el Kenayis W","93":"Bir el Kenayis","94":"Bir Khalda","95":"Fuka SE","96":"El Alamein SW","97":"Alam Halfa","98":"Alexandria SW","99":"Map Edge","102":"Return for Refit","103":"Beda Fomm","104":"Antelat","105":"Msus SE","106":"Ben Gania","107":"Tengeder SW","108":"Tengeder SE","109":"Bir Hacheim SW","110":"Bir Hacheim SE","111":"Bir Gubi SW","112":"Ft. Maddalena W","113":"Ft. Maddalena","114":"Ft. Maddalena E","115":"Bir Khamsa","116":"Bir el Qatrani","117":"Bir el Kenayis SW","118":"Bir el Kenayis SE","119":"Western Desert","120":"El Himeimat W","121":"El Himeimat","122":"El Himeimat E","123":"Alexandria SW SE","127":"El Agheila Queue","128":"Agedabia","129":"Jebel el Matar","130":"Haraga","131":"Haraga E","132":"Libya","133":"Jalo Oasis Trail","134":"Libya","135":"Libya","136":"Libya","137":"Ft. Maddalena SW","138":"Ft. Maddalena SE","139":"Bir Khamsa SW","140":"Bir Khamsa SE","141":"Bir Fuad","142":"Bir Fuad E","143":"Western Desert","144":"Western Desert","145":"Qattara Depression","146":"Qattara Depression","147":"Qattara Depression","148":"Map Edge","151":"El Agheila","152":"Mersa Brega","153":"El Haseiat","154":"Haraga SW","155":"Haraga SE","156":"Libya","157":"Jalo Oasis Trail","158":"Libya","159":"Libya","160":"Libya","161":"Libya","162":"Jarabub Oasis NW","163":"Jarabub Oasis NE","164":"Siwa Oasis NE NW","165":"Bir Fuad SW","166":"Bir Fuad SE","167":"Western Desert","175":"Map Edge","176":"Maaten Giofer","177":"Maaten Giofer E","178":"Sahaba","179":"Jalo Oasis NW","180":"Jalo Oasis NE","181":"Jalo Oasis Trail","182":"Libya Trail","183":"Libya Trail","184":"Libya Trail","185":"Libya Trail","186":"Jarabub Oasis W","187":"Jarabub Oasis","188":"Jarabub Oasis E","189":"Siwa Oasis NE","190":"Western Desert","191":"Western Desert","197":"Map Edge","203":"Jalo Oasis W","204":"Jalo Oasis","205":"Jalo Oasis E","213":"Siwa Oasis"} @@ -14,6 +15,6 @@ const unit_class = [0,0,1,1,1,1,1,1,1,1,1,1,1,3,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2, const unit_speed = [3,3,3,2,2,1,1,1,1,1,1,1,1,1,4,4,4,3,3,3,3,3,3,3,2,2,1,1,1,3,3,2,2,1,4,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,3,1,1,1,1,1,3,3,3,2,2,2,2,2,2,4,2,2,2,2,2,2,2,2,3,3,3,2,2] if (typeof module !== 'undefined') module.exports = { - all_hexes, hex_exists, hex_name, hex_road, side_road, side_limit, regions, + all_hexes, hex_exists, hex_name, hex_all_road, hex_road, side_road, side_limit, regions, unit_name, unit_appearance, unit_max_steps, unit_elite, unit_class, unit_speed, } @@ -25,7 +25,7 @@ var game = null var view = null const { - all_hexes, hex_exists, hex_road, side_road, side_limit, hex_name, regions, + all_hexes, hex_exists, hex_all_road, hex_road, side_road, side_limit, hex_name, regions, unit_name, unit_appearance, unit_elite, unit_class, unit_speed, unit_max_steps, } = require("./data.js") @@ -1363,12 +1363,33 @@ function trace_unit_supply_line(path, here, here_move, ssrc) { let reached = (next === ssrc) if (!reached) { - // Stop searching if we reach a supplied highway, - // but only if we can't continue by trail or track. - // Example: Tobruk - EL Adem - Sidi Rezegh - Ft. Capuzzo - if (hex_road[next] === HIGHWAY && supply_net[next] === 2) + // Sometimes we can stop searching if we reach a supplied highway. + if (hex_road[next] === HIGHWAY && supply_net[next] === 2) { + + // But only if we can't continue by trail or track. + // If we always stop we'll miss possible departures that reconnect + // to the highway elsewhere. + // + // Example: Tobruk - EL Adem - Sidi Rezegh - Ft. Capuzzo + + // Not enough movement left to leave highway: if (next_move === BACK_HIGHWAY_3 || next_move === BACK_STOP) reached = true + + // MAYBE WRONG + // (can we leave supplied highway to connect to chain elsewhere?) + // Only these places can reconnect to the highway using trail/track: + if ( + next !== 35 && // Gazala + next !== 55 && // Er Regima + next !== 61 && // Bir Harmat + next !== 62 && // El Adem + next !== 64 && // Ft. Capuzzo + next !== 65 && // Sollum + next !== 78 // Ghemines + ) + reached = true + } } // reached supply source diff --git a/tools/gendata.js b/tools/gendata.js index 8ee858a..fb64009 100644 --- a/tools/gendata.js +++ b/tools/gendata.js @@ -31,6 +31,7 @@ let hex_exists = new Array(map_w*map_h).fill(1); let side_limit = new Array(map_w*map_h*3).fill(CLEAR); let side_road = new Array(map_w*map_h*3).fill(0); let hex_road = new Array(map_w*map_h).fill(0); +let hex_all_road = new Array(map_w*map_h).fill(0); function add_side(s, t) { if (side_limit[s]) @@ -57,9 +58,11 @@ function def_side(t,a,b) { } function def_road(t, list) { - for (let i = 0; i < list.length; ++i) + for (let i = 0; i < list.length; ++i) { + hex_all_road[list[i]] |= t; if (t > hex_road[list[i]]) hex_road[list[i]] = t; + } for (let i = 1; i < list.length; ++i) { let s = to_side_id(list[i-1], list[i]); side_road[s] = t; @@ -652,6 +655,7 @@ let data = "// DON'T EDIT - AUTOGENERATED\n" data += "const all_hexes = " + JSON.stringify(all_hexes) + "\n" data += "const hex_exists = " + JSON.stringify(hex_exists) + "\n" data += "const hex_road = " + JSON.stringify(hex_road) + "\n" +data += "const hex_all_road = " + JSON.stringify(hex_all_road) + "\n" data += "const side_road = " + JSON.stringify(side_road) + "\n" data += "const side_limit = " + JSON.stringify(side_limit) + "\n" data += "const hex_name = " + JSON.stringify(hex_name) + "\n" @@ -665,7 +669,7 @@ gen_array("unit_class", u => u.class) gen_array("unit_speed", u => u.speed) data += "if (typeof module !== 'undefined')\n\tmodule.exports = {\n" -data += "\t\tall_hexes, hex_exists, hex_name, hex_road, side_road, side_limit, regions,\n" +data += "\t\tall_hexes, hex_exists, hex_name, hex_all_road, hex_road, side_road, side_limit, regions,\n" data += "\t\tunit_name, unit_appearance, unit_max_steps, unit_elite, unit_class, unit_speed,\n" data += "\t}\n" |