Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: LK.getTime is not a function' in or related to this line: 'self.lastHitTime = LK.getTime();' Line Number: 1099
Code edit (2 edits merged)
Please save this source code
User prompt
could you implement findFactoryForUnit
Code edit (1 edits merged)
Please save this source code
User prompt
add a new function findEmplacementForBuilding(building, cellX, cellY) that scans the map around the given cellX,cellY to find a free area of rocks that fits the given building size
Code edit (5 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Timeout.tick error: buildable.placeBuilding is not a function' in or related to this line: 'buildable.placeBuilding(placeX, placeY);' Line Number: 2117
Code edit (1 edits merged)
Please save this source code
Code edit (6 edits merged)
Please save this source code
User prompt
in handleDragEnd, don't select buildings if they are under fog
User prompt
don't select ennemy units and building if they are under fog
User prompt
in updateFogOfWar remove the fog in a radius shape instead of a square
Code edit (2 edits merged)
Please save this source code
User prompt
in building growExplosion, remove building from player list of buildings
User prompt
in checkGameEnd, check if player1 of player2 have no more buildings game over if so
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
call updateFogOfWar(); after every building placement
Code edit (7 edits merged)
Please save this source code
User prompt
in updateFogOfWar, itterate through all player1 units and buildings and set gameMap.cells[x][y].fog to false 5 cells around them
User prompt
force fogOfWar tint to 0x000000
Code edit (1 edits merged)
Please save this source code
Code edit (3 edits merged)
Please save this source code
User prompt
in harvester update, when self.harvestingMode == 3, add spice to the unit player not always to player1
===================================================================
--- original.js
+++ change.js
@@ -242,11 +242,14 @@
});
self.asset.x = self.x;
self.asset.y = self.y;
self.buildingQueue = [];
+ self.lastAttackTime = 0;
+ self.lastHitTime = 0;
self.damage = function (points) {
console.log("Building " + self.name + " hit! " + points);
self.health -= points;
+ self.lastHitTime = LK.getTime();
self.asset.tint = 0xff0000;
LK.setTimeout(function () {
self.asset.tint = 0xFFFFFF;
}, 500);
@@ -868,8 +871,9 @@
self.attackDamage = unitInfo.attackDamage;
self.attackSpeed = unitInfo.attackSpeed; // Speed of attack (time between attacks)
self.attackMode = 0; // 0 = not attacking, 1 = attacking, 2 = moving to target
self.lastAttackTime = 0;
+ self.lastHitTime = 0;
self.actions = unitInfo.actions;
self.asset = self.attachAsset(type, {
anchorX: 0.5,
anchorY: 0.5,
@@ -1055,8 +1059,9 @@
};
self.damage = function (points) {
console.log("Unit " + self.name + " hit! " + points);
self.asset.tint = 0xff0000;
+ self.lastHitTime = LK.getTime();
LK.setTimeout(function () {
self.asset.tint = getPlayerTint(self.playerId);
}, 300);
self.health -= points;
@@ -1804,12 +1809,29 @@
var rockIlot1Center = {
x: 0,
y: 0
};
-// AI
+/* ***************************************************************************************************** */
+/* ********************************************* AI FUNCTIONS ****************************************** */
+/* ***************************************************************************************************** */
+var AI_LEVEL = {
+ EASY: {
+ acttingDelay: 1000,
+ thinkingDelay: 1000
+ },
+ NORMAL: {
+ acttingDelay: 300,
+ thinkingDelay: 600
+ },
+ HARD: {
+ acttingDelay: 100,
+ thinkingDelay: 200
+ }
+};
+var aiCurrentLevel = AI_LEVEL.EASY;
var aiBaseUnitList = {
'unitHarvester': 1,
- 'unitQuad ': 1,
+ 'unitQuad': 1,
'unitLightTank': 2,
'unitHeavyTank': 4
};
var aiBaseBuildingList = {
@@ -1819,8 +1841,85 @@
'heavyFactory': 1
};
var aiCurrentUnitConstruction = null;
var aiCurrentBuildingConstruction = null;
+var aiNeededBuildingList = null;
+var aiNeededUnitsList = null;
+// Think of what AI must do
+function aiThinking() {
+ if (LK.ticks % aiCurrentLevel.thinkingDelay !== 0) {
+ return;
+ }
+ console.log("aiThinking...");
+ // Check buildings requirements
+ aiNeededBuildingList = checkBuildingRequirements();
+ // Check units requirements
+ aiNeededUnitsList = checkUnitRequirements();
+ // Check defense needs
+ // Check attack opportunities
+}
+function checkBuildingRequirements() {
+ console.log("checkBuildingRequirements...");
+ console.log("player2 buildings:", player2.buildings);
+ // 1) Count currently owned buildings
+ var aiCurrentBuildingList = {
+ 'windTrap': 0,
+ 'spiceRefinery': 0,
+ 'lightFactory': 0,
+ 'heavyFactory': 0
+ };
+ player2.buildings.forEach(function (building) {
+ aiCurrentBuildingList[building.type] = (aiCurrentBuildingList[building.type] || 0) + 1;
+ });
+ console.log("aiCurrentBuildingList:", aiCurrentBuildingList);
+ // 2) Check if all requirements are met
+ var tempNeededBuildingList = {};
+ // Compare aiBaseBuildingList and aiCurrentBuildingList
+ for (var building in aiBaseBuildingList) {
+ if (aiBaseBuildingList[building] > aiCurrentBuildingList[building]) {
+ tempNeededBuildingList[building] = aiBaseBuildingList[building] - aiCurrentBuildingList[building];
+ }
+ }
+ return tempNeededBuildingList;
+}
+function checkUnitRequirements() {
+ console.log("checkUnitRequirements...");
+ console.log("player2 units:", player2.units);
+ // 1) Count currently owned units
+ var aiCurrentUnitList = {
+ 'unitHarvester': 0,
+ 'unitQuad': 0,
+ 'unitLightTank': 0,
+ 'unitHeavyTank': 0
+ };
+ player2.units.forEach(function (unit) {
+ aiCurrentUnitList[unit.type] = (aiCurrentUnitList[unit.type] || 0) + 1;
+ });
+ console.log("aiCurrentUnitList:", aiCurrentUnitList);
+ // 2) Check if all requirements are met
+ var tempNeededUnitList = {};
+ // Compare aiBaseUnitList and aiCurrentUnitList
+ for (var unit in aiBaseUnitList) {
+ if (aiBaseUnitList[unit] > aiCurrentUnitList[unit]) {
+ tempNeededUnitList[unit] = aiBaseUnitList[unit] - aiCurrentUnitList[unit];
+ }
+ }
+ return tempNeededUnitList;
+}
+// Do what AI thought about
+function aiActing() {
+ if (LK.ticks % aiCurrentLevel.acttingDelay !== 0) {
+ return;
+ }
+ console.log("aiActing...");
+ // 1) Meet buildings requirements
+ console.log("aiNeededBuildingList:", aiNeededBuildingList);
+ // 2) Meet units requirements
+ console.log("aiNeededUnitsList:", aiNeededUnitsList);
+}
+/* ***************************************************************************************************** */
+/* ********************************************* INIT FUNCTIONS ****************************************** */
+/* ***************************************************************************************************** */
// Prepare the map
function prepareMap() {
globalTerrain = new Array(mapXSize).fill(0).map(function () {
return new Array(mapYSize).fill(0);
@@ -2420,12 +2519,8 @@
// Update the FPS text on the screen
fpsText.setText('FPS: ' + fps);
}, 1000); // 1000 milliseconds = 1 second
};
-function aiUpdate() {
- console.log("aiUpdate...");
- // Check units requirements
-}
function checkGameEnd() {
console.log("checkGameEnd...");
// Check if either player1 or player2 has no more buildings
if (player1.buildings.length === 0 || player2.buildings.length === 0) {
@@ -2508,8 +2603,10 @@
if (unit.assetEffect) {
game.addChild(unit.assetEffect);
}
});
+ aiThinking();
+ aiActing();
}
tickCounter++;
});
// Start the game with Player 1 construction yard preselected
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