Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @ Author: Sagi Maor
- */
- import java.util.Scanner;
- import java.awt.Rectangle;
- import java.awt.Point;
- // dev & testing components
- boolean onlyText = true; // if true, the game uses no graphical assets.
- boolean mapEditor = false; // if true, the execution will set up the dev map editor mode.
- // draw components
- PFont f; // font oject(null) initialized only at setup
- int tick = 0; // tick increases by 1 each time the draw method initiates.
- // external data components
- PrintWriter output; // scanner that writes to data file
- // text components
- String[] decision = new String[6];
- String descriptionText = ""; // String that usually appears above decisions. Should be wheelable
- int[] decisionFill = new int[6]; // color fill for decisions
- int wheel =0; // Some text can be wheeled up / down with the mouse. this int tracks its location.
- int lineGap = 50; //blank space between choices
- int decisionX; int decisionY; // location where decisions start
- // Control componenet
- BorderBox[] borderBox = new BorderBox[90]; // create borederbox around clickable areas
- boolean clearBorderBox = false; // if true, borderboxes will be cleared with the draw instance.
- Point mousePoint = new Point(); // where the mouse is
- boolean lastClickWasOnDecision = false; // did the user clicked last time on decision or something else
- boolean activeDecision = false;
- String chosenDecision = ""; // the latest game player clicked on
- Legate chosenLegate; // the legate the game currently refers to
- Location chosenLocation; // the location the game is currently referring to.
- // Graphic components
- PImage[] tile = new PImage[20]; // types of map tiles.
- final int tileSize = 100;
- // Game components
- int startingLegions = 3; // amount of legions player decide dto start with
- Legate[] startingLegate = new Legate[8]; // first legates who attempt to join you.
- Region region; // The region where it all happens.
- Player player = new Player();
- void setup() {
- // setting draw components
- size(1200,1000);
- f = createFont("Arial",16,true);
- tile[0] = loadImage("/res/GreenBackground.png");
- tile[1] = loadImage("/res/SPQR.png");
- tile[2] = loadImage("/res/Mountains.png");
- tile[3] = loadImage("/res/Forest.png");
- tile[11] = loadImage("/res/Tent.png");
- tile[12] = loadImage("/res/RomanSoldierLeft.png");
- // Create a new file in the sketch directory
- output = createWriter("/data/metaData.txt");
- // initializing game components
- region = new Region();
- player.army = new Army();
- Legion playerLegion = new Legion();
- playerLegion.imperialLegion();
- playerLegion.leader = player;
- player.army.addLegion(playerLegion);
- player.army.setLeader(player);
- player.army.setLocation(region.getLocation(15,15));
- chosenLocation = player.army.getLocation();
- for(int i=0; i<startingLegate.length; i++) //available legates
- startingLegate[i]= new Legate();
- }
- void draw() {
- delay(20);
- fill(0); // default text color is always black, change it inside methods.
- textSize(16);
- background(255,255,255);
- if(tick==0)initDrawComponents();
- tick++;
- if(clearBorderBox == true)
- {
- clearBorderBoxes();
- clearBorderBox = false;
- println("### BB CLEARED ###");
- }
- //drawTestScreen();
- //drawFullGridMap();
- //drawAreaAround(14+(tick/50),14+(tick/100));
- if(startingLegions > 0 || player.army.secondLieutenant == null)
- chooseLegatesScreen();
- else if (true==true)
- //drawAreaAround(5+(tick/5000),5+(tick/5000));
- drawAreaAround(chosenLocation.x, chosenLocation.y);
- //centralMessage("The big man was looking over my shoulder to see there are no spiders");
- //noLoop();
- output.flush(); // Writes the remaining data to the file
- output.close(); // Finishes the file
- }
- /////////////////////////////////////// DRAW ON SCREEN METHODS //////////////////////////////////////////////
- void drawTestScreen()
- {
- //String s = "The quick brown fox jumps over the lazy dog.";
- //text(s, 10, 10, 70, 90); // Text wraps within text box
- text("Game running, \n \n \n tick = "+tick,300,90,60,600);
- }
- void drawFullGridMap()
- {
- textSize(14);
- for(int i=0; i<region.location.length; i++)
- {
- for(int j =0; j< region.location[0].length; j++)
- {
- text(region.location[i][j].terrain.substring(0,1), i*20,j*20);
- }
- }
- }
- void drawAreaAround(int _x, int _y)
- {
- // drawing 9x9 tiles around, center is usually player
- clearBorderBoxes();
- int offSet = 30;
- for(int i=0; i<9; i++)
- {
- for(int j =0; j< 9; j++)
- {
- int yPoint = j*tileSize+40;
- int xPoint = offSet+i*tileSize;
- if(onlyText == false)
- image(tile[0], offSet+xPoint,yPoint); // Green background tile
- try{
- addBorderBox(new BorderBox(region.location[_x-4+i][_y-4+j].getId(), offSet+xPoint, yPoint, tileSize, tileSize));
- if(onlyText){
- text(region.location[_x-4+i][_y-4+j].terrain.substring(0,1), offSet+xPoint,yPoint,tileSize,tileSize);
- }
- else {
- if(region.location[_x-4+i][_y-4+j].terrain.contains("Mountain")) image(tile[2], offSet+xPoint, yPoint); // Mountain tile
- if(region.location[_x-4+i][_y-4+j].terrain.contains("Forest")) image(tile[3], offSet+xPoint, yPoint); // Forest tile
- }
- if(_x == (_x-4+i) && _y == (_y-4+j))
- { //displaying center of display
- if(onlyText){
- text("0", offSet+xPoint, yPoint,tileSize,tileSize);
- } else {
- //image(tile[12], offSet+xPoint, yPoint,tileSize,tileSize); // Soldier logo
- }
- }
- if(player.army.location.getId().equals(region.location[_x-4+i][_y-4+j].getId()))
- {
- if(onlyText){
- text("A", offSet+xPoint, yPoint,tileSize,tileSize);
- } else {
- image(tile[12], offSet+xPoint, yPoint,tileSize,tileSize); // Soldier logo
- }
- }
- if(region.location[_x-4+i][_y-4+j].settlement!=null)
- { // displaying settlement
- if(onlyText){
- text("_", offSet+xPoint,yPoint,tileSize,tileSize);
- }
- else{
- image(tile[11], offSet+xPoint,yPoint,tileSize,tileSize); // tent logo
- }
- }
- }catch(Exception e){
- text("#", offSet+xPoint,yPoint);
- }
- }
- }
- }
- void chooseLegatesScreen()
- {
- for(int i = 0; i<startingLegate.length; i++)
- {
- if(startingLegate[i]!=null)
- {
- text(startingLegate[i].name, 70+(i*110), 150, 100, 400 );
- addBorderBox(new BorderBox(startingLegate[i].name, 70+(i*110), 150, 100, 150));
- getBorderBox(startingLegate[i].name).setToolTip(startingLegate[i].name+"");
- }
- }
- activeDecision = true;
- int x=0;
- clearDecisions();
- if(chosenLegate != null)
- {
- if(startingLegions >=1)
- {decision[x] = "Give "+chosenLegate.name+" control over one of the Legions("+startingLegions+" left)"; x++;}
- if(player.army.secondLieutenant == null)
- {decision[x] = "Make "+chosenLegate.name+" second in command of the army"; x++;}
- //decision[x] = "Offer him a position in the military tribune"; x++;
- text(descriptionText, 500, 250+wheel,400,800);
- decisionsLabel(decision, 500, 250+(descriptionText.length()/2), 400);
- }
- if(checkDecision("second"))
- {
- if(chosenLegate!=null)
- {
- player.army.secondLieutenant = chosenLegate;
- println(player.army.secondLieutenant.name+" was set");
- removeBorderBox(getBorderBox(chosenLegate.name));
- removeStartingLegate(chosenLegate);
- chosenLegate = null;
- }
- if(player.army.secondLieutenant != null)
- centralMessage(player.army.secondLieutenant.name+" will serve as your second");
- //removeDecision("second");
- }
- if(checkDecision("Legion"))
- {
- if(chosenLegate!=null)
- {
- Legion _l = player.army.createNewLegion(chosenLegate);
- startingLegions--;
- removeBorderBox(getBorderBox(chosenLegate.name));
- removeStartingLegate(chosenLegate);
- chosenLegate = null;
- lastClickWasOnDecision = true;
- }
- if(lastClickWasOnDecision)
- centralMessage(player.army.getLatestLegion().leader.getName()+" will serve as a legate over "+player.army.getLatestLegion().getName()+".");
- }
- if(startingLegions <= 0 && player.army.secondLieutenant != null)
- {
- clearBorderBox = true;
- }
- }
- public void clearDecisions()
- {
- for(int i = 0; i<decision.length; i++)
- {
- if(decision[i]!=null)
- {
- removeBorderBox(getBorderBox(decision[i]));
- decision[i] = null;
- }
- }
- }
- boolean checkDecision(String desc)
- {
- if(chosenDecision.contains(desc)) return true;
- return false;
- }
- void removeDecision(String desc)
- {
- // removing the decision and the associated borderBox
- for(int i=0; i<decision.length; i++)
- {
- if(decision[i]!=null && decision[i].contains(desc))
- {
- removeBorderBox(getBorderBox(decision[i]));
- decision[i] = null;
- break;
- }
- }
- }
- void centralMessage(String message)
- {
- int rectW = 450;
- int rectH = 600;
- fill(222,222,255);
- rect(width/2-rectW/2,height/2-rectH/2,rectW,rectH);
- fill(0);
- text(message, 25+width/2-rectW/2, 25+height/2-rectH/2,rectW-50,rectH-50);
- }
- /////////////////////////////////////// GRAPHICS //////////////////////////////////////////////
- void initDrawComponents()
- {
- background(255,255,255);
- stroke(175);
- textFont(f);
- fill(0);
- textAlign(LEFT);
- text("Sagi Maor",200,722);
- }
- void decisionsLabel(String[] decision, int _x, int _y, int _width)
- {
- fill(0);
- decisionX = _x;
- decisionY = _y;
- _width = 400;
- for(int i=0; i<decision.length; i++)
- {
- if(decision[i]!=null && decision[i].equals("")==false)
- {
- // Decision in place
- fill(decisionFill[i],0,0); // changes according to MouseMoved() method
- text((i+1)+") "+decision[i], decisionX, decisionY+wheel+(i*lineGap),_width,lineGap);
- addBorderBox(new BorderBox(decision[i], decisionX, decisionY+wheel+(i*lineGap),_width,lineGap));
- }
- fill(0);
- }
- }
- void addBorderBox(BorderBox _bb)
- {
- for(int i =0; i<borderBox.length; i++)
- {
- if(borderBox[i]!=null && borderBox[i].getName().equals(_bb.getName()))
- {
- // replace last border box with this. it changed location.
- if(replaceBorderBoxes(_bb)==false) //checking if it can replace an existing instance at the same place, instead of creating new instance
- {
- // if it could replace anything, creating new borderbox
- borderBox[i] = _bb;
- }
- else println(_bb.name+" replaced an existing instance");
- break; // exiting loop because its already there
- }
- if(borderBox[i] == null)
- {
- borderBox[i] = _bb;
- //System.out.println("***BB CREATED: "+borderBox[i].getName());
- break;
- }
- }
- }
- boolean replaceBorderBoxes(BorderBox _bb)
- {
- // replaces existing borderboxes if it is contained within the same location
- boolean bool = false;
- for(int i =0; i<borderBox.length; i++)
- {
- if(borderBox[i]!=null)
- {
- if(_bb.contains((Rectangle)borderBox[i]))
- {
- borderBox[i] = _bb;
- bool = true;
- }
- }
- }
- return bool;
- }
- BorderBox getBorderBox(String _s)
- {
- for(int i =0; i<borderBox.length; i++)
- {
- if(borderBox[i]!=null && borderBox[i].getName().contains(_s))
- {
- return borderBox[i];
- }
- }
- return null;
- }
- void removeBorderBox(BorderBox _bb)
- {
- for(int i =0; i<borderBox.length; i++)
- {
- if(borderBox[i]!=null && borderBox[i].getName().equals(_bb.getName()))
- {
- borderBox[i] = null;
- break; // exiting loop because its already there
- }
- }
- }
- void clearBorderBoxes()
- {
- for (int i=0; i<borderBox.length; i++)
- {
- borderBox[i] = null;
- }
- }
- /////////////////////////////////////// GAME COMPONENTS METHODOLOGY //////////////////////////////////////////////
- void removeStartingLegate(Legate _legate)
- {
- for(int i =0 ; i<startingLegate.length; i++)
- {
- if(startingLegate[i]!=null && startingLegate[i].getName().equals(_legate.getName()))
- {
- startingLegate[i]=null;
- break;
- }
- }
- }
- /////////////////////////////////////// KEY EVENTS //////////////////////////////////////////////
- void mouseWheel(MouseEvent event) {
- float e = event.getCount();
- wheel = (int)(wheel+(e*20));
- //println((int)(wheel+(e*20)));
- }
- void mouseMoved()
- { // when mouse hovers something
- mousePoint.move(mouseX, mouseY);
- hoverOnDecision();
- for(int i =0; i<borderBox.length; i++)
- {
- if(borderBox[i]!=null && borderBox[i].contains(mousePoint))
- {
- // add methods related to border boxes here.
- hoverMapTile(i);
- hoverToolTip(i);
- }
- }
- }
- void hoverToolTip(int i)
- {
- if(borderBox[i].toolTip != null)
- {
- println("***Hovering tooltip: "+borderBox[i].getToolTip());
- fill(255,200,200);
- rect(mouseX, mouseY, 300, 100);
- fill(0);
- text(borderBox[i].getToolTip()+"", mouseX+25, mouseY+10, 270, 90);
- fill(0);
- }
- }
- void hoverMapTile(int i)
- {
- int offSet = 20;
- for(int j = 0; j<region.location.length; j++)
- {
- for(int k = 0; k<region.location[j].length; k++)
- {
- if(region.location[j][k]!=null && region.location[j][k].getId().equals(borderBox[i].getName()))
- {
- //println("hovering: x"+j+", y"+k);
- text("*",borderBox[i].x,borderBox[i].y, tileSize,tileSize);
- }
- }
- }
- }
- void hoverOnDecision()
- {
- int _width = 400;
- if ( (mouseY-(decisionY+wheel))/lineGap < decisionFill.length && activeDecision == true && mouseX >= decisionX && mouseX <= decisionX+_width && mouseY >= decisionY+wheel && mouseY <= decisionY+wheel+500)
- {
- for(int i=0; i<decisionFill.length; i++)
- {
- if(decisionFill[i] != decisionFill[(mouseY-(decisionY+wheel))/lineGap]){
- decisionFill[i] =0;
- } else{
- decisionFill[(mouseY-(decisionY+wheel))/lineGap] = 245+i;
- //System.out.println("Filling index(tick:"+tick+"): "+(mouseY-(decisionY+wheel))/lineGap);
- }
- }
- }
- }
- void mousePressed()
- {
- chosenDecision = "REALLY NOTHING NO DECISION AT ALL AT THIS POINT MOVE ALONG NUTTING TO SEE MAY CHANGE L8R K THX HAHA BYE X0X";
- lastClickWasOnDecision = false;
- for(int i =0; i<borderBox.length; i++)
- {
- if(borderBox[i]!=null && borderBox[i].contains(mousePoint))
- {
- System.out.println("***Clicked on: "+borderBox[i].getName());
- clickLegatePortrait(i);
- clickOnDecision(i);
- clickOnMapTile(i);
- }
- }
- }
- void clickOnMapTile(int i)
- {
- for(int j = 0; j<region.location.length; j++)
- {
- for(int k = 0; k<region.location[j].length; k++)
- {
- if(region.location[j][k]!=null && region.location[j][k].getId().equals(borderBox[i].getName()))
- {
- println("**Supply: "+region.location[j][k].currentSupply);
- println("**ID: "+region.location[j][k].getId());
- region.getLocationsAround(region.location[j][k].x, region.location[j][k].y, 2);
- chosenLocation = region.location[j][k];
- }
- }
- }
- }
- void clickLegatePortrait(int i)
- {
- for(int j=0; j<startingLegate.length; j++)
- {
- if(startingLegate[j]!=null && borderBox[i].getName().equals(startingLegate[j].name))
- {
- chosenDecision = startingLegate[j].name;
- descriptionText = startingLegate[j].description;
- chosenLegate = startingLegate[j];
- }
- }
- }
- void clickOnDecision(int i)
- {
- for(int j=0; j<decision.length; j++)
- {
- if(decision[j]!=null && borderBox[i].getName().equals(decision[j]))
- {
- chosenDecision = decision[j];
- println("CHOICE: "+chosenDecision);
- }
- }
- }
- /////////////////////////////////////// CLASSES //////////////////////////////////////////////
- public class Region
- {
- // Map grid
- public String name="Gaul"; //Gaal, Hispania, etc
- public Location[][] location = new Location[30][30]; // player start at 25x25. He will never reach over 50 because the option will not be available
- public Region()
- {
- generateRegion();
- }
- public void generateRegion()
- {
- locationInit();
- if(getName().equals("Gaul"))
- {
- createPlains();
- int forests = (int)(Math.random() * 10) + 20; // 8-11 forests
- createForests(forests);
- int ridges = (int)(Math.random() * 20) + 60; // 12-16 ridges
- createRidges(ridges);
- createSettlements(14);
- }
- }
- public void locationInit()
- {
- for(int i=0; i<location.length; i++)
- {
- for(int j=0; j< location[i].length; j++)
- {
- location[i][j] = new Location(i,j);
- }
- }
- }
- public void createPlains()
- {
- if(getName().equals("Gaul"))
- {
- for(int i=0; i<location.length; i++)
- {
- for(int j=0; j< location[i].length; j++)
- {
- location[i][j].setTerrain("Plains");
- location[i][j].generateLocation();
- }
- }
- }
- }
- public void createForests(int iterations)
- {
- for(int i=0; i<iterations; i++)
- {
- createForest();
- }
- }
- public void createForest()
- {
- // creates a forest, starting in specified x and y
- int sqrSize = (int)(Math.random() * 3) + 3;
- int x = (int)(Math.random() * location.length) + 0; //between 0 to 49
- if(x > location.length-3) x=x-3; if(x<3) x=x+3;
- int y = (int)(Math.random() * location[0].length) +0;
- if(y > location[0].length-3) y=y-3; if(y<3) y=y+3;
- for(int i=0; i<(sqrSize*sqrSize); i++)
- {
- location[x-2+(i%sqrSize)][y-2+(i/sqrSize)].setTerrain("Forest");
- location[x-2+(i%sqrSize)][y-2+(i/sqrSize)].generateLocation();
- System.out.println("Forest in: x("+(x-2+(i%sqrSize))+"), y("+(y-2+(i/sqrSize))+")");
- }
- }
- public void createRidges(int iterations)
- {
- for(int i=0; i<iterations; i++)
- {
- createRidge();
- }
- }
- public void createRidge()
- {
- // creates a forest, 5x5, starting in specified x and y
- int x = (int)(Math.random() * location.length) + 0; //between 0 to 49
- if(x > location.length-3) x=x-3; if(x<3) x=x+3;
- int y = (int)(Math.random() * location[0].length) +0;
- if(y > location[0].length-3) y=y-3; if(y<3) y=y+3;
- int distance = (int)(Math.random() * 2) +2;
- int to = (int)(Math.random() * 2) + 1;
- if(to==1)
- {
- for(int i=0; i<distance; i++)
- {
- int offSet = (int)(Math.random() * 3) +0;
- location[x+i][y-1+offSet].setTerrain("Mountain");
- location[x+i][y-1+offSet].generateLocation();
- System.out.println("Mountain in: x("+(x+i)+"), y("+(y-1+offSet)+")");
- }
- }
- if(to==2)
- {
- for(int i=0; i<distance; i++)
- {
- int offSet = (int)(Math.random() * 3) +0;
- location[x-1+offSet][y+i].setTerrain("Mountain");
- location[x-1+offSet][y+i].generateLocation();
- System.out.println("Mountain in: x("+(x-1+offSet)+"), y("+(y+i)+")");
- }
- }
- }
- public void createSettlements(int iterations)
- {
- for(int i=0; i<iterations; i++)
- {
- int x = (int)(Math.random() * location.length) + 0; //between 0 to 49
- if(x > location.length-3) x=x-3; if(x<3) x=x+3;
- int y = (int)(Math.random() * location[0].length) +0;
- if(y > location[0].length-3) y=y-3; if(y<3) y=y+3;
- if(location[x][y].settlement==null)
- {
- Settlement s = new Settlement(location[x][y]);
- location[x][y].settlement = s;
- System.out.println("Settlement in: x("+(x)+"), y("+(y)+")");
- if(i<iterations/3)
- {
- s.generateSettlement(3);
- }
- else if(i<iterations/2)
- {
- s.generateSettlement(1);
- }
- else {
- s.generateSettlement(2);
- }
- }
- }
- }
- public Location getLocation(int _x, int _y)
- {
- return location[_x][_y];
- }
- public Location getLocation(Location _loc)
- {
- for(int i=0; i<location.length; i++)
- {
- for(int j=0; j<location[i].length; i++)
- {
- if(location[i][j].getId().equals(_loc.getId()))
- {
- return location[i][j];
- }
- }
- }
- return _loc;
- }
- public Location[][] getLocationsAround(int _x, int _y, int _radius)
- {
- // returning location matrix in an area around x,y location in a radius larger than 0.
- Location[][] localList = new Location[((_radius*2)+1)][((_radius*2)+1)];
- for(int i=0; i<((_radius*2)+1); i++)
- {
- for(int j =0; j<((_radius*2)+1); j++)
- {
- if( _x-_radius+i >= 0 && _x-_radius+i < location.length && _y-_radius+j >= 0 && _y-_radius+j < location[0].length && region.location[_x-_radius+i][_y-_radius+j] != null)
- {
- //println("i = "+i+", j = "+j);
- localList[i][j] = region.location[_x-_radius+i][_y-_radius+j];
- //println("** added location "+localList[i][j].getId());
- }
- }
- }
- return localList;
- }
- public String getName()
- {
- return name;
- }
- }
- public class Location
- {
- public String terrain; // Forest, Mountain, River, Plains
- public String id; //name + location. always unique
- public String[] trait = new String[10]; // traits like swamps, hills, caverns, etc
- public Settlement settlement = null;
- public int familiarity = 0; // how faimiliar the terrain is for the player's army?
- public int MAX_SUPPLY; //the maximum amount of forageable supplies at this terrain
- public int currentSupply; // the amount the location currently has
- public int x; // location on map x axis
- public int y; // location on map y axis
- public Location(int _x, int _y)
- {
- x = _x;
- y = _y;
- //generateLocation(); // Don't do it here, since name is still null.
- }
- public String getId()
- {
- return id;
- }
- public void setId(String _id)
- {
- id = _id;
- }
- public String getTerrain()
- {
- return terrain;
- }
- public void setTerrain(String _t)
- {
- terrain = _t;
- }
- public boolean isTraitExist(String t)
- {
- for(int i =0; i<trait.length; i++)
- {
- if(trait[i]!=null && trait[i].contains(t))
- return true;
- }
- return false;
- }
- public void generateLocation()
- {
- generateTraits();
- generateSupply();
- generateId();
- }
- public void generateTraits()
- {
- if(terrain.contains("Plains"))
- {
- int rand = (int)(Math.random() * 3) + 1;
- }
- }
- public void generateId()
- {
- id = ""+getTerrain()+", x"+x+", y"+y;
- }
- public void generateSupply()
- {
- MAX_SUPPLY = 5000;
- if(terrain.contains("Plain")){
- MAX_SUPPLY += (int)(Math.random() * 5000) + 30000;
- }
- if(terrain.contains("Forest")){
- MAX_SUPPLY += (int)(Math.random() * 5000) + 35000;
- }
- if(terrain.contains("Mountain")){
- MAX_SUPPLY += (int)(Math.random() * 5000) + 25000;
- }
- currentSupply = MAX_SUPPLY - ((int)(Math.random() * (MAX_SUPPLY/5)));
- }
- public int maxSupplyCarry(Army _army)
- {
- // returns the maximum amount of supply an army can carry in to this region.
- int maxSupply = 0;
- maxSupply = MAX_SUPPLY/2 + 5000;
- if(terrain.contains("Mountain")) maxSupply= maxSupply/3;
- if(_army.isTraitExist("Guide")) maxSupply= (maxSupply*120)/100; // guide allows you to carry more supply
- return maxSupply;
- }
- public int regeneration()
- {
- // the location regenerates resources. Happens at all times except in winter.
- int reg = 0;
- reg = (MAX_SUPPLY-currentSupply)/3; // regenerates 33% towards max.
- currentSupply = currentSupply + reg; // updating current supply
- return reg;
- }
- public int decay()
- {
- // the location decays in resources. happens usually in winter.
- int dec = 0;
- dec = currentSupply/3; // decays 33% towards 0.
- currentSupply = currentSupply - dec; // updating current supply
- return dec;
- }
- }
- public class Settlement {
- public int population = 600; //standard size for a settlement.
- public int attitude = 30; // attitude towards the army. 100 is great, 0 is hostile. 50 cautious
- public int pacified = 10; // how pacified are they.
- public int knowledge = 10; // knowledge of the army about the settlement
- public String[] trait = new String[10]; // physical traits. buildings, etc
- public String[] culture = new String[10]; // cultural traits
- public Location location; // the location they are at
- public Settlement()
- {
- }
- public Settlement(Location loc)
- {
- location = loc;
- }
- public Settlement(int population, int attitude, int pacified, int knowledge, String[] trait, Location location) {
- this.population = population;
- this.attitude = attitude;
- this.pacified = pacified;
- this.knowledge = knowledge;
- this.trait = trait;
- this.location = location;
- }
- public void generateSettlement(int hostility)
- {
- if(hostility == 3)
- {// big settlements ten to be proud and hostile towards the empire
- population = (int)(Math.random() * 2000) +3000;
- attitude = 0;
- pacified = 0;
- knowledge = 0;
- }
- if(hostility == 2)
- {
- population = (int)(Math.random() * 3000) +2000;
- attitude = 40;
- pacified = 10;
- knowledge = 0;
- }
- if(hostility == 1)
- {// mostly small settlements want to integrate to the roman empire
- population = (int)(Math.random() * 3000) +500;
- attitude = 70;
- pacified = 20;
- knowledge = 10;
- }
- generateTraits();
- generateCulture();
- }
- public void generateTraits()
- {
- // tbd. physical stuff they have. Walls, towers, feeding by river, by underground water, etc
- }
- public void generateCulture()
- {
- // tbd. How do they behave
- }
- public void addTrait(String t)
- {
- for(int i=0; i<trait.length; i++)
- {
- if(trait[i]==null)
- {
- trait[i] = t;
- break;
- }
- }
- }
- public int getPopulation() {
- return population;
- }
- public void setPopulation(int population) {
- this.population = population;
- }
- public int getAttitude() {
- return attitude;
- }
- public void setAttitude(int attitude) {
- this.attitude = attitude;
- }
- public int getPacified() {
- return pacified;
- }
- public void setPacified(int pacified) {
- this.pacified = pacified;
- }
- public int getKnowledge() {
- return knowledge;
- }
- public void setKnowledge(int knowledge) {
- this.knowledge = knowledge;
- }
- public String[] getTraitArray() {
- return trait;
- }
- public void setTrait(String[] trait) {
- this.trait = trait;
- }
- public Location getLocation() {
- return location;
- }
- public void setLocation(Location location) {
- this.location = location;
- }
- }
- public class Character
- {
- public String name = "";
- public String[] trait = new String[10]; // traits initiate at gamestart.
- public int age = 30; // age of the character
- public void addTrait(String t)
- {
- if(isTraitExist(t)==false)
- for(int i=0; i<trait.length; i++)
- {
- if(trait[i]==null){
- trait[i] = t;
- break;
- }
- }
- else System.out.println(t+" already exists");
- }
- public String getName() {
- return name;
- }
- public void setName(String n) {
- name = n;
- }
- public String[] getTraits()
- {
- return trait;
- }
- public boolean isTraitExist(String t)
- {
- for(int i=0; i<trait.length; i++)
- {
- if(trait[i]!=null && trait[i].equals(t)){
- return true;
- }
- }
- return false;
- }
- public int countTraits()
- {
- int count = 0;
- for(int i=0; i<trait.length; i++)
- {
- if(trait[i]!=null){
- count++;
- }
- }
- return count;
- }
- public void generateRomanName()
- {
- String firstName[] = {"Oppius", "Amulius", "Arruns", "Caius", "Lars", "Mamercus", "Manius",
- "Julianus", "Agrippa", "Tullus", "Drusus", "Tiberius", "Decius", "Augustus", "Marcus" };
- int first = (int)(Math.random() * firstName.length) + 0;
- String secondName[] = {"Ulpius", "Minucius", "Albanius", "Plotius", "Baebius", "Vesnius", "Sextius",
- "Titinius", "Matius", "Pontius", "Drusus", "Scribonius", "Titiedius", "Labienus", "Atilius" };
- int second = (int)(Math.random() * secondName.length) + 0;
- String thirdName[] = {"Murena", "Proxsimus", "Genesius", "Eclectus", "Ursinus", "Crispian", "Lentulus",
- "Scaevola", "Florens", "Bato", "Mauricia", "Synnoda", "Celata", "Iustina", "Tanica","Ramira","Tranio",
- "Vibius","Perpenna","Drusus","Brutus"};
- int third = (int)(Math.random() * thirdName.length) + 0;
- setName(firstName[first]+" "+secondName[second]+" "+thirdName[third]);
- }
- }
- public class Player extends Character
- {
- public Army army;
- public Player()
- {
- super();
- }
- }
- public class Legate extends Character
- {
- public Legion legion; // the legion he is a head of.
- public int attitude; // towards the player
- public int exp; // how much time he spent on campaigns, affects decision making and drilling effectiveness
- public int tolerance = 3; // how he feels about the barbarians. from 1-5, 1 is hateful, 5 is accepting.
- public String faction ="";// Reformist, conservative, or other political faction
- public String description;
- // for generation uses only
- public int points = 3;
- public Legate()
- {
- generateStats();
- generatePersonalityTraits();
- generateBackgroundTraits();
- generateDescription();
- }
- public void generateStats()
- {
- generateRomanName();
- age = (int)(Math.random() * 30) + 30;
- tolerance = (int)(Math.random() * 5) + 1; tolerance--;
- int r = (int)(Math.random() * 2) + 1;
- if(r==1) faction = "Reformist"; if(r==2) faction = "Conservative";
- exp = (int)(Math.random() * 50) + age;
- }
- public void generatePersonalityTraits()
- {
- int r = (int)(Math.random() * 8) + 1;
- switch(r)
- {
- case 1:
- // is less likely to betray you, and will tell you upfront if he is ungappy
- addTrait("Honest");
- points--;
- break;
- case 2:
- // Will only present one choice, and be offended if denied
- addTrait("Arrogant");
- points++;
- break;
- case 3:
- // More likely to betray you, will sieze opportunities for power to himself.
- addTrait("Ambitious");
- points++;
- break;
- case 4:
- // His legion will lose less morale in battle, better at charging, more likely to die.
- addTrait("Brave");
- points--;
- break;
- case 5:
- // Focus on discipline and tactics. His legion loses morale in uncertain cattles battles and gain morale in certain battles
- addTrait("Cautious");
- break;
- case 6:
- // His followers love him, low morale regenerates faster when resting
- addTrait("Cheerful");
- points--;
- break;
- case 7:
- // tends to be aggressive and jump to harsh decisions.
- addTrait("Wroth");
- points++;
- break;
- case 8:
- // Understands his position and is content with it, will present many options.
- addTrait("Humble");
- points--;
- break;
- }
- }
- public void generateBackgroundTraits()
- {
- int i =(int)(Math.random() * points) + 0; ;
- while(i<2) // that means the legate will have 2 traits
- {
- int r = (int)(Math.random() * 8) + 1;
- switch(r)
- {
- case 1:
- if(isTraitExist("Wroth")==false){ // wroth characters cant be diplomats.
- // More likely to succeed in diplomacy. Tends to negotiate rather than fight.
- addTrait("Diplomat");
- tolerance++;
- }
- else i--;
- break;
- case 2:
- // His attitude towards you will affect the senate.
- addTrait("Politician");
- break;
- case 3:
- // Will take more advantage of a good ground and fortification. More effective in siege.
- // Tends to favor sieges, learning the enemy, and building fortifications
- addTrait("Renowned Strategist");
- points--;
- break;
- case 4:
- // more likely to tip the odds and gain opportunities in battle.
- // Prefers to engage battles, initiative, and fast advancement
- if(isTraitExist("Cautious")==false) // Cautious characters cant be a tactician.
- addTrait("Adaptive Tactician");
- break;
- case 5:
- // Reduces supply cost of roadbuilding
- // Gives extra care about the supply lines of the army.
- addTrait("Ingenius Stewards");
- break;
- case 6:
- // You can never tell what he plans or thinks.
- // he often conjures brilliant plans out of a desperate situation. Sow dissent within the enemy, and bribe his way into a settlement
- if(isTraitExist("Honest")==false){ // honest characters cant be intriguer.
- addTrait("Cunning Intriguer");
- }
- break;
- case 7:
- // This man has travelled across many lands. He knows how to naviagte
- // +10 familiarity on every location you enter. lose less supply when marching. Can lead across impassable mountains.
- // Will always strive to move forward, but not when supplies are limited.
- if(age>32)
- addTrait("Veteran Guide");
- break;
- case 8:
- // Knows alot about the culture and beliefs of the barbarians
- // Prefers to get closer to settlements in order to study them. dislikes combat.
- if(age>38)
- {
- addTrait("Scholar");
- tolerance++;
- }
- break;
- }
- i++;
- }
- }
- public String experienceDescription()
- {
- String desc;
- if(exp <45) desc = "Little";
- else if(exp <70) desc = "Decent";
- else if(exp <90) desc = "Long";
- else desc = "Great";
- return desc;
- }
- public String generateDescription()
- {
- String desc = name+" is "+age+" years old."+
- " He has "+experienceDescription()+" experience as a Legate.";
- if(trait[0].contains("Wroth")) desc +=" He is known for his hot temper and aggressive decision making, sometimes throwing a tantrum when things go wrong.";
- if(trait[0].contains("Honest")) desc +=" He has a reputation as an honorable and honest man who doesn't beautify the truth and always tries to do the right thing.";
- if(trait[0].contains("Arrogant")) desc +=" He is extremely arrogant, and believes himself to be better than others. Gets envious when left out of a plan.";
- if(trait[0].contains("Ambitious")) desc +=" He is very ambitious, and cares a great deal for his prestige and status.";
- if(trait[0].contains("Brave")) desc +=" His bravery is renowned, known to take every opportunity for greatness and glory, sometimes to a dangerous extent.";
- if(trait[0].contains("Humble")) desc +=" He is humble and quiet.";
- if(trait[0].contains("Cheerful")) desc +=" His men love him, for he is kind and cheerful. Rumours tell he knows the story and name of everyone in his legion.";
- if(trait[0].contains("Cautious")) desc +=" He is a thoughtful and cautious man, who is sometime accused of being a coward. He is never to take any plan lightly.";
- if(isTraitExist("Scholar")) desc +=" Most of his free time he spends around books, practicing philosophy and scholarship. "+
- " He is always keen on stuying more about different cultures, and can contribute a great deal to understanding the barbarian way of life.";
- if(isTraitExist("Diplomat")) desc +=" When it comes to words and speech he is one of the best at it. Not once or twice he was called to speak before the senate.";
- if(isTraitExist("Veteran Guide")) desc +=" His military career and curiousity made him a natural guide within foreign land. "+
- " He has an intuition for studying new terrain, finding supplies and knows how to keep a foraging party safe from raids.";
- if(isTraitExist("Ingenius Stewards")) desc +=" Numbers click and make sense inside "+name+"'s head!"+
- " He is an avid thinker at keeping supply calculations in check, will never let a stock spoil and will always find the most cost-effective way around anything.";
- if(isTraitExist("Adaptive Tactician")) desc +=" "+name+" loves the field of war! He is an admirer of combat and tactics."+
- " Most of the time you can find him playing against his soldiers with his war-board, making tactical plans for the next forseen battle, inventing tricks and manuevers for any situation.";
- if(isTraitExist("Renowned Strategist")) desc +=" "+name+" is a Renowned Strategist, he always thinks for the long term, making sure the set-up for the coming battle favors his side."+
- " He prefers long preperations rather than haste, and knows alot about how to deal or build fortifications, sieges, and long term conflicts";
- if(isTraitExist("Politician")) desc +=" Politics is what concerns "+name+" the most. He has deep ties with almost every senator at the senate, and many owe him a favor."+
- " Getting to good graces with such man will surely reap benefits, and improve the attitude of some in the senate towards you";
- if(isTraitExist("Cunning Intriguer")) desc +=" No one knows exactly what "+name+" thinks or feels, but he certainly knows what everyone else is thinking and how to take advantage of it."+
- " Mastering intrigue and weaving his network is all he does, he has a way in and out of every situation. As if he knows and understnds everyone, even enemies of foreign culture...";
- if(tolerance<=1) desc +=" "+name+" hates the 'barbaric savages' who live outside of rome, and thinks they should all be purged.";
- if(tolerance==2) desc +=" "+name+" feels un-ease around none-roman citizens. He would rather make them enemies than friends..";
- if(tolerance==3) desc +=" "+name+" is indifferent towards none-roman citizens. He understands some may be of use, but he would rather not trust them.";
- if(tolerance==4) desc +=" "+name+" is tolerant towards none-roman citizens. He thinks they hold potential, and some could be of use as allies for the prosperity of rome.";
- if(tolerance>=5) desc +=" "+name+" regards none-roman citizens with the same respect he regards roman citizens. He is an admirer of their culture and beliefs.";
- //Cunning Intriguer
- description = desc;
- return desc;
- }
- public int getAttitude() {
- return attitude;
- }
- public void setAttitude(int attitude) {
- this.attitude = attitude;
- }
- public int getExp() {
- return exp;
- }
- public void setExp(int exp) {
- this.exp = exp;
- }
- public String getFaction() {
- return faction;
- }
- public void setFaction(String faction) {
- this.faction = faction;
- }
- public String getDescription() {
- return description;
- }
- public void setDescription(String d) {
- description = d;
- }
- }
- public class Legion
- {
- // an army is a collective of units marching in the same location.
- public String name = "";
- public Character leader; // the man leading the legion. If its a legion, its a legate
- public Legate legate; // the legate in control of the legion
- public int men;
- public int discipline; // 0-100
- public int morale; //0-100
- public int exp; //their effective power at battles
- public boolean mounted = false; //mounted units require 3 times supplies. They are better at flanking
- public Legion()
- {
- }
- public void imperialLegion()
- {
- men = 5000 + (int)(Math.random() * 200) + 1; ;
- discipline = 80;
- morale = 70;
- exp = 100;
- name = "The 1st Legion";
- }
- public String getName() {
- return name;
- }
- public void setName(String n) {
- name = n;
- }
- public void setLeader(Character _leader)
- {
- leader = _leader;
- }
- public Character getLeader()
- {
- return leader;
- }
- public int getMen() {
- return men;
- }
- public void setMen(int men) {
- this.men = men;
- }
- public int getDiscipline() {
- return discipline;
- }
- public void setDiscipline(int discipline) {
- this.discipline = discipline;
- }
- public int getMorale() {
- return morale;
- }
- public void setMorale(int morale) {
- this.morale = morale;
- }
- public int getExp() {
- return exp;
- }
- public void setExp(int exp) {
- this.exp = exp;
- }
- }
- public class Army
- {
- public String name; //Roman army, XXX's army, etc
- public int supply;
- public Legion[] legion = new Legion[10];
- public Character leader; // the man leading the army
- public Character secondLieutenant; // the man serving as second in command
- public Location location; // the location this army is currently at.
- public String auxillaryFocus = "Forage";
- public int forageRaidus = 50; // percentage. 0-100. usually goes 25, 50, 75. Base is 50
- public int totalMen()
- {
- int total=0;
- for(int i=0; i<legion.length; i++)
- {
- total+= legion[i].getMen();
- }
- return total;
- }
- public String getName() {
- return name;
- }
- public void setName(String n) {
- name = n;
- }
- public void setLeader(Character _leader)
- {
- leader = _leader;
- }
- public int getSupply()
- {
- return supply;
- }
- public void setSupply(int s)
- {
- supply = s;
- }
- public Location getLocation() {
- return location;
- }
- public void setLocation(Location location) {
- this.location = location;
- }
- public void setLocation(int _x, int _y)
- {
- location = region.getLocation(_x,_y);
- }
- public void addLegion(Legion _legion)
- {
- // adding an existing legion
- for(int i =0; i<legion.length; i++)
- {
- if(legion[i]==null)
- {
- legion[i] = _legion;
- break;
- }
- }
- }
- public Legion createNewLegion(Character _leader)
- {
- Legion _legion = new Legion();
- _legion.imperialLegion();
- _legion.leader = _leader;
- addLegion(_legion);
- return _legion;
- }
- public Legion getLatestLegion()
- {
- // returns the legion who is latest on the array. usually means latest to join.
- Legion latest = null;
- for(int i =0; i<legion.length; i++)
- {
- if(legion[i]!=null)
- {
- latest = legion[i];
- }
- }
- return latest;
- }
- public int forage()
- {
- int foraged = totalMen() +(int)(Math.random() * totalMen()) + 1;
- if(auxillaryFocus.equals("Forage")) foraged += (totalMen()/10);
- if(foraged < (location.currentSupply*forageRaidus)/100){
- foraged = (location.currentSupply*forageRaidus)/100;
- }
- location.currentSupply -= foraged;
- return foraged;
- }
- public void scout()
- { // increases familiarity around your area at the map.
- int multi = 1; // multiplying boosts from different effects
- if(isTraitExist("Guide")) multi++;
- if(auxillaryFocus.equals("Scouting")) multi++;
- location.familiarity += 10+(10*multi);
- int mountainBoost = 0;
- if(location.terrain.contains("Mountain")) mountainBoost+=10;
- for(int i=1; i<4; i++)
- {
- Location[][] scoutLoc = region.getLocationsAround(location.x, location.y, i);
- for(int j=0;j<scoutLoc.length;j++)
- {
- for(int k=0; k<scoutLoc[j].length; k++)
- {
- if( scoutLoc[j][k].terrain.contains("Forest"))
- scoutLoc[j][k].familiarity+= (int)(Math.random() * 5)+(2*multi);
- else if(scoutLoc[j][k].terrain.contains("Plain"))
- scoutLoc[j][k].familiarity+=(int)(Math.random() * 10)+((5+mountainBoost)*multi);
- else scoutLoc[j][k].familiarity+= scoutLoc[j][k].familiarity+=(int)(Math.random() * 10)+(5*multi);
- }
- }
- }
- }
- public int spoilage()
- {
- // this method calculates the amount of supply that gets spoiled. Spoilage happens only at the very end of a turn after consumed and used resources.
- int spoil = 0;
- int care = 0;
- if(isTraitExist("Steward")) care += 5; // more care, less spoilage.
- if(auxillaryFocus.equals("Maintenance")) care += 5;
- care += (int)(Math.random() * 20);
- if(care > 10)
- spoil = 0;
- else
- spoil = supply/(10+care);
- return spoil;
- }
- public Location moveTo(String _d)
- {
- // this causes the army to move a tile, this doesn't affect supplies or any other variable but the location
- // south is + in the y axis, north is -
- if(_d.equals("NW")) return location = region.getLocation(location.x-1, location.y-1);
- if(_d.equals("N")) return location = region.getLocation(location.x, location.y-1);
- if(_d.equals("NE")) return location = region.getLocation(location.x+1, location.y-1);
- if(_d.equals("E")) return location = region.getLocation(location.x+1, location.y);
- if(_d.equals("SE")) return location = region.getLocation(location.x+1, location.y+1);
- if(_d.equals("S")) return location = region.getLocation(location.x, location.y+1);
- if(_d.equals("SW")) return location = region.getLocation(location.x-1, location.y+1);
- if(_d.equals("W")) return location = region.getLocation(location.x-1, location.y);
- return null; // shouldn't happen.
- }
- public boolean isTraitExist(String _s)
- {
- // searching if anyone in the army has a certain trait
- boolean res = false;
- if(secondLieutenant.isTraitExist(_s)) res = true;
- for(int i=0; i< legion.length; i++)
- {
- if(legion[i] !=null && legion[i].legate !=null && legion[i].legate.isTraitExist(_s))
- return res;
- }
- return res;
- }
- // with less than 10 familiarity points you know nothing about a place. over 20 you assume supply, over 40 you know it, over 60 you know special traits.
- }
- public class BorderBox extends Rectangle
- {
- public String name; // identifier. Two borderBoxes should never have the same name
- public String toolTip = null; // tooltip box may appear when mouse hovers this borderbox.
- public BorderBox(String _n, int _x, int _y, int _width, int _height)
- {
- setBounds(_x, _y, _width, _height);
- name = _n;
- }
- public String getName()
- {
- return name;
- }
- public void setName(String n)
- {
- name = n;
- }
- public String getToolTip()
- {
- return toolTip;
- }
- public void setToolTip(String _s)
- {
- toolTip = _s;
- }
- }
- public class Base
- {
- public Army garrison = null; // garrisoned army. usually between 0-500 just to fend off raids.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement