Advertisement
Bidderlyn

Roman Triumph java

Jun 10th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 49.16 KB | None | 0 0
  1. /**
  2. * @ Author: Sagi Maor
  3. */
  4. import java.util.Scanner;
  5. import java.awt.Rectangle;
  6. import java.awt.Point;
  7.  
  8. // dev & testing components
  9. boolean onlyText = true; // if true, the game uses no graphical assets.
  10. boolean mapEditor = false; // if true, the execution will set up the dev map editor mode.
  11.  
  12. // draw components
  13. PFont f; // font oject(null) initialized only at setup
  14. int tick = 0; // tick increases by 1 each time the draw method initiates.
  15.  
  16. // external data components
  17. PrintWriter output; // scanner that writes to data file
  18.  
  19. // text components
  20. String[] decision = new String[6];
  21. String descriptionText = ""; // String that usually appears above decisions. Should be wheelable
  22. int[] decisionFill = new int[6]; // color fill for decisions
  23. int wheel =0; // Some text can be wheeled up / down with the mouse. this int tracks its location.
  24. int lineGap = 50; //blank space between choices
  25. int decisionX; int decisionY; // location where decisions start
  26.  
  27. // Control componenet
  28. BorderBox[] borderBox = new BorderBox[90]; // create borederbox around clickable areas
  29. boolean clearBorderBox = false; // if true, borderboxes will be cleared with the draw instance.
  30. Point mousePoint = new Point(); // where the mouse is
  31. boolean lastClickWasOnDecision = false; // did the user clicked last time on decision or something else
  32. boolean activeDecision = false;
  33. String chosenDecision = ""; // the latest game player clicked on
  34. Legate chosenLegate; // the legate the game currently refers to
  35. Location chosenLocation; // the location the game is currently referring to.
  36.  
  37. // Graphic components
  38. PImage[] tile = new PImage[20]; // types of map tiles.
  39. final int tileSize = 100;
  40.  
  41. // Game components
  42. int startingLegions = 3; // amount of legions player decide dto start with
  43. Legate[] startingLegate = new Legate[8]; // first legates who attempt to join you.
  44. Region region; // The region where it all happens.
  45. Player player = new Player();
  46.  
  47.  
  48. void setup() {
  49.   // setting draw components
  50.   size(1200,1000);
  51.   f = createFont("Arial",16,true);
  52.   tile[0] = loadImage("/res/GreenBackground.png");
  53.   tile[1] = loadImage("/res/SPQR.png");  
  54.   tile[2] = loadImage("/res/Mountains.png");
  55.   tile[3] = loadImage("/res/Forest.png");  
  56.   tile[11] = loadImage("/res/Tent.png");  
  57.   tile[12] = loadImage("/res/RomanSoldierLeft.png");  
  58.  
  59.   // Create a new file in the sketch directory
  60.   output = createWriter("/data/metaData.txt");
  61.  
  62.   // initializing game components
  63.   region = new Region();
  64.   player.army = new Army();
  65.   Legion playerLegion = new Legion();
  66.   playerLegion.imperialLegion();
  67.   playerLegion.leader = player;
  68.   player.army.addLegion(playerLegion);
  69.   player.army.setLeader(player);
  70.   player.army.setLocation(region.getLocation(15,15));
  71.   chosenLocation = player.army.getLocation();
  72.  
  73.   for(int i=0; i<startingLegate.length; i++) //available legates
  74.     startingLegate[i]= new Legate();
  75.  
  76. }
  77.  
  78. void draw() {
  79.   delay(20);
  80.   fill(0); // default text color is always black, change it inside methods.
  81.   textSize(16);
  82.   background(255,255,255);
  83.   if(tick==0)initDrawComponents();
  84.    tick++;
  85.    if(clearBorderBox == true)
  86.    {
  87.     clearBorderBoxes();
  88.     clearBorderBox = false;
  89.     println("### BB CLEARED ###");
  90.    }
  91.    
  92.   //drawTestScreen();
  93.   //drawFullGridMap();
  94.   //drawAreaAround(14+(tick/50),14+(tick/100));
  95.   if(startingLegions > 0 || player.army.secondLieutenant == null)
  96.      chooseLegatesScreen();
  97.   else if (true==true)
  98.   //drawAreaAround(5+(tick/5000),5+(tick/5000));
  99.   drawAreaAround(chosenLocation.x, chosenLocation.y);
  100.   //centralMessage("The big man was looking over my shoulder to see there are no spiders");
  101.   //noLoop();
  102.  
  103.  
  104.    output.flush(); // Writes the remaining data to the file
  105.    output.close(); // Finishes the file
  106.     }
  107.    
  108.  
  109. /////////////////////////////////////// DRAW ON SCREEN METHODS //////////////////////////////////////////////
  110.    
  111. void drawTestScreen()
  112. {
  113.   //String s = "The quick brown fox jumps over the lazy dog.";
  114.   //text(s, 10, 10, 70, 90);  // Text wraps within text box
  115.   text("Game running, \n \n \n tick = "+tick,300,90,60,600);
  116. }
  117.  
  118. void drawFullGridMap()
  119. {
  120.   textSize(14);
  121.   for(int i=0; i<region.location.length; i++)
  122.   {
  123.     for(int j =0; j< region.location[0].length; j++)
  124.     {
  125.       text(region.location[i][j].terrain.substring(0,1), i*20,j*20);
  126.     }
  127.   }
  128. }
  129.  
  130. void drawAreaAround(int _x, int _y)
  131. {
  132.   // drawing 9x9 tiles around, center is usually player
  133.  
  134.   clearBorderBoxes();
  135.   int offSet = 30;
  136.   for(int i=0; i<9; i++)
  137.   {
  138.     for(int j =0; j< 9; j++)
  139.     {
  140.       int yPoint = j*tileSize+40;
  141.        int xPoint = offSet+i*tileSize;
  142.        
  143.       if(onlyText == false)
  144.         image(tile[0],  offSet+xPoint,yPoint); // Green background tile
  145.        
  146.      try{  
  147.        addBorderBox(new BorderBox(region.location[_x-4+i][_y-4+j].getId(), offSet+xPoint, yPoint, tileSize, tileSize));  
  148.        
  149.       if(onlyText){
  150.        text(region.location[_x-4+i][_y-4+j].terrain.substring(0,1), offSet+xPoint,yPoint,tileSize,tileSize);
  151.        }
  152.        else {
  153.         if(region.location[_x-4+i][_y-4+j].terrain.contains("Mountain")) image(tile[2],  offSet+xPoint, yPoint); // Mountain tile
  154.         if(region.location[_x-4+i][_y-4+j].terrain.contains("Forest")) image(tile[3],  offSet+xPoint, yPoint); // Forest tile  
  155.          }
  156.          
  157.         if(_x == (_x-4+i) && _y == (_y-4+j))
  158.         { //displaying center of display
  159.           if(onlyText){
  160.            text("0", offSet+xPoint, yPoint,tileSize,tileSize);
  161.           } else {
  162.             //image(tile[12],  offSet+xPoint, yPoint,tileSize,tileSize); // Soldier logo
  163.           }
  164.         }
  165.        
  166.         if(player.army.location.getId().equals(region.location[_x-4+i][_y-4+j].getId()))
  167.         {
  168.           if(onlyText){
  169.            text("A", offSet+xPoint, yPoint,tileSize,tileSize);
  170.           } else {
  171.             image(tile[12],  offSet+xPoint, yPoint,tileSize,tileSize); // Soldier logo
  172.           }
  173.         }
  174.        
  175.         if(region.location[_x-4+i][_y-4+j].settlement!=null)
  176.          { // displaying settlement
  177.           if(onlyText){
  178.             text("_", offSet+xPoint,yPoint,tileSize,tileSize);
  179.            }
  180.            else{
  181.            image(tile[11],  offSet+xPoint,yPoint,tileSize,tileSize); // tent logo
  182.            }
  183.         }
  184.        
  185.       }catch(Exception e){
  186.         text("#", offSet+xPoint,yPoint);
  187.        }
  188.     }
  189.   }
  190.  
  191. }
  192.  
  193.  
  194. void chooseLegatesScreen()
  195. {
  196.  
  197.  
  198.   for(int i = 0; i<startingLegate.length; i++)
  199.   {
  200.     if(startingLegate[i]!=null)
  201.     {
  202.     text(startingLegate[i].name, 70+(i*110), 150, 100, 400 );
  203.     addBorderBox(new BorderBox(startingLegate[i].name, 70+(i*110), 150, 100, 150));  
  204.     getBorderBox(startingLegate[i].name).setToolTip(startingLegate[i].name+"");
  205.     }
  206.   }
  207.  
  208.   activeDecision = true;
  209.   int x=0;
  210.   clearDecisions();
  211.   if(chosenLegate != null)
  212.   {
  213.   if(startingLegions >=1)
  214.     {decision[x] = "Give "+chosenLegate.name+" control over one of the Legions("+startingLegions+" left)"; x++;}
  215.   if(player.army.secondLieutenant == null)
  216.     {decision[x] = "Make "+chosenLegate.name+" second in command of the army"; x++;}
  217.   //decision[x] = "Offer him a position in the military tribune"; x++;  
  218.  
  219.   text(descriptionText, 500, 250+wheel,400,800);
  220.   decisionsLabel(decision, 500,  250+(descriptionText.length()/2),  400);
  221.   }
  222.  
  223.  
  224.   if(checkDecision("second"))
  225.   {
  226.     if(chosenLegate!=null)
  227.     {
  228.       player.army.secondLieutenant = chosenLegate;
  229.       println(player.army.secondLieutenant.name+" was set");
  230.       removeBorderBox(getBorderBox(chosenLegate.name));
  231.       removeStartingLegate(chosenLegate);
  232.       chosenLegate = null;
  233.     }
  234.     if(player.army.secondLieutenant != null)
  235.       centralMessage(player.army.secondLieutenant.name+" will serve as your second");
  236.       //removeDecision("second");
  237.   }
  238.  
  239.   if(checkDecision("Legion"))
  240.   {
  241.     if(chosenLegate!=null)
  242.     {
  243.       Legion _l = player.army.createNewLegion(chosenLegate);
  244.       startingLegions--;
  245.       removeBorderBox(getBorderBox(chosenLegate.name));
  246.       removeStartingLegate(chosenLegate);
  247.       chosenLegate = null;
  248.       lastClickWasOnDecision = true;
  249.     }
  250.    
  251.     if(lastClickWasOnDecision)
  252.       centralMessage(player.army.getLatestLegion().leader.getName()+" will serve as a legate over "+player.army.getLatestLegion().getName()+".");
  253.    
  254.   }
  255.  
  256.   if(startingLegions <= 0 && player.army.secondLieutenant != null)
  257.   {
  258.     clearBorderBox = true;
  259.   }
  260. }
  261.  
  262. public void clearDecisions()
  263. {
  264.   for(int i = 0; i<decision.length; i++)
  265.   {
  266.    if(decision[i]!=null)
  267.    {
  268.    removeBorderBox(getBorderBox(decision[i]));
  269.    decision[i] = null;
  270.    }
  271.   }
  272. }
  273.  
  274. boolean checkDecision(String desc)
  275. {
  276.  
  277.   if(chosenDecision.contains(desc)) return true;
  278.   return false;
  279. }
  280.  
  281. void removeDecision(String desc)
  282. {
  283.  // removing the decision and the associated borderBox
  284.  for(int i=0; i<decision.length; i++)
  285.   {
  286.     if(decision[i]!=null && decision[i].contains(desc))
  287.     {
  288.       removeBorderBox(getBorderBox(decision[i]));
  289.       decision[i] = null;
  290.       break;
  291.     }
  292.   }
  293. }
  294.  
  295. void centralMessage(String message)
  296. {
  297.   int rectW = 450;
  298.   int rectH = 600;
  299.  fill(222,222,255);
  300.  rect(width/2-rectW/2,height/2-rectH/2,rectW,rectH);
  301.  fill(0);
  302.  text(message, 25+width/2-rectW/2, 25+height/2-rectH/2,rectW-50,rectH-50);
  303. }
  304.  
  305. /////////////////////////////////////// GRAPHICS //////////////////////////////////////////////
  306.  
  307. void initDrawComponents()
  308. {
  309.   background(255,255,255);
  310.   stroke(175);
  311.   textFont(f);      
  312.   fill(0);
  313.   textAlign(LEFT);
  314.   text("Sagi Maor",200,722);
  315. }
  316.  
  317. void decisionsLabel(String[] decision, int _x, int _y, int _width)
  318. {
  319.   fill(0);
  320.   decisionX = _x;
  321.   decisionY = _y;
  322.   _width = 400;
  323.  
  324.   for(int i=0; i<decision.length; i++)
  325.   {
  326.      if(decision[i]!=null && decision[i].equals("")==false)
  327.     {
  328.       // Decision in place  
  329.       fill(decisionFill[i],0,0); // changes according to MouseMoved() method
  330.       text((i+1)+") "+decision[i], decisionX, decisionY+wheel+(i*lineGap),_width,lineGap);
  331.       addBorderBox(new BorderBox(decision[i], decisionX, decisionY+wheel+(i*lineGap),_width,lineGap));
  332.     }
  333.     fill(0);
  334.   }
  335.  
  336. }
  337.  
  338.  
  339. void addBorderBox(BorderBox _bb)
  340. {
  341.  
  342.  
  343.   for(int i =0; i<borderBox.length; i++)
  344.   {
  345.    if(borderBox[i]!=null && borderBox[i].getName().equals(_bb.getName()))
  346.    {
  347.      // replace last border box with this. it changed location.
  348.      if(replaceBorderBoxes(_bb)==false) //checking if it can replace an existing instance at the same place, instead of creating new instance  
  349.      {
  350.        // if it could replace anything, creating new borderbox
  351.        borderBox[i] = _bb;
  352.      }
  353.      else println(_bb.name+" replaced an existing instance");
  354.      break; // exiting loop because its already there
  355.    }
  356.  
  357.    if(borderBox[i] == null)
  358.    {
  359.      borderBox[i] = _bb;
  360.      //System.out.println("***BB CREATED:  "+borderBox[i].getName());
  361.      break;
  362.    }
  363.   }
  364. }
  365.  
  366. boolean replaceBorderBoxes(BorderBox _bb)
  367. {
  368.  // replaces existing borderboxes if it is contained within the same location
  369.  boolean bool = false;
  370.  for(int i =0; i<borderBox.length; i++)
  371.  {
  372.   if(borderBox[i]!=null)
  373.   {
  374.     if(_bb.contains((Rectangle)borderBox[i]))
  375.      {
  376.         borderBox[i] = _bb;
  377.         bool = true;
  378.       }
  379.   }
  380.  }
  381.  
  382.  
  383.  return bool;
  384. }
  385.  
  386. BorderBox getBorderBox(String _s)
  387. {
  388.  for(int i =0; i<borderBox.length; i++)
  389.   {
  390.    if(borderBox[i]!=null && borderBox[i].getName().contains(_s))
  391.    {
  392.     return borderBox[i];
  393.    }
  394.   }
  395.    return null;
  396. }
  397.  
  398. void removeBorderBox(BorderBox _bb)
  399. {
  400.   for(int i =0; i<borderBox.length; i++)
  401.   {
  402.    if(borderBox[i]!=null && borderBox[i].getName().equals(_bb.getName()))
  403.    {
  404.      borderBox[i] = null;
  405.      break; // exiting loop because its already there
  406.    }
  407.  
  408.   }
  409. }
  410.  
  411. void clearBorderBoxes()
  412. {
  413.  for (int i=0; i<borderBox.length; i++)
  414.  {
  415.   borderBox[i] = null;
  416.  }
  417. }
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424. /////////////////////////////////////// GAME COMPONENTS METHODOLOGY //////////////////////////////////////////////
  425.  
  426. void removeStartingLegate(Legate _legate)
  427. {
  428.   for(int i =0 ; i<startingLegate.length; i++)
  429.   {
  430.    if(startingLegate[i]!=null && startingLegate[i].getName().equals(_legate.getName()))
  431.    {
  432.     startingLegate[i]=null;
  433.     break;
  434.    }
  435.   }
  436. }
  437.  
  438.  
  439.  
  440.  
  441.  
  442.  
  443. /////////////////////////////////////// KEY EVENTS //////////////////////////////////////////////
  444.  
  445. void mouseWheel(MouseEvent event) {
  446.   float e = event.getCount();
  447.   wheel = (int)(wheel+(e*20));
  448.   //println((int)(wheel+(e*20)));
  449. }
  450.  
  451.  
  452. void mouseMoved()
  453. { // when mouse hovers something
  454.   mousePoint.move(mouseX, mouseY);
  455.  
  456.   hoverOnDecision();
  457.  
  458.   for(int i =0; i<borderBox.length; i++)
  459.   {
  460.    
  461.    if(borderBox[i]!=null && borderBox[i].contains(mousePoint))
  462.    {
  463.      // add methods related to border boxes here.
  464.      hoverMapTile(i);
  465.      hoverToolTip(i);
  466.    }
  467.   }
  468.  
  469.  
  470. }
  471.  
  472.  
  473. void hoverToolTip(int i)
  474. {
  475.   if(borderBox[i].toolTip != null)
  476.   {
  477.     println("***Hovering tooltip: "+borderBox[i].getToolTip());
  478.     fill(255,200,200);
  479.     rect(mouseX, mouseY, 300, 100);
  480.     fill(0);
  481.     text(borderBox[i].getToolTip()+"", mouseX+25, mouseY+10, 270, 90);
  482.     fill(0);
  483.   }
  484. }
  485.  
  486. void hoverMapTile(int i)
  487. {
  488.   int offSet = 20;
  489.   for(int j = 0; j<region.location.length; j++)
  490.   {
  491.     for(int k = 0; k<region.location[j].length; k++)
  492.     {
  493.       if(region.location[j][k]!=null && region.location[j][k].getId().equals(borderBox[i].getName()))
  494.       {
  495.         //println("hovering: x"+j+", y"+k);
  496.         text("*",borderBox[i].x,borderBox[i].y, tileSize,tileSize);
  497.       }
  498.     }
  499.   }
  500. }
  501.  
  502. void hoverOnDecision()
  503. {
  504.   int _width = 400;
  505.   if ( (mouseY-(decisionY+wheel))/lineGap < decisionFill.length && activeDecision == true && mouseX >=  decisionX && mouseX <=  decisionX+_width && mouseY >=  decisionY+wheel && mouseY <=  decisionY+wheel+500)
  506.   {
  507.     for(int i=0; i<decisionFill.length; i++)
  508.     {
  509.       if(decisionFill[i] != decisionFill[(mouseY-(decisionY+wheel))/lineGap]){
  510.         decisionFill[i] =0;
  511.       } else{
  512.       decisionFill[(mouseY-(decisionY+wheel))/lineGap] = 245+i;
  513.       //System.out.println("Filling index(tick:"+tick+"): "+(mouseY-(decisionY+wheel))/lineGap);
  514.       }
  515.     }
  516.   }
  517. }
  518.  
  519.  
  520.  
  521. void mousePressed()
  522. {
  523.   chosenDecision = "REALLY NOTHING NO DECISION AT ALL AT THIS POINT MOVE ALONG NUTTING TO SEE MAY CHANGE L8R K THX HAHA BYE X0X";
  524.   lastClickWasOnDecision = false;
  525.   for(int i =0; i<borderBox.length; i++)
  526.   {
  527.    
  528.    if(borderBox[i]!=null && borderBox[i].contains(mousePoint))
  529.    {
  530.      System.out.println("***Clicked on:  "+borderBox[i].getName());
  531.      
  532.      clickLegatePortrait(i);
  533.      clickOnDecision(i);
  534.      clickOnMapTile(i);
  535.    }
  536.   }
  537. }
  538.  
  539. void clickOnMapTile(int i)
  540. {
  541.   for(int j = 0; j<region.location.length; j++)
  542.   {
  543.     for(int k = 0; k<region.location[j].length; k++)
  544.     {
  545.       if(region.location[j][k]!=null && region.location[j][k].getId().equals(borderBox[i].getName()))
  546.       {
  547.         println("**Supply: "+region.location[j][k].currentSupply);
  548.         println("**ID: "+region.location[j][k].getId());
  549.         region.getLocationsAround(region.location[j][k].x, region.location[j][k].y, 2);
  550.         chosenLocation = region.location[j][k];
  551.       }
  552.     }
  553.   }
  554. }
  555.  
  556. void clickLegatePortrait(int i)
  557. {
  558.      for(int j=0; j<startingLegate.length; j++)
  559.      {
  560.        if(startingLegate[j]!=null && borderBox[i].getName().equals(startingLegate[j].name))
  561.        {
  562.         chosenDecision = startingLegate[j].name;
  563.         descriptionText = startingLegate[j].description;
  564.         chosenLegate = startingLegate[j];
  565.        }
  566.      }
  567. }
  568.  
  569. void clickOnDecision(int i)
  570. {
  571.   for(int j=0; j<decision.length; j++)
  572.      {
  573.       if(decision[j]!=null && borderBox[i].getName().equals(decision[j]))
  574.       {
  575.        chosenDecision = decision[j];
  576.        println("CHOICE: "+chosenDecision);
  577.       }
  578.      }
  579. }
  580.  
  581.  
  582.  
  583.  
  584.  
  585.  
  586.  
  587. /////////////////////////////////////// CLASSES //////////////////////////////////////////////
  588.  
  589. public class Region
  590. {
  591.     // Map grid
  592.     public String name="Gaul"; //Gaal, Hispania, etc
  593.     public Location[][] location = new Location[30][30]; // player start at 25x25. He will never reach over 50 because the option will not be available
  594.    
  595.     public Region()
  596.     {
  597.         generateRegion();
  598.     }
  599.    
  600.     public void generateRegion()
  601.     {
  602.         locationInit();
  603.         if(getName().equals("Gaul"))
  604.         {
  605.             createPlains();
  606.             int forests = (int)(Math.random() * 10) + 20;  // 8-11 forests
  607.             createForests(forests);
  608.             int ridges = (int)(Math.random() * 20) + 60;  // 12-16 ridges
  609.             createRidges(ridges);
  610.             createSettlements(14);
  611.         }
  612.     }
  613.    
  614.     public void locationInit()
  615.     {
  616.         for(int i=0; i<location.length; i++)
  617.         {
  618.             for(int j=0; j< location[i].length; j++)
  619.             {
  620.                 location[i][j] = new Location(i,j);
  621.             }
  622.         }
  623.     }
  624.    
  625.     public void createPlains()
  626.     {
  627.         if(getName().equals("Gaul"))
  628.         {
  629.             for(int i=0; i<location.length; i++)
  630.             {
  631.                 for(int j=0; j< location[i].length; j++)
  632.                 {
  633.                     location[i][j].setTerrain("Plains");
  634.                     location[i][j].generateLocation();
  635.                 }
  636.             }
  637.         }
  638.     }
  639.    
  640.     public void createForests(int iterations)
  641.     {
  642.             for(int i=0; i<iterations; i++)
  643.             {
  644.                 createForest();
  645.             }
  646.     }
  647.    
  648.     public void createForest()
  649.     {
  650.         // creates a forest, starting in specified x and y
  651.         int sqrSize = (int)(Math.random() * 3) + 3;
  652.         int x = (int)(Math.random() * location.length) + 0; //between 0 to 49
  653.         if(x > location.length-3) x=x-3; if(x<3) x=x+3;
  654.         int y = (int)(Math.random() * location[0].length) +0;
  655.         if(y > location[0].length-3) y=y-3; if(y<3) y=y+3;
  656.         for(int i=0; i<(sqrSize*sqrSize); i++)
  657.         {
  658.            location[x-2+(i%sqrSize)][y-2+(i/sqrSize)].setTerrain("Forest");
  659.            location[x-2+(i%sqrSize)][y-2+(i/sqrSize)].generateLocation();
  660.            System.out.println("Forest in: x("+(x-2+(i%sqrSize))+"), y("+(y-2+(i/sqrSize))+")");
  661.         }
  662.        
  663.     }
  664.    
  665.     public void createRidges(int iterations)
  666.     {
  667.             for(int i=0; i<iterations; i++)
  668.             {
  669.                 createRidge();
  670.             }
  671.     }
  672.    
  673.     public void createRidge()
  674.     {
  675.         // creates a forest, 5x5, starting in specified x and y
  676.         int x = (int)(Math.random() * location.length) + 0; //between 0 to 49
  677.         if(x > location.length-3) x=x-3; if(x<3) x=x+3;
  678.         int y = (int)(Math.random() * location[0].length) +0;
  679.         if(y > location[0].length-3) y=y-3; if(y<3) y=y+3;
  680.         int distance = (int)(Math.random() * 2) +2;
  681.        
  682.         int to = (int)(Math.random() * 2) + 1;
  683.         if(to==1)
  684.         {
  685.             for(int i=0; i<distance; i++)
  686.             {
  687.                 int offSet = (int)(Math.random() * 3) +0;  
  688.                 location[x+i][y-1+offSet].setTerrain("Mountain");
  689.                 location[x+i][y-1+offSet].generateLocation();
  690.                 System.out.println("Mountain in: x("+(x+i)+"), y("+(y-1+offSet)+")");
  691.             }
  692.         }
  693.         if(to==2)
  694.         {
  695.             for(int i=0; i<distance; i++)
  696.             {
  697.                 int offSet = (int)(Math.random() * 3) +0;  
  698.                 location[x-1+offSet][y+i].setTerrain("Mountain");
  699.                 location[x-1+offSet][y+i].generateLocation();
  700.                 System.out.println("Mountain in: x("+(x-1+offSet)+"), y("+(y+i)+")");
  701.             }
  702.         }
  703.        
  704.     }
  705.    
  706.      public void createSettlements(int iterations)
  707.     {
  708.         for(int i=0; i<iterations; i++)
  709.         {
  710.             int x = (int)(Math.random() * location.length) + 0; //between 0 to 49
  711.             if(x > location.length-3) x=x-3; if(x<3) x=x+3;
  712.             int y = (int)(Math.random() * location[0].length) +0;
  713.             if(y > location[0].length-3) y=y-3; if(y<3) y=y+3;
  714.        
  715.            
  716.            if(location[x][y].settlement==null)
  717.            {
  718.             Settlement s = new Settlement(location[x][y]);
  719.             location[x][y].settlement = s;
  720.             System.out.println("Settlement in: x("+(x)+"), y("+(y)+")");
  721.             if(i<iterations/3)
  722.             {
  723.                s.generateSettlement(3);
  724.             }
  725.             else if(i<iterations/2)
  726.             {
  727.                s.generateSettlement(1);
  728.             }
  729.             else {
  730.                s.generateSettlement(2);
  731.             }
  732.            }
  733.            
  734.         }
  735.     }
  736.    
  737.     public Location getLocation(int _x, int _y)
  738.     {
  739.       return location[_x][_y];
  740.     }
  741.    
  742.     public Location getLocation(Location _loc)
  743.     {
  744.       for(int i=0; i<location.length; i++)
  745.       {
  746.        for(int j=0; j<location[i].length; i++)
  747.        {
  748.          if(location[i][j].getId().equals(_loc.getId()))
  749.          {
  750.            return location[i][j];
  751.          }
  752.        }
  753.       }
  754.       return _loc;
  755.     }
  756.    
  757.  public Location[][] getLocationsAround(int _x, int _y, int _radius)
  758.  {
  759.   // returning location matrix in an area around x,y location in a radius larger than 0.
  760.   Location[][] localList = new Location[((_radius*2)+1)][((_radius*2)+1)];
  761.   for(int i=0; i<((_radius*2)+1); i++)
  762.   {
  763.     for(int j =0; j<((_radius*2)+1); j++)
  764.     {
  765.       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)
  766.       {
  767.         //println("i = "+i+", j = "+j);
  768.         localList[i][j] = region.location[_x-_radius+i][_y-_radius+j];
  769.         //println("** added location "+localList[i][j].getId());
  770.       }
  771.      
  772.     }
  773.   }
  774.   return localList;
  775.  }
  776.    
  777.    
  778.     public String getName()
  779.     {
  780.         return name;
  781.     }
  782. }
  783.  
  784.  
  785.  
  786.  
  787.  
  788.  
  789. public class Location
  790. {
  791.    public String terrain; // Forest, Mountain, River, Plains
  792.    public String id; //name + location. always unique
  793.    public String[] trait = new String[10]; // traits like swamps, hills, caverns, etc
  794.    public Settlement settlement = null;
  795.    public int familiarity = 0; // how faimiliar the terrain is for the player's army?
  796.    public int MAX_SUPPLY; //the maximum amount of forageable supplies at this terrain
  797.    public int currentSupply; // the amount the location currently has
  798.    public int x; // location on map x axis
  799.    public int y; // location on map y axis
  800.    
  801.    
  802.    public Location(int _x, int _y)
  803.    {
  804.        x = _x;
  805.        y = _y;
  806.        //generateLocation(); // Don't do it here, since name is still null.
  807.     }
  808.    
  809.    public String getId()
  810.    {
  811.     return id;
  812.    }
  813.    
  814.    public void setId(String _id)
  815.    {
  816.     id = _id;
  817.    }
  818.    
  819.    public String getTerrain()
  820.    {
  821.        return terrain;
  822.     }
  823.    
  824.    public void setTerrain(String _t)
  825.    {
  826.        terrain = _t;
  827.     }
  828.    
  829.    public boolean isTraitExist(String t)
  830.    {
  831.        for(int i =0; i<trait.length; i++)
  832.        {
  833.            if(trait[i]!=null && trait[i].contains(t))
  834.             return true;
  835.         }
  836.         return false;
  837.     }
  838.    
  839.    public void generateLocation()
  840.    {
  841.     generateTraits();
  842.     generateSupply();
  843.     generateId();
  844.    }
  845.    
  846.    public void generateTraits()
  847.    {
  848.        if(terrain.contains("Plains"))
  849.        {
  850.            int rand = (int)(Math.random() * 3) + 1;
  851.            
  852.         }
  853.     }
  854.    
  855.     public void generateId()
  856.    {
  857.      id = ""+getTerrain()+", x"+x+", y"+y;
  858.     }
  859.    
  860.     public void generateSupply()
  861.     {
  862.       MAX_SUPPLY = 5000;
  863.      if(terrain.contains("Plain")){
  864.        MAX_SUPPLY += (int)(Math.random() * 5000) + 30000;
  865.      }
  866.        
  867.      if(terrain.contains("Forest")){
  868.        MAX_SUPPLY += (int)(Math.random() * 5000) + 35000;  
  869.      }
  870.        
  871.      if(terrain.contains("Mountain")){
  872.        MAX_SUPPLY += (int)(Math.random() * 5000) + 25000;  
  873.      }
  874.      
  875.      currentSupply = MAX_SUPPLY - ((int)(Math.random() * (MAX_SUPPLY/5)));
  876.     }
  877.    
  878.     public int maxSupplyCarry(Army _army)
  879.     {
  880.       // returns the maximum amount of supply an army can carry in to this region.
  881.       int maxSupply = 0;
  882.       maxSupply = MAX_SUPPLY/2 + 5000;
  883.       if(terrain.contains("Mountain")) maxSupply= maxSupply/3;
  884.       if(_army.isTraitExist("Guide")) maxSupply= (maxSupply*120)/100; // guide allows you to carry more supply
  885.       return maxSupply;
  886.     }
  887.    
  888.     public int regeneration()
  889.     {
  890.       // the location regenerates resources. Happens at all times except in winter.
  891.       int reg = 0;
  892.       reg = (MAX_SUPPLY-currentSupply)/3; // regenerates 33% towards max.
  893.       currentSupply = currentSupply + reg; // updating current supply
  894.       return reg;
  895.     }
  896.    
  897.     public int decay()
  898.     {
  899.       // the location decays in resources. happens usually in winter.
  900.       int dec = 0;
  901.       dec = currentSupply/3; // decays 33% towards 0.
  902.       currentSupply = currentSupply - dec; // updating current supply
  903.       return dec;
  904.     }
  905. }
  906.  
  907.  
  908.  
  909.  
  910.  
  911.  
  912. public class Settlement {
  913.   public int population = 600; //standard size for a settlement.
  914.     public int attitude = 30; // attitude towards the army. 100 is great, 0 is hostile. 50 cautious
  915.     public int pacified = 10; // how pacified are they.
  916.     public int knowledge = 10; // knowledge of the army about the settlement
  917.     public String[] trait = new String[10]; // physical traits. buildings, etc
  918.     public String[] culture = new String[10]; // cultural traits
  919.     public Location location; // the location they are at
  920.  
  921.     public Settlement()
  922.     {
  923.        
  924.     }
  925.    
  926.     public Settlement(Location loc)
  927.     {
  928.         location = loc;
  929.     }
  930.    
  931.   public Settlement(int population, int attitude, int pacified, int knowledge, String[] trait, Location location) {
  932.     this.population = population;
  933.     this.attitude = attitude;
  934.     this.pacified = pacified;
  935.     this.knowledge = knowledge;
  936.     this.trait = trait;
  937.     this.location = location;
  938.   }
  939.  
  940.   public void generateSettlement(int hostility)
  941.   {
  942.       if(hostility == 3)
  943.       {// big settlements ten to be proud and hostile towards the empire
  944.        population = (int)(Math.random() * 2000) +3000;
  945.        attitude = 0;
  946.        pacified = 0;
  947.        knowledge = 0;
  948.       }
  949.       if(hostility == 2)
  950.       {
  951.        population = (int)(Math.random() * 3000) +2000;
  952.        attitude = 40;
  953.        pacified = 10;
  954.        knowledge = 0;
  955.       }
  956.       if(hostility == 1)
  957.       {// mostly small settlements want to integrate to the roman empire
  958.        population = (int)(Math.random() * 3000) +500;
  959.        attitude = 70;
  960.        pacified = 20;
  961.        knowledge = 10;
  962.       }
  963.       generateTraits();
  964.       generateCulture();
  965.      }
  966.      
  967.   public void generateTraits()
  968.   {
  969.       // tbd. physical stuff they have. Walls, towers, feeding by river, by underground water, etc
  970.      }
  971.      
  972.   public void generateCulture()
  973.   {
  974.       // tbd. How do they behave
  975.      }
  976.      
  977.   public void addTrait(String t)
  978.   {
  979.       for(int i=0; i<trait.length; i++)
  980.       {
  981.           if(trait[i]==null)
  982.           {
  983.               trait[i] = t;
  984.               break;
  985.              }
  986.          }
  987.      }
  988.      
  989.   public int getPopulation() {
  990.     return population;
  991.   }
  992.   public void setPopulation(int population) {
  993.     this.population = population;
  994.   }
  995.   public int getAttitude() {
  996.     return attitude;
  997.   }
  998.   public void setAttitude(int attitude) {
  999.     this.attitude = attitude;
  1000.   }
  1001.   public int getPacified() {
  1002.     return pacified;
  1003.   }
  1004.   public void setPacified(int pacified) {
  1005.     this.pacified = pacified;
  1006.   }
  1007.   public int getKnowledge() {
  1008.     return knowledge;
  1009.   }
  1010.   public void setKnowledge(int knowledge) {
  1011.     this.knowledge = knowledge;
  1012.   }
  1013.   public String[] getTraitArray() {
  1014.     return trait;
  1015.   }
  1016.   public void setTrait(String[] trait) {
  1017.     this.trait = trait;
  1018.   }
  1019.   public Location getLocation() {
  1020.     return location;
  1021.   }
  1022.   public void setLocation(Location location) {
  1023.     this.location = location;
  1024.   }
  1025.  }
  1026.  
  1027.  
  1028.  
  1029.  
  1030.  
  1031. public class Character
  1032. {
  1033.     public String name = "";
  1034.     public String[] trait = new String[10]; // traits initiate at gamestart.
  1035.     public int age = 30; // age of the character
  1036.      
  1037.     public void addTrait(String t)
  1038.     {
  1039.        if(isTraitExist(t)==false)
  1040.         for(int i=0; i<trait.length; i++)
  1041.         {
  1042.             if(trait[i]==null){
  1043.                 trait[i] = t;
  1044.                 break;
  1045.               }
  1046.         }
  1047.        else System.out.println(t+" already exists");
  1048.     }
  1049.    
  1050.     public String getName() {
  1051.         return name;
  1052.     }
  1053.    
  1054.     public void setName(String n) {
  1055.         name = n;
  1056.     }
  1057.    
  1058.     public String[] getTraits()
  1059.     {
  1060.         return trait;
  1061.     }
  1062.    
  1063.     public boolean isTraitExist(String t)
  1064.     {
  1065.         for(int i=0; i<trait.length; i++)
  1066.         {
  1067.             if(trait[i]!=null && trait[i].equals(t)){
  1068.                 return true;
  1069.               }
  1070.         }
  1071.         return false;
  1072.     }
  1073.    
  1074.     public int countTraits()
  1075.     {
  1076.         int count = 0;
  1077.         for(int i=0; i<trait.length; i++)
  1078.         {
  1079.             if(trait[i]!=null){
  1080.                 count++;
  1081.               }
  1082.         }
  1083.         return count;
  1084.     }
  1085.    
  1086.     public void generateRomanName()
  1087.     {
  1088.         String firstName[] = {"Oppius", "Amulius", "Arruns", "Caius", "Lars", "Mamercus", "Manius",
  1089.         "Julianus", "Agrippa", "Tullus", "Drusus", "Tiberius", "Decius", "Augustus", "Marcus" };
  1090.         int first = (int)(Math.random() * firstName.length) + 0;
  1091.        
  1092.         String secondName[] = {"Ulpius", "Minucius", "Albanius", "Plotius", "Baebius", "Vesnius", "Sextius",
  1093.         "Titinius", "Matius", "Pontius", "Drusus", "Scribonius", "Titiedius", "Labienus", "Atilius" };
  1094.         int second = (int)(Math.random() * secondName.length) + 0;
  1095.        
  1096.         String thirdName[] = {"Murena", "Proxsimus", "Genesius", "Eclectus", "Ursinus", "Crispian", "Lentulus",
  1097.         "Scaevola", "Florens", "Bato", "Mauricia", "Synnoda", "Celata", "Iustina", "Tanica","Ramira","Tranio",
  1098.          "Vibius","Perpenna","Drusus","Brutus"};
  1099.         int third = (int)(Math.random() * thirdName.length) + 0;
  1100.        
  1101.         setName(firstName[first]+" "+secondName[second]+" "+thirdName[third]);
  1102.     }
  1103. }
  1104.  
  1105.  
  1106.  
  1107.  
  1108.  
  1109.  
  1110.  
  1111. public class Player extends Character
  1112. {
  1113.   public Army army;
  1114.  
  1115.   public Player()
  1116.   {
  1117.    super();
  1118.   }
  1119.  
  1120.  
  1121. }
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128. public class Legate extends Character
  1129. {
  1130.     public Legion legion; // the legion he is a head of.
  1131.     public int attitude; // towards the player
  1132.     public int exp; // how much time he spent on campaigns, affects decision making and drilling effectiveness
  1133.     public int tolerance = 3; // how he feels about the barbarians. from 1-5, 1 is hateful, 5 is accepting.
  1134.     public String faction ="";// Reformist, conservative, or other political faction
  1135.     public String description;
  1136.     // for generation uses only
  1137.     public int points = 3;
  1138.    
  1139.     public Legate()
  1140.     {
  1141.         generateStats();
  1142.         generatePersonalityTraits();
  1143.         generateBackgroundTraits();
  1144.         generateDescription();
  1145.      }
  1146.    
  1147.    public void generateStats()
  1148.    {
  1149.         generateRomanName();
  1150.         age = (int)(Math.random() * 30) + 30;
  1151.         tolerance = (int)(Math.random() * 5) + 1; tolerance--;
  1152.         int r = (int)(Math.random() * 2) + 1;
  1153.         if(r==1) faction = "Reformist"; if(r==2) faction = "Conservative";
  1154.         exp = (int)(Math.random() * 50) + age;
  1155.     }
  1156.      
  1157.     public void generatePersonalityTraits()
  1158.     {
  1159.             int r = (int)(Math.random() * 8) + 1;
  1160.             switch(r)
  1161.             {
  1162.                 case 1:
  1163.                 // is less likely to betray you, and will tell you upfront if he is ungappy
  1164.                 addTrait("Honest");
  1165.                 points--;
  1166.                 break;
  1167.                 case 2:
  1168.                 // Will only present one choice, and be offended if denied
  1169.                 addTrait("Arrogant");
  1170.                 points++;
  1171.                 break;
  1172.                 case 3:
  1173.                 // More likely to betray you, will sieze opportunities for power to himself.
  1174.                 addTrait("Ambitious");
  1175.                 points++;
  1176.                 break;
  1177.                 case 4:
  1178.                 // His legion will lose less morale in battle, better at charging, more likely to die.
  1179.                 addTrait("Brave");
  1180.                 points--;
  1181.                 break;
  1182.                 case 5:
  1183.                 // Focus on discipline and tactics. His legion loses morale in uncertain cattles battles and gain morale in certain battles
  1184.                 addTrait("Cautious");
  1185.                 break;
  1186.                 case 6:
  1187.                 // His followers love him, low morale regenerates faster when resting
  1188.                 addTrait("Cheerful");
  1189.                 points--;
  1190.                 break;
  1191.                 case 7:
  1192.                 // tends to be aggressive and jump to harsh decisions.
  1193.                 addTrait("Wroth");
  1194.                 points++;
  1195.                 break;
  1196.                 case 8:
  1197.                 // Understands his position and is content with it, will present many options.
  1198.                 addTrait("Humble");
  1199.                 points--;
  1200.                 break;
  1201.             }
  1202.     }
  1203.    
  1204.     public void generateBackgroundTraits()
  1205.     {
  1206.             int i =(int)(Math.random() * points) + 0; ;
  1207.             while(i<2) // that means the legate will have 2 traits
  1208.             {
  1209.             int r = (int)(Math.random() * 8) + 1;
  1210.              switch(r)
  1211.              {
  1212.                 case 1:
  1213.                 if(isTraitExist("Wroth")==false){ // wroth characters cant be diplomats.
  1214.                  // More likely to succeed in diplomacy. Tends to negotiate rather than fight.
  1215.                  addTrait("Diplomat");
  1216.                  tolerance++;
  1217.                 }
  1218.                 else i--;
  1219.                 break;
  1220.                 case 2:
  1221.                 // His attitude towards you will affect the senate.
  1222.                 addTrait("Politician");
  1223.                 break;
  1224.                 case 3:
  1225.                 // Will take more advantage of a good ground and fortification. More effective in siege.
  1226.                 // Tends to favor sieges, learning the enemy, and building fortifications
  1227.                 addTrait("Renowned Strategist");
  1228.                 points--;
  1229.                 break;
  1230.                 case 4:
  1231.                 // more likely to tip the odds and gain opportunities in battle.
  1232.                 // Prefers to engage battles, initiative, and fast advancement
  1233.                 if(isTraitExist("Cautious")==false) // Cautious characters cant be a tactician.
  1234.                 addTrait("Adaptive Tactician");
  1235.                 break;
  1236.                 case 5:
  1237.                 // Reduces supply cost of roadbuilding
  1238.                 // Gives extra care about the supply lines of the army.
  1239.                 addTrait("Ingenius Stewards");
  1240.                 break;
  1241.                 case 6:
  1242.                 // You can never tell what he plans or thinks.
  1243.                 // he often conjures brilliant plans out of a desperate situation. Sow dissent within the enemy, and bribe his way into a settlement
  1244.                  if(isTraitExist("Honest")==false){ // honest characters cant be intriguer.
  1245.                  addTrait("Cunning Intriguer");
  1246.                  }
  1247.                 break;
  1248.                 case 7:
  1249.                 // This man has travelled across many lands. He knows how to naviagte
  1250.                 // +10 familiarity on every location you enter. lose less supply when marching. Can lead across impassable mountains.
  1251.                 // Will always strive to move forward, but not when supplies are limited.
  1252.                 if(age>32)
  1253.                 addTrait("Veteran Guide");
  1254.                 break;
  1255.                 case 8:
  1256.                 // Knows alot about the culture and beliefs of the barbarians
  1257.                 // Prefers to get closer to settlements in order to study them. dislikes combat.
  1258.                 if(age>38)
  1259.                 {
  1260.                  addTrait("Scholar");
  1261.                  tolerance++;
  1262.                  }
  1263.                 break;
  1264.               }
  1265.              i++;
  1266.             }
  1267.     }
  1268.    
  1269.     public String experienceDescription()
  1270.     {
  1271.         String desc;
  1272.         if(exp <45) desc = "Little";
  1273.         else if(exp <70) desc = "Decent";
  1274.         else if(exp <90) desc = "Long";
  1275.         else  desc = "Great";
  1276.        
  1277.         return desc;
  1278.     }
  1279.    
  1280.     public String generateDescription()
  1281.     {
  1282.         String desc = name+" is "+age+" years old."+
  1283.         " He has "+experienceDescription()+" experience as a Legate.";
  1284.         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.";
  1285.         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.";
  1286.         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.";
  1287.         if(trait[0].contains("Ambitious")) desc +=" He is very ambitious, and cares a great deal for his prestige and status.";
  1288.         if(trait[0].contains("Brave")) desc +=" His bravery is renowned, known to take every opportunity for greatness and glory, sometimes to a dangerous extent.";
  1289.         if(trait[0].contains("Humble")) desc +=" He is humble and quiet.";
  1290.         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.";
  1291.         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.";
  1292.        
  1293.         if(isTraitExist("Scholar"))  desc +=" Most of his free time he spends around books, practicing philosophy and scholarship. "+
  1294.         " He is always keen on stuying more about different cultures, and can contribute a great deal to understanding the barbarian way of life.";
  1295.         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.";
  1296.         if(isTraitExist("Veteran Guide"))  desc +=" His military career and curiousity made him a natural guide within foreign land. "+
  1297.         " He has an intuition for studying new terrain, finding supplies and knows how to keep a foraging party safe from raids.";
  1298.         if(isTraitExist("Ingenius Stewards"))  desc +=" Numbers click and make sense inside "+name+"'s head!"+
  1299.         " 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.";
  1300.         if(isTraitExist("Adaptive Tactician"))  desc +=" "+name+" loves the field of war! He is an admirer of combat and tactics."+
  1301.         " 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.";
  1302.         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."+
  1303.         " He prefers long preperations rather than haste, and knows alot about how to deal or build fortifications, sieges, and long term conflicts";
  1304.         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."+
  1305.         " Getting to good graces with such man will surely reap benefits, and improve the attitude of some in the senate towards you";
  1306.         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."+
  1307.         " 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...";
  1308.        
  1309.         if(tolerance<=1) desc +=" "+name+" hates the 'barbaric savages' who live outside of rome, and thinks they should all be purged.";
  1310.         if(tolerance==2) desc +=" "+name+" feels un-ease around none-roman citizens. He would rather make them enemies than friends..";
  1311.         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.";
  1312.         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.";
  1313.         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.";
  1314.         //Cunning Intriguer
  1315.         description = desc;
  1316.         return desc;
  1317.     }
  1318.    
  1319.     public int getAttitude() {
  1320.         return attitude;
  1321.     }
  1322.     public void setAttitude(int attitude) {
  1323.         this.attitude = attitude;
  1324.     }
  1325.     public int getExp() {
  1326.         return exp;
  1327.     }
  1328.     public void setExp(int exp) {
  1329.         this.exp = exp;
  1330.     }
  1331.     public String getFaction() {
  1332.         return faction;
  1333.     }
  1334.     public void setFaction(String faction) {
  1335.         this.faction = faction;
  1336.     }
  1337.     public String getDescription() {
  1338.         return description;
  1339.     }
  1340.     public void setDescription(String d) {
  1341.         description = d;
  1342.     }
  1343.    
  1344. }
  1345.  
  1346.  
  1347.  
  1348.  
  1349.  
  1350. public class Legion
  1351. {
  1352.     // an army is a collective of units marching in the same location.
  1353.     public String name = "";
  1354.     public Character leader; // the man leading the legion. If its a legion, its a legate
  1355.    
  1356.     public Legate legate; // the legate in control of the legion
  1357.     public int men;
  1358.     public int discipline; // 0-100
  1359.     public int morale; //0-100
  1360.     public int exp; //their effective power at battles
  1361.     public boolean mounted = false; //mounted units require 3 times supplies. They are better at flanking
  1362.     public Legion()
  1363.     {
  1364.        
  1365.     }
  1366.    
  1367.     public void imperialLegion()
  1368.     {
  1369.      men = 5000 + (int)(Math.random() * 200) + 1; ;
  1370.      discipline = 80;
  1371.      morale = 70;
  1372.      exp = 100;
  1373.      name = "The 1st Legion";
  1374.     }
  1375.    
  1376.     public String getName() {
  1377.     return name;
  1378.   }
  1379.  
  1380.   public void setName(String n) {
  1381.     name = n;
  1382.   }
  1383.    
  1384.     public void setLeader(Character _leader)
  1385.     {
  1386.         leader = _leader;
  1387.     }
  1388.    
  1389.     public Character getLeader()
  1390.     {
  1391.         return leader;
  1392.     }
  1393.    
  1394.     public int getMen() {
  1395.     return men;
  1396.   }
  1397.  
  1398.   public void setMen(int men) {
  1399.     this.men = men;
  1400.   }
  1401.  
  1402.   public int getDiscipline() {
  1403.     return discipline;
  1404.   }
  1405.  
  1406.   public void setDiscipline(int discipline) {
  1407.     this.discipline = discipline;
  1408.   }
  1409.  
  1410.   public int getMorale() {
  1411.     return morale;
  1412.   }
  1413.  
  1414.   public void setMorale(int morale) {
  1415.     this.morale = morale;
  1416.   }
  1417.  
  1418.   public int getExp() {
  1419.     return exp;
  1420.   }
  1421.  
  1422.   public void setExp(int exp) {
  1423.     this.exp = exp;
  1424.   }
  1425. }
  1426.  
  1427.  
  1428.  
  1429.  
  1430.  
  1431.  
  1432.  
  1433. public class Army
  1434. {
  1435.     public String name; //Roman army, XXX's army, etc
  1436.     public int supply;
  1437.     public Legion[] legion = new Legion[10];
  1438.     public Character leader; // the man leading the army
  1439.     public Character secondLieutenant; // the man serving as second in command
  1440.     public Location location; // the location this army is currently at.
  1441.     public String auxillaryFocus = "Forage";
  1442.     public int forageRaidus = 50; // percentage. 0-100. usually goes 25, 50, 75. Base is 50
  1443.     public int totalMen()
  1444.     {
  1445.         int total=0;
  1446.         for(int i=0; i<legion.length; i++)
  1447.         {
  1448.             total+= legion[i].getMen();
  1449.         }
  1450.         return total;
  1451.     }
  1452.    
  1453.      public String getName() {
  1454.     return name;
  1455.   }
  1456.  
  1457.   public void setName(String n) {
  1458.     name = n;
  1459.   }
  1460.    
  1461.     public void setLeader(Character _leader)
  1462.     {
  1463.         leader = _leader;
  1464.     }
  1465.    
  1466.     public int getSupply()
  1467.     {
  1468.         return supply;
  1469.     }
  1470.    
  1471.     public void setSupply(int s)
  1472.     {
  1473.         supply = s;
  1474.     }
  1475.    
  1476.     public Location getLocation() {
  1477.     return location;
  1478.   }
  1479.  
  1480.   public void setLocation(Location location) {
  1481.     this.location = location;
  1482.   }
  1483.  
  1484.   public void setLocation(int _x, int _y)
  1485.   {
  1486.     location = region.getLocation(_x,_y);
  1487.   }
  1488.  
  1489.   public void addLegion(Legion _legion)
  1490.     {
  1491.       // adding an existing legion
  1492.      for(int i =0; i<legion.length; i++)
  1493.      {
  1494.       if(legion[i]==null)
  1495.       {
  1496.        legion[i] = _legion;
  1497.        break;
  1498.       }
  1499.      }
  1500.     }
  1501.  
  1502.   public Legion createNewLegion(Character _leader)
  1503.   {
  1504.   Legion _legion = new Legion();
  1505.   _legion.imperialLegion();
  1506.   _legion.leader = _leader;
  1507.   addLegion(_legion);
  1508.   return _legion;
  1509.   }
  1510.  
  1511.   public Legion getLatestLegion()
  1512.   {
  1513.    // returns the legion who is latest on the array. usually means latest to join.
  1514.    Legion latest = null;
  1515.    for(int i =0; i<legion.length; i++)
  1516.    {
  1517.     if(legion[i]!=null)
  1518.     {
  1519.      latest = legion[i];
  1520.     }
  1521.    }
  1522.    
  1523.     return latest;
  1524.   }
  1525.  
  1526.   public int forage()
  1527.   {
  1528.     int foraged = totalMen() +(int)(Math.random() * totalMen()) + 1;
  1529.     if(auxillaryFocus.equals("Forage")) foraged += (totalMen()/10);
  1530.     if(foraged < (location.currentSupply*forageRaidus)/100){
  1531.        foraged = (location.currentSupply*forageRaidus)/100;
  1532.     }
  1533.     location.currentSupply -= foraged;
  1534.     return foraged;
  1535.   }
  1536.  
  1537.   public void scout()
  1538.   { // increases familiarity around your area at the map.
  1539.  
  1540.     int multi = 1; // multiplying boosts from different effects
  1541.     if(isTraitExist("Guide")) multi++;
  1542.     if(auxillaryFocus.equals("Scouting")) multi++;
  1543.     location.familiarity += 10+(10*multi);
  1544.     int mountainBoost = 0;
  1545.     if(location.terrain.contains("Mountain")) mountainBoost+=10;
  1546.     for(int i=1; i<4; i++)
  1547.     {
  1548.      Location[][] scoutLoc = region.getLocationsAround(location.x, location.y, i);
  1549.        for(int j=0;j<scoutLoc.length;j++)
  1550.        {
  1551.         for(int k=0; k<scoutLoc[j].length; k++)
  1552.         {
  1553.          if( scoutLoc[j][k].terrain.contains("Forest"))
  1554.            scoutLoc[j][k].familiarity+= (int)(Math.random() * 5)+(2*multi);
  1555.          else if(scoutLoc[j][k].terrain.contains("Plain"))
  1556.            scoutLoc[j][k].familiarity+=(int)(Math.random() * 10)+((5+mountainBoost)*multi);
  1557.          else  scoutLoc[j][k].familiarity+= scoutLoc[j][k].familiarity+=(int)(Math.random() * 10)+(5*multi);
  1558.         }
  1559.        }
  1560.     }
  1561.   }
  1562.  
  1563.   public int spoilage()
  1564.   {
  1565.     // 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.
  1566.     int spoil = 0;
  1567.     int care = 0;
  1568.     if(isTraitExist("Steward")) care += 5; // more care, less spoilage.
  1569.     if(auxillaryFocus.equals("Maintenance")) care += 5;
  1570.     care += (int)(Math.random() * 20);
  1571.     if(care > 10)
  1572.       spoil = 0;
  1573.     else  
  1574.       spoil = supply/(10+care);
  1575.    
  1576.     return spoil;
  1577.   }
  1578.  
  1579.   public Location moveTo(String _d)
  1580.   {
  1581.     // this causes the army to move a tile, this doesn't affect supplies or any other variable but the location
  1582.     // south is + in the y axis, north is -
  1583.    
  1584.      if(_d.equals("NW")) return location = region.getLocation(location.x-1, location.y-1);
  1585.      if(_d.equals("N")) return location = region.getLocation(location.x, location.y-1);
  1586.      if(_d.equals("NE")) return location = region.getLocation(location.x+1, location.y-1);
  1587.      
  1588.      if(_d.equals("E")) return location = region.getLocation(location.x+1, location.y);
  1589.      
  1590.      if(_d.equals("SE")) return location = region.getLocation(location.x+1, location.y+1);
  1591.      if(_d.equals("S")) return location = region.getLocation(location.x, location.y+1);
  1592.      if(_d.equals("SW")) return location = region.getLocation(location.x-1, location.y+1);
  1593.      
  1594.      if(_d.equals("W")) return location = region.getLocation(location.x-1, location.y);
  1595.      
  1596.      return null; // shouldn't happen.
  1597.   }
  1598.  
  1599.   public boolean isTraitExist(String _s)
  1600.   {
  1601.     // searching if anyone in the army has a certain trait
  1602.     boolean res = false;
  1603.     if(secondLieutenant.isTraitExist(_s)) res = true;
  1604.     for(int i=0; i< legion.length; i++)
  1605.     {
  1606.      if(legion[i] !=null && legion[i].legate !=null && legion[i].legate.isTraitExist(_s))
  1607.        return res;
  1608.     }
  1609.     return res;
  1610.   }
  1611.  
  1612.   // 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.
  1613. }
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619. public class BorderBox extends Rectangle
  1620. {
  1621.   public String name; // identifier. Two borderBoxes should never have the same name
  1622.   public String toolTip = null; // tooltip box may appear when mouse hovers this borderbox.
  1623.  
  1624.   public BorderBox(String _n, int _x, int _y, int _width, int _height)
  1625.   {
  1626.     setBounds(_x, _y, _width, _height);
  1627.     name = _n;
  1628.   }
  1629.  
  1630.   public String getName()
  1631.   {
  1632.    return name;
  1633.   }
  1634.  
  1635.   public void setName(String n)
  1636.   {
  1637.    name = n;
  1638.   }
  1639.  
  1640.   public String getToolTip()
  1641.   {
  1642.    return toolTip;
  1643.   }
  1644.  
  1645.   public void setToolTip(String _s)
  1646.   {
  1647.     toolTip = _s;
  1648.   }
  1649. }
  1650.  
  1651.  
  1652. public class Base
  1653. {
  1654.  public Army garrison = null; // garrisoned army. usually between 0-500 just to fend off raids.
  1655.  
  1656. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement