mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
AI builds a taskforce
bugfixes and optimizations
This commit is contained in:
@@ -11,7 +11,11 @@ Player.finishedNavalFactory = false
|
||||
Player.startedExtractor = false
|
||||
Player.finishedExtractor = false
|
||||
Player.startedHarvesting = false
|
||||
Player.startedBuildingTaskforce = false
|
||||
Player.finishedBuildingTaskforce = false
|
||||
|
||||
--TODO use enum-like values instead of literals for order types
|
||||
--TODO simplify building construction
|
||||
function Player:buildFort()
|
||||
if self.startedFort then
|
||||
return true
|
||||
@@ -159,6 +163,36 @@ function Player:startHarvesting()
|
||||
return true
|
||||
end
|
||||
|
||||
function Player:buildTaskforce()
|
||||
landFactory = self:getUnitsByClass(UnitClass.LAND_FACTORY, 1)[1]:toFactory()
|
||||
|
||||
numWarMechs = 10
|
||||
numTanks = 5
|
||||
numArtillery = 5
|
||||
|
||||
if not self.startedBuildingTaskforce then
|
||||
self.startedBuildingTaskforce = true
|
||||
|
||||
for i = 0, numWarMechs do
|
||||
landFactory:appendToQueue(UnitId.WAR_MECH)
|
||||
end
|
||||
|
||||
for i = 0, numTanks do
|
||||
landFactory:appendToQueue(UnitId.TANK)
|
||||
end
|
||||
|
||||
for i = 0, numArtillery do
|
||||
landFactory:appendToQueue(UnitId.ARTILLERY)
|
||||
end
|
||||
end
|
||||
|
||||
currWarMechs = self:getUnitsByClass(UnitClass.WAR_MECH, -1)
|
||||
currTanks = self:getUnitsByClass(UnitClass.TANK, -1)
|
||||
currArtillery = self:getUnitsByClass(UnitClass.ARTILLERY, -1)
|
||||
|
||||
return #currWarMechs == numWarMechs and #currTanks == numTanks and #currArtillery == numArtillery
|
||||
end
|
||||
|
||||
Player.behaviour = {
|
||||
type = BTNodeType.SEQUENCE,
|
||||
children = {
|
||||
@@ -169,5 +203,6 @@ Player.behaviour = {
|
||||
{type = BTNodeType.FUNCTION, func = 'buildLandFactory'},
|
||||
{type = BTNodeType.FUNCTION, func = 'buildHarvester'},
|
||||
{type = BTNodeType.FUNCTION, func = 'startHarvesting'},
|
||||
{type = BTNodeType.FUNCTION, func = 'buildTaskforce'},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -196,6 +196,8 @@ units = {
|
||||
unitClass = UnitClass.RESOURCE_ROVER,
|
||||
unitType = UnitType.HOVER,
|
||||
armor = {ArmorType.CAST},
|
||||
capacity = 3000,
|
||||
loadRate = 1,
|
||||
isVehicle = true,
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
@@ -516,6 +518,7 @@ units = {
|
||||
isVehicle = false,
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
drawRate = 1,
|
||||
cost = 500,
|
||||
size = {x = 4, y = 1.15, z = 4},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
|
||||
+4
-1
@@ -11,7 +11,7 @@ namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd) : Structure(player, id, pos, rot, buildStatus), drawRate(10){
|
||||
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd) : Structure(player, id, pos, rot, buildStatus){
|
||||
if(!rd){
|
||||
vector<ResourceDeposit*> deposits;
|
||||
|
||||
@@ -27,6 +27,9 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
sol::table unitTable = generateView()["units"][id + 1];
|
||||
drawRate = unitTable["drawRate"];
|
||||
|
||||
Vector2 size = Vector2(lenHpBar, 10);
|
||||
ammountBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||
ammountForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1));
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ namespace battleship{
|
||||
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
|
||||
|
||||
Unit::displayUnitStats(buildStatusForeground, buildStatusBackground, trainingStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||
sol::table targTable = generateView()["units"][unitQueue[0]];
|
||||
sol::table targTable = generateView()["units"][unitQueue[0] + 1];
|
||||
int costRate = (int)targTable["cost"] / 100, trainRate = (int)targTable["buildTime"] / 100;
|
||||
|
||||
if(player->getRefineds() >= costRate && getTime() - lastTrainTime > trainRate){
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
#include "mapListbox.h"
|
||||
#include "map.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
#include <button.h>
|
||||
#include <checkbox.h>
|
||||
#include <slider.h>
|
||||
#include <textbox.h>
|
||||
#include <node.h>
|
||||
#include <text.h>
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
MapListbox::MapListbox(Vector2 pos, Vector2 size, std::vector<string> &lines, int maxDisplay, string fontPath, bool closeable) : Listbox(pos, size, lines, maxDisplay, fontPath, closeable){}
|
||||
|
||||
void MapListbox::onClose(){
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
|
||||
Listbox *mapListbox = guiManager->getListboxes()[0];
|
||||
int selectedMap = mapListbox->getSelectedOption();
|
||||
string mapName = wstringToString(mapListbox->getContents()[selectedMap]);
|
||||
string mapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/" + mapName + ".lua";
|
||||
int numSpawnPoints = Map::getNumSpawnPointsByMap(mapPath);
|
||||
|
||||
guiManager->readLuaScreenScript("singlePlayerMenu.lua");
|
||||
mapListbox = guiManager->getListboxes()[0];
|
||||
vector<Button*> buttons = guiManager->getButtons();
|
||||
guiManager->readLuaScreenScript("playerSelection.lua", buttons, vector<Listbox*>{mapListbox}, vector<Checkbox*>{}, vector<Slider*>{}, vector<Textbox*>{}, vector<Node*>{}, vector<Text*>{}, numSpawnPoints);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ namespace battleship{
|
||||
using namespace gameBase;
|
||||
using namespace std;
|
||||
|
||||
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name(n), refineds(10000) {}
|
||||
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name(n), refineds(30000) {}
|
||||
|
||||
Player::~Player() {}
|
||||
|
||||
|
||||
+5
-5
@@ -13,11 +13,11 @@ namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
ResourceRover::ResourceRover(Player *player, int id, Vector3 pos, Quaternion rot) :
|
||||
Vehicle(player, id, pos, rot),
|
||||
capacity(300),
|
||||
loadRate(10)
|
||||
{
|
||||
ResourceRover::ResourceRover(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot) {
|
||||
sol::table unitTable = generateView()["units"][id + 1];
|
||||
capacity = unitTable["capacity"];
|
||||
loadRate = unitTable["loadRate"];
|
||||
|
||||
Vector2 size = Vector2(lenHpBar, 10);
|
||||
loadBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||
loadForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 1, 0, 1));
|
||||
|
||||
Reference in New Issue
Block a user