User prompt
before the game starts display a popup
Code edit (6 edits merged)
Please save this source code
User prompt
how would you handle energy so that low energy level slow down constructions
Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: Cannot read properties of null (reading 'type')' in or related to this line: 'player1.spice += buildableRepository.getBuildableInfo(currentBuildingForPlacement.type).cost;' Line Number: 462
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (8 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: unit is not defined' in or related to this line: 'switch (unit.type) {' Line Number: 2176
Code edit (1 edits merged)
Please save this source code
Code edit (14 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: rockIlot2Center is not defined' in or related to this line: 'baseBuilding = {' Line Number: 1740
Code edit (1 edits merged)
Please save this source code
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
===================================================================
--- original.js
+++ change.js
@@ -100,9 +100,10 @@
return;
}
var progressDisplay = new BuildingProgressDisplay(self);
game.addChild(progressDisplay);
- enqueueBuildable(self, progressDisplay);
+ //enqueueBuildable(self, progressDisplay);
+ enqueueBuildable2(self.type, self.sourceFactory, player1, progressDisplay);
game.children.forEach(function (child) {
if (child instanceof BuildableItemIcon) {
child.alpha = 0.75;
}
@@ -529,9 +530,10 @@
if (building.assetEffect) {
self.addChild(building.assetEffect);
}
}
- if (cell.fog) {
+ if (false && cell.fog) {
+ // TEMP DEBUG !!! TEMP DEBUG !!! TEMP DEBUG !!! TEMP DEBUG !!!
var fogAsset = cell.fogAsset;
fogAsset.x = screenX - 1;
fogAsset.y = screenY - 1;
if (!fogAsset.parent) {
@@ -729,8 +731,9 @@
self.energy = 0; // Initialize spice property with 1000
// Initialize player-specific properties here
self.buildings = []; // Array to store all the player's buildings
self.units = []; // Array to store all the player's units
+ self.isCurrentlyBuilding = false;
// ...
self.addUnit = function (unit) {
// Add the unit to the player's units array
self.units.push(unit);
@@ -1732,8 +1735,131 @@
cancelActionBtn = new CancelActionButton(commandPanel.x + commandPanel.width - 200, commandPanel.y + 200);
}
game.addChild(cancelActionBtn);
}
+function enqueueBuildable2(buildableType, buildableSourceFactory, currentPlayer, progressDisplay) {
+ console.log(currentPlayer.playerId + " - enqueueBuildable2...", buildableType, buildableSourceFactory);
+ if (currentPlayer.playerId === player1.playerId && !currentSelection || !currentSelection.buildable.includes(buildableType)) {
+ console.log(currentPlayer.playerId + " - Cannot build this item here.");
+ return;
+ }
+ var buildableInfo = buildableRepository.getBuildableInfo(buildableType);
+ if (buildableInfo && currentPlayer.spice < buildableInfo.cost) {
+ console.log(currentPlayer.playerId + " - Not enough resources to build.");
+ if (currentPlayer.playerId === player1.playerId) {
+ progressDisplay.blinkRed();
+ }
+ return;
+ }
+ if (currentPlayer.playerId === player1.playerId) {
+ updateBaseInfo();
+ }
+ var constructionTime = buildableInfo.constructionTime;
+ var buildable;
+ switch (buildableInfo.className) {
+ case 'ConstructionYard':
+ buildable = new ConstructionYard(0, 0, currentPlayer.playerId);
+ break;
+ case 'WindTrap':
+ buildable = new WindTrap(0, 0, currentPlayer.playerId);
+ break;
+ case 'SpiceRefinery':
+ buildable = new SpiceRefinery(0, 0, currentPlayer.playerId);
+ break;
+ case 'LightFactory':
+ buildable = new LightFactory(0, 0, currentPlayer.playerId);
+ break;
+ case 'HeavyFactory':
+ buildable = new HeavyFactory(0, 0, currentPlayer.playerId);
+ break;
+ case 'UnitQuad':
+ buildable = new UnitQuad(0, 0, currentPlayer.playerId);
+ break;
+ case 'UnitLightTank':
+ buildable = new UnitLightTank(0, 0, currentPlayer.playerId);
+ break;
+ case 'UnitHeavyTank':
+ buildable = new UnitHeavyTank(0, 0, currentPlayer.playerId);
+ break;
+ case 'UnitHarvester':
+ buildable = new UnitHarvester(0, 0, currentPlayer.playerId);
+ break;
+ // Add cases for other buildings as needed
+ }
+ if (!buildable) {
+ console.error(currentPlayer.playerId + " - Building object is not defined.");
+ return;
+ }
+ buildable.constructionProgress = 0;
+ buildable.constructionTimer = LK.setInterval(function () {
+ buildable.constructionProgress += 0.1;
+ var progressFraction = buildable.constructionProgress / constructionTime;
+ if (currentPlayer.playerId === player1.playerId) {
+ buildable.progressDisplay.setProgress(progressFraction);
+ }
+ // Deduct spice progressively based on construction progress
+ var costPerTick = buildableInfo.cost * 0.1 / constructionTime;
+ currentPlayer.spice -= costPerTick;
+ if (currentPlayer.playerId === player1.playerId) {
+ updateBaseInfo();
+ }
+ // When construction is complete...
+ if (buildable.constructionProgress >= constructionTime) {
+ LK.clearInterval(buildable.constructionTimer);
+ console.log(currentPlayer.playerId + " - " + buildableType + " construction completed.");
+ buildable.constructionTimer = null;
+ if (currentPlayer.playerId === player1.playerId) {
+ buildable.progressDisplay.hide();
+ if (buildable.isBuilding) {
+ console.log(currentPlayer.playerId + " - Building Ready for placement ", buildable);
+ if (progressDisplay.parentIcon && typeof progressDisplay.parentIcon.setLabelToPlace === 'function') {
+ progressDisplay.parentIcon.setLabelToPlace(); // Change label text to 'Place'
+ }
+ currentBuildingForPlacement = buildable;
+ }
+ } else {
+ aiPlaceBuilding(buildable);
+ }
+ if (buildable.isUnit) {
+ console.log(currentPlayer.playerId + " - Unit Ready to spawn ", buildable);
+ var spawnCell = {
+ cellX: 0,
+ cellY: 0
+ };
+ if (buildableSourceFactory) {
+ console.log(currentPlayer.playerId + " - Found source factory ", buildableSourceFactory);
+ spawnCell.cellX = buildableSourceFactory.cellX;
+ spawnCell.cellY = buildableSourceFactory.cellY;
+ } else {
+ console.log(currentPlayer.playerId + " - No source factory found ", buildableSourceFactory);
+ }
+ spawnUnit(buildable.type, spawnCell.cellX, spawnCell.cellY, currentPlayer.playerId);
+ }
+ if (currentPlayer.playerId === player1.playerId) {
+ game.children.forEach(function (child) {
+ if (child instanceof BuildableItemIcon) {
+ child.asset.interactive = true;
+ child.alpha = 1.0;
+ }
+ });
+ }
+ }
+ }, 100);
+ if (currentPlayer.playerId === player1.playerId) {
+ buildable.progressDisplay = progressDisplay;
+ currentSelection.buildingQueue.push(buildable);
+ game.children.forEach(function (child) {
+ if (child instanceof BuildableItemIcon) {
+ child.asset.interactive = false;
+ }
+ });
+ // Instantiate and display the CancelActionButton on the command panel for buildings
+ if (buildable.isBuilding) {
+ cancelActionBtn = new CancelActionButton(commandPanel.x + commandPanel.width - 200, commandPanel.y + 200);
+ }
+ game.addChild(cancelActionBtn);
+ }
+}
var applyCellOccupation = function applyCellOccupation(cellX, cellY) {
var building = gameMap.cells[cellX][cellY].building;
if (building) {
for (var w = 0; w < building.cellW; w++) {
@@ -1834,9 +1960,9 @@
'unitLightTank': 2,
'unitHeavyTank': 4
};
var aiBaseBuildingList = {
- 'windTrap': 2,
+ 'windTrap': 3,
'spiceRefinery': 1,
'lightFactory': 1,
'heavyFactory': 1
};
@@ -1912,11 +2038,63 @@
}
console.log("aiActing...");
// 1) Meet buildings requirements
console.log("aiNeededBuildingList:", aiNeededBuildingList);
+ if (Object.keys(aiNeededBuildingList).length > 0 && !player2.isCurrentlyBuilding) {
+ aiHandleBuilding(aiNeededBuildingList);
+ }
// 2) Meet units requirements
console.log("aiNeededUnitsList:", aiNeededUnitsList);
}
+function aiHandleBuilding(buildingList) {
+ console.log("aiHandleBuilding...", buildingList);
+ if (player2.isCurrentlyBuilding) {
+ console.log("Already building...");
+ return;
+ }
+ player2.isCurrentlyBuilding = true;
+ // Build first in the list - Later handle priorities
+ enqueueBuildable2(Object.keys(buildingList)[0], null, player2);
+}
+function aiPlaceBuilding(buildable) {
+ console.log("aiPlaceBuilding...", buildable);
+ if (!buildable || !buildable.isBuilding) {
+ return;
+ }
+ var baseBuilding = findClosestConstructionYard(buildable);
+ /*
+ if (!baseBuilding) {
+ if (buildable.player1Id === player1.playerId) {
+ baseBuilding = {
+ cellX: rockIlot1Center.x,
+ cellY: rockIlot1Center.y
+ };
+ } else {
+ baseBuilding = {
+ cellX: rockIlot2Center.x,
+ cellY: rockIlot2Center.y
+ };
+ }
+ }
+ */
+ var freePosition = findAvailablePositionAroundBuilding(baseBuilding.cellX, baseBuilding.cellY);
+ var placeX = baseBuilding.cellX;
+ var placeY = baseBuilding.cellY;
+ if (freePosition && freePosition.length === 1) {
+ placeX += freePosition[0].cellX;
+ placeY += freePosition[0].cellY;
+ }
+ gameMap.cells[placeX][placeY].building = buildable;
+ buildable.cellX = placeX;
+ buildable.cellY = placeY;
+ buildable.x = placeX * tileSize;
+ buildable.y = placeY * tileSize;
+ gameMap.addChild(buildable);
+ if (buildable.playerId === player2.playerId) {
+ player2.addBuilding(buildable);
+ }
+ applyCellOccupation(placeX, placeY);
+}
/* ***************************************************************************************************** */
/* ********************************************* INIT FUNCTIONS ****************************************** */
/* ***************************************************************************************************** */
// Prepare the map
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