maj degats + calcul flamme/gazor
[multileek.git] / src / include_shoot__86113.lks
blob55f0019ab2234d4597d65f23576a664e5c9e247e
1 // NAME : include_shoot
2 // DEFINITIONS :
3 //
5 include("include_basic_global_variables");
6 include("include_STUFFS_G");
7 include("include_leeks");
8 include("include_ground");
12 // 0 si impossible
13 // 1 si theoriquement possible (distance non-calculee)
14 function canShootBasic(shootingLeek_p, item_p){
15 //debug(">>> canShootBasic(" + getName(shootingLeek_p) + ", " + getItemName(item_p) + ")");
17         var result_l = 1;
18         if(item_p === null || item_p == -1 ||
19         shootingLeek_p === null || shootingLeek_p == -1){
20                 result_l = 0;
21         }
22         //si pas assez de TP,
23         //impossible
24         else if(getTP(shootingLeek_p) < getStuffCostComplete(item_p)){
25                 result_l = 0;
26         }
27         else if(isChip(item_p)){
28                 //si le cooldown d'item_p est KO,
29                 //impossible
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]){
32                         result_l = 0;
33                 }
34         }
35 //debug("<<< canShootBasic(" + getName(shootingLeek_p) + ", " + getItemName(item_p) + ") = " + result_l);
36         return 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) + ")");
47         var shootCell_l;
48         if(isWeapon(item_p)){
49                 shootCell_l = getCellToUseWeapon(item_p, leek_p);
50         }else if(isChip(item_p)){
51                 shootCell_l = getCellToUseChip(item_p, leek_p);
52         }
53         if(shootCell_l === null || shootCell_l == -1){
54                 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
55                 return 0;
56         }
57         var currentCell_l = getCell();
58         if(currentCell_l === shootCell_l){
59                 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 1");
60                 return 1;
61         }
62         var distToShootCell_l;
63         if(LEVEL_G < 5){
64                 if(getMP() === 0){
65                         debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
66                         return 0;
67                 }
68                 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = -1");
69                 return -1;
70         }else{
71                 distToShootCell_l = getCellDistance(shootCell_l, currentCell_l);
72                 if(distToShootCell_l > getMP()){
73                         debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
74                         return 0;
75                 }
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");
80                                 return 0;
81                         }
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");
85                                 return 0;
86                         }
87                         if(distToShootCell_l > getMP()){
88                                 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 0");
89                                 return 0;
90                         }else{
91                                 debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = 1");
92                                 return 1;
93                         }
94                 }
95         }
96         debug("<<< closeToShoot(" + getItemName(item_p) + ", " + getName(leek_p) + ") = -1");
97         return -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){
105                 if(LEVEL_G >= 5 &&
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])){
108                         return 0;
109                 }
111                 if(!lineOfSight(shootingCell_p, targetCell_p) && item_p != CHIP_SPARK){
112                         return 0;
113                 }
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){
118                         return 0;
119                 }
120                 return 1;
121         }else if(shootingLeek_p === ME_G){
122                 return closeToShoot(item_p, targetLeek_p);
123         }
124         return -1;
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){
132                 if(LEVEL_G >= 5 &&
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])){
135                         return 0;
136                 }
138                 if(!lineOfSight(shootingCell_p, targetCell_p, ALL_LEEKS) && item_p != CHIP_SPARK){
139                         return 0;
140                 }
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){
145                         return 0;
146                 }
147                 return 1;
148         }else if(shootingLeek_p === ME_G){
149                 return closeToShoot(item_p, targetLeek_p);
150         }
151         return -1;
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)){
160                 return 0;
161         }
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 + ")");
170         if(LEVEL_G < 5){
171                 return null;
172         }
174         var score_l = 0;
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){
183                                         isEnemy_l = true;
184                                 }
185                         }
186                         if(isEnemy_l){
187                                 score_l += itemScore(item_p, distance_l, nbAttack_p, leek_l, isWithFail_p);
188                         }else{
189                                 score_l -= itemScore(item_p, distance_l, nbAttack_p, leek_l, isWithFail_p);
190                         }
191                 }
192         }
193 //debug("<<< itemCellScore(" + getItemName(item_p) + ", " + cell_p + ", " + nbAttack_p + ", " + isWithFail_p + ") = " + score_l);
194         return 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){
208         if(LEVEL_G < 5){
209                 return [];
210         }
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];
216                 if(radius_l > 0){
217                         for(var cellsIt_l : var pathsIt_l in getAttackableCells(cellEnemy_l, radius_l)){
218                                 pushIfAbsentAndNotNull(cellsTarget_l, cellsIt_l);
219                         }
220                 }
221         }
222         return cellsTarget_l;
227 function getItemCellScores(){
229         var itemCellList_l = []; //table of [item, cell]
230         var index_l = 0;
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;
241                                         index_l++;
242                                 }
243                         }
244                 }
245         }
246         assocSort(scoreList_l, SORT_DESC);
247         return [itemCellList_l, scoreList_l];