Code edit (18 edits merged)
Please save this source code
Code edit (4 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'units')' in or related to this line: 'var allUnits = player1.units.concat(player2.units);' Line Number: 2806
Code edit (1 edits merged)
Please save this source code
===================================================================
--- original.js
+++ change.js
@@ -2066,9 +2066,9 @@
}
};
var aiCurrentLevel = AI_LEVEL.EASY;
var aiBaseUnitList = {
- 'unitHarvester': 1,
+ 'unitHarvester': 2,
'unitQuad': 3,
'unitLightTank': 2,
'unitHeavyTank': 4
};
@@ -2220,9 +2220,9 @@
return tempNeededUnitList;
}
function getUnitNeedsPerWave(waveIndex) {
//console.log("getUnitNeedsPerWave...", waveIndex);
- /*
+ /*
Wave 1 : 1 Quad
Wave 2 : 2 Quad
Wave 3 : 2 Quad + 1 LightTank
Wave 4 : 2 Quad + 2 LightTank
@@ -2316,9 +2316,9 @@
// keep only units alive
return !unit.isDestroyed;
});
aiCurrentArmyUnits = tempCleanArmy;
- if (aiCurrentArmyUnits.length >= aiCurrentAttackWave) {
+ if (aiCurrentArmyUnits.length >= Math.min(6, aiCurrentAttackWave)) {
// ATTENTION !!! Arbitray rue : Nb units == Wave index
//console.log("Army is ready:", aiCurrentArmyUnits);
aiArmyIsReady = true;
}
@@ -2441,13 +2441,18 @@
aiCurrentlyBuildingForArmy = !!forArmy; // Flag to add the unit to the army
enqueueBuildable(unitToBuild, sourceFactory, player2);
}
function aiFindClosestBuildingToAttack(firstAttaker) {
+ if (!firstAttaker) {
+ console.warn("AI : No attack leader!");
+ return null;
+ }
// Browse player1.buildings
var potientialTargetBuildings = orderEntitiesPerDistance(firstAttaker, player1.buildings);
if (potientialTargetBuildings && potientialTargetBuildings.length > 0) {
return potientialTargetBuildings[0].entity;
}
+ console.warn("AI : Found no building to attack!");
return null;
}
function aiStartAttack(target) {
var nbUnits = aiCurrentArmyUnits.length;
@@ -2473,24 +2478,24 @@
// Define a fixed rock ilot near the center left of the map
// Randomize starting positions for rockIlot1Center and rockIlot2Center
var startingPositions = [{
x: 8,
- y: 10
+ y: 8
},
// Top left
{
x: 30,
- y: 10
+ y: 8
},
// Top right
{
x: 8,
- y: 30
+ y: 32
},
// Bottom left
{
x: 30,
- y: 30
+ y: 32
} // Bottom right
];
var randomIndex = Math.floor(Math.random() * startingPositions.length);
rockIlot1Center = startingPositions[randomIndex];
@@ -3230,16 +3235,16 @@
y: game.height / 2,
anchorX: 0.5,
anchorY: 0.5
});
-var welcomeText = new Text2("Welcome on Dune", {
+var welcomeText = new Text2("Welcome on Sandoria", {
size: 90,
fill: "#ffffff",
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
-welcomeText.anchor.set(0.5, 6.6);
+welcomeText.anchor.set(0.5, 6.4);
LK.gui.center.addChild(welcomeText);
-var helpText = new Text2("This is the planet of Spice, the most valuable \nresource of the universe.\n\nYou have just been promoted as a commander of\nthe Atreides family army.\nYour mission is to HARVEST SPICE in this area\nand CLEAR ALL ENEMY presence.\n\nFrom your CONSTRUCTION YARD, build a\nSPICE REFINERY and use SPICE HARVESTERS to\ncollect the orange SPICE on the soil.\nBuild Wind Traps to produce energy. Monitor\nyour energy and Spice counters at the top right.\n\nEnemy Harkonnen troops have been reported\nin the area: build LIGHT FACTORY OR \nHEAVY FACTORY to train more troops.\n\nGood luck Commander!", {
+var helpText = new Text2("Planet of sand and Spice, the most valuable \nresource of the universe.\n\nYou have just been promoted as a commander of\nthe Adrians family army.\nYour mission is to HARVEST SPICE in this area\nand CLEAR ALL ENEMY presence.\n\nFrom your CONSTRUCTION YARD, build a\nSPICE REFINERY and use SPICE HARVESTERS to\ncollect the orange SPICE on the soil.\nBuild WIND TRAPS to produce energy. Monitor\nyour energy and Spice counters at the top right.\n\nEnemy Kojrims troops have been reported\nin the area: build LIGHT FACTORY OR \nHEAVY FACTORY to train more troops.\n\nGood luck Commander!", {
size: 50,
fill: "#ffffff",
font: "'GillSans-Bold',Impact,'Arial Black',Tahoma"
});
@@ -3252,12 +3257,21 @@
// Start the game with Player 1 construction yard preselected
initGame();
LK.setTimeout(function () {
gameIsRunning = true;
- viewPort.wCellX = rockIlot1Center.x;
- viewPort.wCellY = rockIlot1Center.y;
- viewPort.wX = rockIlot1Center.x * tileSize - viewPort.wCellX * tileSize;
- viewPort.wY = rockIlot1Center.y * tileSize - viewPort.wCellY * tileSize;
+ viewPort.wCellX = Math.max(0, Math.min(mapXSize - viewPort.cellW, rockIlot1Center.x - Math.floor(viewPort.cellW / 2)));
+ viewPort.wCellY = Math.max(0, Math.min(mapYSize - viewPort.cellH, rockIlot1Center.y - Math.floor(viewPort.cellH / 2)));
+ gameMap.handleDrag({
+ x: 0,
+ y: 0
+ });
+ // Call handleDrag on player1 units
+ player1.units.forEach(function (unit) {
+ unit.handleDrag({
+ x: 0,
+ y: 0
+ });
+ });
currentSelection = gameMap.cells[rockIlot1Center.x][rockIlot1Center.y].building;
selectionMarker.setOnElement(currentSelection);
updateActionBoard();
updateFogOfWar();
a tileable sand terrain tile.
A square tileable rock terrain tile WITHOUT BBORDER. Single Game Texture. In-Game asset. 2d. No shadows. No Border
Zenith view of Dune's Wind Trap power facility square fence. Ressembles a bit to Sydney's Opera. Zenith view Directly from above.
grey cancel icon. UI
thin white circle empty.
0x5e86ff
Zenith view of a white rectangular Harvester shape of a garbage truck with a triangular head. Harvesting on sand, with flowing spice in the back. inside a square fence. Zenith view. Directly overhead. Plumb view.
Minimal Ui icon of an right sign aside with an icon of a target. sand background
Minimal icon of a home with direction icon pointing to the home. sand background
3 white flat isometric concentric circles like a target.
Remove background
Gray background
Minimal Ui icon of target sign on a fire icon.. sand background
top view of an explosion effect.
Simple heavy army tank factory buiding a tank with a crane. Square fence... Zenith view Directly overhead. Plumb view.
an empty black popup UI. UI