Skip to content

Commit

Permalink
Merge pull request #62 from S-Mackenzie1678/cities
Browse files Browse the repository at this point in the history
Settlements
  • Loading branch information
adamhutchings authored Nov 15, 2020
2 parents 057ca69 + 642f626 commit 859666b
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/org/qme/player/PoliticalEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class PoliticalEntity {

public String name;

ArrayList<Tile> territory = new ArrayList<>();
public ArrayList<Tile> territory = new ArrayList<>();

ArrayList<Settlement> ownedCities = new ArrayList<>();
public ArrayList<Settlement> ownedCities = new ArrayList<>();

ArrayList<Unit> troops = new ArrayList<>();

Expand Down
21 changes: 20 additions & 1 deletion src/org/qme/structure/Settlement.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.qme.structure;

import java.util.ArrayList;
import org.qme.main.QApplication;
import org.qme.player.PoliticalEntity;
import org.qme.world.Tile;

/**
* Just the basics of what I assume a settlement might need.
* @author adamhutchings
* @author S-Mackenzie1678
* @since pre3
*/
public class Settlement extends Structure {
Expand All @@ -20,14 +22,31 @@ public Settlement(QApplication app, Tile t, PoliticalEntity s) {
public Tile tile;

public PoliticalEntity directOwner;

public int population;
public int maxPopulation;

public double happiness;
public double crime;

// Will eventually become an array of the child class of Structure for processing buildings
private ArrayList<Structure> processingBuildings = new ArrayList();
// Ditto, but social buildings
private ArrayList<Structure> socialBuildings = new ArrayList();
// Ditto, but defense buildings
private ArrayList<Structure> defenseBuildings = new ArrayList();

@Override
public void action() {
// Money. We'll see. Who knows?
}

@Override
public void update(QApplication app) {}
public void update(QApplication app) {
if(this.population > this.maxPopulation) {
this.population = this.maxPopulation;
}
}

/**
* Is this the capital city? Checks if the owner is itself.
Expand Down
3 changes: 3 additions & 0 deletions src/org/qme/world/Tile.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.qme.main.GlobalState;
import org.qme.main.QApplication;
import org.qme.main.QObject;
import org.qme.structure.Structure;
import static org.qme.util.GlobalConstants.SQUASH_FACTOR;
import static org.qme.util.GlobalConstants.TILE_SIZE;
import static org.qme.util.GlobalConstants.TOOLTIPS;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class Tile extends QObject implements QRenderable, UIComponent {
//
public Unit occupier;

public Structure structure;

// Resources fun time
public String resource = "";

Expand Down
3 changes: 3 additions & 0 deletions src/org/qme/world/World.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.qme.world;

import org.qme.main.QApplication;
import org.qme.world.gen.SettlementGen;
import org.qme.world.gen.WorldGenNeo;
import org.qme.world.gen.WorldGenRandom;
import org.qme.world.gen.WorldGenSquigglyBlob;

/**
* Represents a 2D array of tiles
* @author adamhutchings
* @author S-Mackenzie1678
* @since pre0
*/
public class World {
Expand Down Expand Up @@ -56,6 +58,7 @@ public World(QApplication a, int x, int y) {
}
}

SettlementGen.settlementGive(this);
}

}
66 changes: 66 additions & 0 deletions src/org/qme/world/gen/SettlementGen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.qme.world.gen;

import java.util.ArrayList;
import java.util.Random;

import org.qme.player.PoliticalEntity;
import org.qme.structure.Settlement;
import org.qme.world.Tile;
import org.qme.world.TileType;
import org.qme.world.World;

/**
* Generates settlement
* CURSED!
* @author santiago
* @since pre5
*/
public class SettlementGen {
private static int settlementProbabilityModifier(Tile tile) {
if(tile.getType() == TileType.OCEAN) {
return 10000;
}
if(tile.getType() == TileType.SEA) {
return 2100000000;
}
if(tile.getType() == TileType.DESERT) {
return 4;
}
if(tile.getType() == TileType.PLAINS) {
return 1;
}
if(tile.getType() == TileType.FOREST) {
return 2;
}
if(tile.getType() == TileType.MOUNTAIN) {
return 3;
}
if(tile.getType() == TileType.HIGH_MOUNTAIN) {
return 5;
}
return 2100000000;
}

public static void settlementGive(World world) {
ArrayList<PoliticalEntity> civs = world.tiles[0][0].application.game.civilizations;
for(int w = 0; w < civs.size(); w++) {
while(civs.get(w).capital == null) {
for(int i = 0; i < world.xDimension; i++) {
for(int j = 0; j < world.yDimension; j++) {
Random rand = new Random();
if(rand.nextInt(17) == 0) {
if(rand.nextInt(settlementProbabilityModifier(world.tiles[i][j])) == 0) {
Settlement newCity = new Settlement(world.tiles[i][j].application, world.tiles[i][j], civs.get(w));
world.tiles[i][j].structure = newCity;
civs.get(w).capital = newCity;
civs.get(w).superior = null;
civs.get(w).territory.add(0, world.tiles[i][j]);
civs.get(w).ownedCities.add(0, newCity);
}
}
}
}
}
}
}
}

0 comments on commit 859666b

Please sign in to comment.