Skip to content

Commit

Permalink
Updated for AI
Browse files Browse the repository at this point in the history
  • Loading branch information
David52920 committed Jan 5, 2021
1 parent eaf756f commit f70a46e
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.benberi.cadesim.BlockadeSimulator;
import com.benberi.cadesim.Constants;

Expand Down Expand Up @@ -37,10 +36,6 @@ public static void main (String[] arg) {
config.setForegroundFPS(60);
config.setTitle("GC: v" + Constants.VERSION);
config.setWindowIcon("gclogo.png");
// if(System.getProperty("os.name").toLowerCase().contains("mac")) {
// ShaderProgram.prependVertexCode = "#version 110\n#define varying out\n#define attribute in\n";
// ShaderProgram.prependFragmentCode = "#version 110\n#define varying in\n#define texture2D texture\n#define gl_FragColor fragColor\nout vec4 fragColor;\n";
// }
new Lwjgl3Application(cadesim, config);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class ServerConfiguration {
private static String mapFilter = ".txt";
private static String disengageBehavior = "simple";
private static int votingMajority = 75; // percent
private static String aiLevel = "easy";
private static JobbersQuality jobbersQuality = JobbersQuality.ELITE;
private static String attackerName = "attacker";
private static String defenderName = "defender";
Expand All @@ -49,7 +50,7 @@ public class ServerConfiguration {
private static boolean checkForUpdatesOnStartup = false;

private static ArrayList<Object> gameSettings = new ArrayList<Object>(Arrays.asList(turnDuration,
roundDuration,respawnDelay, disengageBehavior, getJobbersQualityAsString(), isCustomMap(), mapName, null,
roundDuration,respawnDelay, disengageBehavior, getJobbersQualityAsString(), isCustomMap(), mapName, null, aiLevel,
turnDuration,roundDuration,respawnDelay, disengageBehavior, getJobbersQualityAsString()));
// uninitializable defaults
private static String nextMapName = null; // the next map in the rotation. cannot be initialized by CLI.
Expand Down Expand Up @@ -455,31 +456,39 @@ public static void setMapSetting(int[][] value) {
ServerConfiguration.gameSettings.set(7, value);
}

public static String getAISetting() {
return (String)ServerConfiguration.gameSettings.get(8);
}

public static void setAISetting(String value) {
ServerConfiguration.gameSettings.set(8, value);
}

public static int getDefaultTurnSetting() {
return (int)ServerConfiguration.gameSettings.get(8);
return (int)ServerConfiguration.gameSettings.get(9);
}

public static void setDefaultTurnSetting(int value) {
ServerConfiguration.gameSettings.set(8,value);
ServerConfiguration.gameSettings.set(9,value);
}

public static int getDefaultRoundSetting() {
return (int)ServerConfiguration.gameSettings.get(9);
return (int)ServerConfiguration.gameSettings.get(10);
}

public static void setDefaultRoundSetting(int value) {
ServerConfiguration.gameSettings.set(9,value);
ServerConfiguration.gameSettings.set(10,value);
}

public static int getDefaultRespawnSetting() {
return (int)ServerConfiguration.gameSettings.get(10);
return (int)ServerConfiguration.gameSettings.get(11);
}

public static String getDefaultDisengageSetting() {
return (String)ServerConfiguration.gameSettings.get(11);
return (String)ServerConfiguration.gameSettings.get(12);
}

public static String getDefaultJobberSetting() {
return (String)ServerConfiguration.gameSettings.get(12);
return (String)ServerConfiguration.gameSettings.get(13);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public NPC_Type2(ServerContext ctx, Channel c) {

@Override
public void performLogic() {
this.getMoves().setMove(0, MoveType.FORWARD);
this.getMoves().setMove(0, MoveType.RIGHT);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ private boolean getPersistTemporarySettings()
{
return persistTemporarySettings;
}

public static void setAILevel(String value){
ServerConfiguration.setAISetting(value);
}
/**
* set with string so can load from cli
*/
Expand Down Expand Up @@ -1565,6 +1569,7 @@ else if (currentVote.getDescription().equals("gamesettings"))
setRespawnDelay(ServerConfiguration.getRespawnSetting());
setDisengageBehavior(ServerConfiguration.getDisengageSetting());
setJobbersQuality(ServerConfiguration.getJobberSetting());
setAILevel(ServerConfiguration.getAISetting());
if(!ServerConfiguration.isCustomMap() || ServerConfiguration.getMapSetting() == null) { //check if customMap is false
String match=null;
for (String s : ServerConfiguration.getAvailableMaps()) {
Expand Down Expand Up @@ -1648,6 +1653,49 @@ private void printCommandHelp(Player pl)

}

public void removeAI() {
for(Player p : listRegisteredPlayers()) {
for (Player player : listRegisteredPlayers()) {
if((!player.isBot()) && p.isBot()) {
player.getPackets().sendRemovePlayer(p);
removeBot(p);
}
}
}
}

public void spawnAI() {
removeAI();
int playerListSize = listRegisteredPlayers().size();
switch(ServerConfiguration.getAISetting()) {
case "off":
return;
case "easy":
createBot(NPC_Type.TYPE1, "Type1", 11, Team.ATTACKER, null, VesselFace.SOUTH, 0.0f);
createBot(NPC_Type.TYPE2, "Type2", 11, Team.ATTACKER, null, VesselFace.SOUTH, 0.0f);
break;
case "medium":
for (int i =1; i <=(playerListSize * 1.5) ; i++) {
System.out.println("Medium: " + i);
createBot(NPC_Type.TYPE1, "Type1", 11, Team.ATTACKER, null, VesselFace.SOUTH, 0.0f);
}
break;
case "hard":
for (int i =1; i <=(playerListSize * 2) ; i++) {
System.out.println("Hard: " + i);
createBot(NPC_Type.TYPE1, "Type1", 11, Team.ATTACKER, null, VesselFace.SOUTH, 0.0f);
}
break;
default:
return;
}
for(Player p : listRegisteredPlayers()) {
if(!p.isBot()) {
p.getPackets().sendPlayers();
}
}
}

private void printTeams(Player pl, boolean verbose) {
int numAttackers = 0;
int numDefenders = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ else if (
// complete the game refresh
playerManager.renewGame();
context.getTimeMachine().renewRound(); // bugfix - order matters

playerManager.spawnAI();
playerManager.serverBroadcastMessage("Started new round: #" + (gamesCompleted + 1));
}

Expand Down

0 comments on commit f70a46e

Please sign in to comment.