1 // NAME : include_shoot
5 include("include_basic_global_variables");
6 include("include_STUFFS_G");
7 include("include_leeks");
8 include("include_ground");
13 // 1 si theoriquement possible (distance non-calculee)
14 function canShootBasic(shootingLeek_p, item_p){
15 //debug(">>> canShootBasic(" + getName(shootingLeek_p) + ", " + getItemName(item_p) + ")");
18 if(item_p === null || item_p == -1 ||
19 shootingLeek_p === null || shootingLeek_p == -1){
24 else if(getTP(shootingLeek_p) < getStuffCostComplete(item_p)){
27 else if(isChip(item_p)){
28 //si le cooldown d'item_p est KO,
30 if(LEEKS_VARIABLE_CARAC_G[shootingLeek_p][0][CARAC_LAST_TURN_USED_CHIP][item_p] != null &&
31 getChipCooldown(item_p) > TURN_G - LEEKS_VARIABLE_CARAC_G[shootingLeek_p][0][CARAC_LAST_TURN_USED_CHIP][item_p]){
35 //debug("<<< canShootBasic(" + getName(shootingLeek_p) + ", " + getItemName(item_p) + ") = " + result_l);
41 //si assez proche pour s'avancer et tirer sur leek_p : return 1
42 //si impossible : return 0
43 //si on ne sait pas : return -1
44 function closeToShoot(item_p, leek_p){
45 debug(">>> closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ")");
49 shootCell_l = getCellToUseWeapon(item_p, leek_p);
50 }else if(isChip(item_p)){
51 shootCell_l = getCellToUseChip(item_p, leek_p);
53 if(shootCell_l === null || shootCell_l == -1){
54 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
57 var currentCell_l = getCell();
58 if(currentCell_l === shootCell_l){
59 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 1");
62 var distToShootCell_l;
65 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
68 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = -1");
71 distToShootCell_l = getCellDistance(shootCell_l, currentCell_l);
72 if(distToShootCell_l > getMP()){
73 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
76 if(LEVEL_G >= 37 && CORES_G >= 2){
77 var pathLenght_l = getPathLength(shootCell_l, currentCell_l);
78 if(pathLenght_l === null || pathLenght_l == -1){
79 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
82 distToShootCell_l = pathLenght_l + 1;
83 if(shootCell_l != currentCell_l && distToShootCell_l <= 0){
84 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
87 if(distToShootCell_l > getMP()){
88 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
91 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 1");
96 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = -1");
102 function canShootCellToCell(shootingCell_p, shootingLeek_p, item_p, targetCell_p, targetLeek_p){
103 if(targetCell_p !== -1 && targetCell_p !== null &&
104 shootingCell_p !== -1 && shootingCell_p !== null){
106 (getCellDistance(targetCell_p, shootingCell_p) > STUFFS_G[item_p][STUFF_SCOPE_G][STUFF_SCOPE_MAX_G] ||
107 getCellDistance(targetCell_p, shootingCell_p) < STUFFS_G[item_p][STUFF_SCOPE_G][STUFF_SCOPE_MIN_G])){
111 if(!lineOfSight(shootingCell_p, targetCell_p) && item_p != CHIP_SPARK){
115 if(STUFFS_G[item_p][STUFF_SCOPE_G][STUFF_SCOPE_INLINE_G] &&
116 (shootingCell_p - targetCell_p) % 18 != 0 &&
117 (shootingCell_p - targetCell_p) % 17 != 0){
121 }else if(shootingLeek_p === ME_G){
122 return closeToShoot(item_p, targetLeek_p);
129 function mightShootCellToCell(shootingCell_p, shootingLeek_p, item_p, targetCell_p, targetLeek_p){
130 if(targetCell_p !== -1 && targetCell_p !== null &&
131 shootingCell_p !== -1 && shootingCell_p !== null){
133 (getCellDistance(targetCell_p, shootingCell_p) > STUFFS_G[item_p][STUFF_SCOPE_G][STUFF_SCOPE_MAX_G] ||
134 getCellDistance(targetCell_p, shootingCell_p) < STUFFS_G[item_p][STUFF_SCOPE_G][STUFF_SCOPE_MIN_G])){
138 if(!lineOfSight(shootingCell_p, targetCell_p, ALL_LEEKS) && item_p != CHIP_SPARK){
142 if(STUFFS_G[item_p][STUFF_SCOPE_G][STUFF_SCOPE_INLINE_G] &&
143 (shootingCell_p - targetCell_p) % 18 != 0 &&
144 (shootingCell_p - targetCell_p) % 17 != 0){
148 }else if(shootingLeek_p === ME_G){
149 return closeToShoot(item_p, targetLeek_p);
156 function canShootComplete(shootingCell_p, shootingLeek_p, item_p, targetCell_p, targetLeek_p){
157 //debug(">>> canShootComplete(" + shootingCell_p + ", " + getName(shootingLeek_p) + ", " + getItemName(item_p) + ", " + targetCell_p + ", " + getName(targetLeek_p) + ")");
159 if(!canShootBasic(shootingLeek_p, item_p)){
162 return canShootCellToCell(shootingCell_p, shootingLeek_p, item_p, targetCell_p, targetLeek_p);
167 function itemCellScore(item_p, cell_p, nbAttack_p, isWithFail_p){
168 //debug(">>> itemCellScore(" + getItemName(item_p) + ", " + cell_p + ", " + nbAttack_p + ", " + isWithFail_p + ")");
175 for(var leek_l in ALL_LEEKS){
176 if(isAlive(leek_l) && leek_l != ME_G){
177 var leekCell_l = getCell(leek_l);
178 var distance_l = getCellDistance(cell_p, leekCell_l);
180 var isEnemy_l = false;
181 for(var enemy_l in ENEMIES_G){
182 if(enemy_l == leek_l){
187 score_l += itemScore(item_p, distance_l, nbAttack_p, leek_l, isWithFail_p);
189 score_l -= itemScore(item_p, distance_l, nbAttack_p, leek_l, isWithFail_p);
193 //debug("<<< itemCellScore(" + getItemName(item_p) + ", " + cell_p + ", " + nbAttack_p + ", " + isWithFail_p + ") = " + score_l);
199 function itemCellScoreComplete(item_p, cell_p, isWithFail_p){
201 return itemCellScore(item_p, cell_p, getNbAttackComplete(ME_G, item_p), isWithFail_p);
206 function getCellsTarget(item_p){
211 var cellsTarget_l = [];
212 for(var enemy_l in ENEMIES_G){
213 var cellEnemy_l = getCell(enemy_l);
214 pushIfAbsentAndNotNull(cellsTarget_l, cellEnemy_l);
215 var radius_l = STUFFS_G[item_p][STUFF_RADIUS_G];
217 for(var cellsIt_l : var pathsIt_l in getAttackableCells(cellEnemy_l, radius_l)){
218 pushIfAbsentAndNotNull(cellsTarget_l, cellsIt_l);
222 return cellsTarget_l;
227 function getItemCellScores(){
229 var itemCellList_l = []; //table of [item, cell]
231 var scoreList_l = []; //table of [index, score]
232 var itemsAttack_l = getItemsAttack(ME_G);
233 debug("itemsAttack_l = " + itemsAttack_l);
234 for(var item_l : var average_l in itemsAttack_l){
235 if(canShootBasic(ME_G, item_l)){
236 for(var cellTarget_l in getCellsTarget(item_l)){
237 var score_l = itemCellScoreComplete(item_l, cellTarget_l, true);
238 if(score_l !== null || score_l > 0){
239 push(itemCellList_l, [item_l, cellTarget_l]);
240 scoreList_l[index_l] = score_l;
246 assocSort(scoreList_l, SORT_DESC);
247 return [itemCellList_l, scoreList_l];