Skip to content

Commit

Permalink
Fixed AI to spawn on correct side based on team of other players
Browse files Browse the repository at this point in the history
  • Loading branch information
David52920 committed Jan 6, 2021
1 parent 49b92fc commit 91bf0b9
Show file tree
Hide file tree
Showing 12 changed files with 366 additions and 161 deletions.
88 changes: 48 additions & 40 deletions client-core/src/com/benberi/cadesim/GameContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -486,8 +486,13 @@ public void dispose() {
if (getIsInLobby()) {
System.out.println("Returned to lobby");
}else {
getLobbyScreen().setPopupMessage("You have disconnected from the server.");
getLobbyScreen().showPopup();
Gdx.app.postRunnable(new Runnable() {
@Override
public void run() {
getLobbyScreen().setPopupMessage("You have disconnected from the server.");
getLobbyScreen().showPopup();
}
});
}

// #83 reset any lag test mode if we disconnect.
Expand Down Expand Up @@ -618,6 +623,9 @@ public void handleServersideDisconnect() {
public void run() {
ScreenManager.getInstance().showScreen(ScreenEnum.LOBBY, context);
graphics.setResizable(true);
getLobbyScreen().setPopupMessage("Server Disconnected.");
getLobbyScreen().showPopup();
graphics.setTitle("GC: v" + Constants.VERSION);
}
});
}
Expand Down Expand Up @@ -671,96 +679,96 @@ public ArrayList<Object> getGameSettings() {
return gameSettings;
}

public int getTurnSetting() {
public int getDefaultTurnSetting() {
return ((int)gameSettings.get(0)/10);
}

public int getDefaultRoundSetting() {
return ((int)gameSettings.get(1)/10);
}

public int getDefaultRespawnSetting() {
return (int)gameSettings.get(2);
}

public String getDefaultDisengageSetting() {
return (String)gameSettings.get(3);
}

public String getDefaultJobberSetting() {
return (String)gameSettings.get(4);
}

public int getTurnSetting() {
return ((int)gameSettings.get(5)/10);
}

public void setTurnSetting(int value) {
gameSettings.set(0, value);
gameSettings.set(5, value);
}

public int getRoundSetting() {
return ((int)gameSettings.get(1)/10);
return ((int)gameSettings.get(6)/10);
}

public void setRoundSetting(int value) {
gameSettings.set(1, value);
gameSettings.set(6, value);
}

public int getRespawnSetting() {
return (int)gameSettings.get(2);
return (int)gameSettings.get(7);
}

public void setRespawnSetting(int value) {
gameSettings.set(2, value);
gameSettings.set(7, value);
}

public String getDisengageSetting() {
return (String)gameSettings.get(3);
return (String)gameSettings.get(8);
}

public void setDisengageSetting(String value) {
gameSettings.set(3, value);
gameSettings.set(8, value);
}

public String getJobberSetting() {
return (String)gameSettings.get(4);
return (String)gameSettings.get(9);
}

public void setJobberSetting(String value) {
gameSettings.set(4, value);
gameSettings.set(9, value);
}

public boolean getCustomMapSetting() {
return (boolean)gameSettings.get(5);
return (boolean)gameSettings.get(10);
}

public void setCustomMapSetting(boolean b) {
gameSettings.set(5, b);
gameSettings.set(10, b);
}

public String getMapNameSetting() {
return (String)gameSettings.get(6);
return (String)gameSettings.get(11);
}

public void setMapNameSetting(String value) {
gameSettings.set(6, value);
gameSettings.set(11, value);
}

public int[][] getMapSetting() {
return (int[][])gameSettings.get(7);
return (int[][])gameSettings.get(12);
}

public void setMapSetting(int[][] value) {
gameSettings.set(7, value);
gameSettings.set(12, value);
}

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

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

public int getDefaultTurnSetting() {
return ((int)gameSettings.get(9)/10);
}

public int getDefaultRoundSetting() {
return ((int)gameSettings.get(10)/10);
}

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

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

public String getDefaultJobberSetting() {
return (String)gameSettings.get(13);
gameSettings.set(13, value);
}

public ExecutorService getService() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public void execute(Packet p) {
if(getContext().getBattleMenu() != null) {
getContext().getBattleMenu().clearDisengageBehavior();
getContext().getBattleMenu().clearQuality();
getContext().getBattleMenu().clearAI();
int length = p.readInt();
ObjectInputStream ois;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,7 @@ public void render(float delta) {
if(battleMenu.teamTable.isVisible()) {
battleMenu.fillTeamList();
}
stage.getBatch().setColor(Color.WHITE);
stage.getViewport().setCamera(othercamera);
stage.getBatch().setProjectionMatrix(othercamera.combined);
stage.getViewport().apply();
Expand Down Expand Up @@ -883,8 +884,7 @@ public BlockadeMap getMap() {

public void initializePlayerCamera(Vessel vessel) {
cameraFollowsVessel = true; // force reset
othercamera.position.add(getIsometricX(vessel.getX(), vessel.getY(), vessel) - othercamera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - othercamera.position.y, 0);
othercamera.update();
othercamera.translate(getIsometricX(vessel.getX(), vessel.getY(), vessel) - othercamera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - othercamera.position.y, 0);
}

/**
Expand Down Expand Up @@ -954,7 +954,7 @@ public boolean touchDown(int x, int y, int pointer, int button) {
if (battleMenu.touchDown(x, y, pointer, button)) {
return true;
}
if (othercamera != null && y < othercamera.viewportHeight && !battleMenu.teamTable.isVisible()) {
if (othercamera != null && y < othercamera.viewportHeight - 200 && !battleMenu.teamTable.isVisible()) {
// handle camera not following vessel
cameraFollowsVessel = false;

Expand All @@ -975,16 +975,15 @@ public boolean touchUp(int x, int y, int pointer, int button) {
if (battleMenu.touchUp(x, y, pointer,button)) {
return true;
}
if (othercamera != null && y < othercamera.viewportHeight && !battleMenu.teamTable.isVisible()) {
if (othercamera != null && y < othercamera.viewportHeight - 200 && !battleMenu.teamTable.isVisible()) {
// handle camera following/not following vessel
if (button == Input.Buttons.RIGHT) {
cameraFollowsVessel = false;
} else {
this.cameraFollowsVessel = true;
try {
Vessel vessel = context.getEntities().getVesselByName(context.myVessel);
othercamera.position.add(getIsometricX(vessel.getX(), vessel.getY(), vessel) - othercamera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - othercamera.position.y, 0);
othercamera.update();
othercamera.translate(getIsometricX(vessel.getX(), vessel.getY(), vessel) - othercamera.position.x, getIsometricY(vessel.getX(), vessel.getY(), vessel) - othercamera.position.y, 0);
}catch(NullPointerException e){
//TO-DO -fix issue with null pointer
}
Expand All @@ -1005,10 +1004,9 @@ public boolean touchDragged(int sx, int sy, int pointer) {
if (othercamera != null && sy > othercamera.viewportHeight) {
return false;
}
if (this.canDragMap && sy < Gdx.graphics.getHeight() - 200) {
if (this.canDragMap && sy < othercamera.viewportHeight - 200) {
float x = Gdx.input.getDeltaX(); float y = Gdx.input.getDeltaY();
othercamera.position.add(-x*1.3f, y*1.3f, 0);
othercamera.update();
othercamera.translate(-x,y*1f);
}
if (battleMenu.touchDragged(sx, sy, pointer)) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Properties;

import com.badlogic.gdx.graphics.Texture;
Expand Down Expand Up @@ -287,8 +288,8 @@ public void createTeams() {

teamButtonTable.add(attackerTeamButton).padBottom(2.0f).padLeft(8f).padRight(10.0f);
teamButtonTable.add(defenderTeamButton).padBottom(2.0f);
listTables.add(attackerScroller).width(150).height(200).padRight(10.0f);
listTables.add(defenderScroller).width(150).height(200);
listTables.add(attackerScroller).width(250).height(200).padRight(10.0f);
listTables.add(defenderScroller).width(250).height(200);
teamTable.add(teamButtonTable).row();
teamTable.add(listTables);
teamTable.setPosition(Gdx.graphics.getWidth()/2, Gdx.graphics.getHeight()/2);
Expand Down Expand Up @@ -366,12 +367,13 @@ public void createDialog() {
settingsDialog.setMovable(true);
settingsDialog.setResizable(true);
resizeSettingsDialog();
disableAI();
}
/*
* Fill list with proper teams
*/
public void fillTeamList() {
HashSet<Object> seen=new HashSet<>();
context.getEntities().vessels.removeIf(e->!seen.add(e.getName()));
attackerList.getItems().clear();
defenderList.getItems().clear();
ArrayList<Vessel> attacker = new ArrayList<Vessel>();
Expand Down Expand Up @@ -542,38 +544,38 @@ public void exit(InputEvent event, float x, float y, int pointer, Actor actor) {
stage.setScrollFocus(null);
}
});
// getAIOffButton().addListener(new ClickListener() {
// @Override
// public void clicked(InputEvent event, float x, float y) {
// clearAI();
// getCustomMapButton().setDisabled(false);
// setAIButton("off",true);
// context.setAISetting("off");
// }});
// getAIEasyDifficultyButton().addListener(new ClickListener() {
// @Override
// public void clicked(InputEvent event, float x, float y) {
// clearAI();
// getCustomMapButton().setDisabled(false);
// setAIButton("easy",true);
// context.setAISetting("easy");
// }});
// getAIMediumDifficultyButton().addListener(new ClickListener() {
// @Override
// public void clicked(InputEvent event, float x, float y) {
// clearAI();
// getCustomMapButton().setDisabled(false);
// setAIButton("medium",true);
// context.setAISetting("medium");
// }});
// getAIHardDifficultyButton().addListener(new ClickListener() {
// @Override
// public void clicked(InputEvent event, float x, float y) {
// clearAI();
// getCustomMapButton().setDisabled(false);
// setAIButton("hard",true);
// context.setAISetting("hard");
// }});
getAIOffButton().addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
clearAI();
getCustomMapButton().setDisabled(false);
setAIButton("off",true);
context.setAISetting("off");
}});
getAIEasyDifficultyButton().addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
clearAI();
getCustomMapButton().setDisabled(false);
setAIButton("easy",true);
context.setAISetting("easy");
}});
getAIMediumDifficultyButton().addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
clearAI();
getCustomMapButton().setDisabled(false);
setAIButton("medium",true);
context.setAISetting("medium");
}});
getAIHardDifficultyButton().addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
clearAI();
getCustomMapButton().setDisabled(false);
setAIButton("hard",true);
context.setAISetting("hard");
}});
getDisengageOffButton().addListener(new ClickListener() {
@Override
public void clicked(InputEvent event, float x, float y) {
Expand Down Expand Up @@ -880,6 +882,10 @@ public void selected(Array<FileHandle> file) {
selectCustomMap();
}
}
@Override
public void canceled() {
getCustomMapButton().setDisabled(false);
}
});
}

Expand Down Expand Up @@ -943,6 +949,11 @@ public void showDialog() {
if(button.getText().toString().toLowerCase().equals(context.getJobberSetting())) {
button.setDisabled(true);
}
}
for (TextButton button: aiGroup.getButtons()) {
if(button.getText().toString().toLowerCase().equals(context.getAISetting())) {
button.setDisabled(true);
}
}
settingsDialog.pack();
settingsScroller.layout();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ public ServerPacketManager(ServerContext context) {
* Queues all packets and executes them
*/
public void queuePackets() {
for (Player p : context.getPlayerManager().getPlayers()) {
p.getPackets().queueIncomingPackets();
}
try {
for (Player p : context.getPlayerManager().getPlayers()) {
p.getPackets().queueIncomingPackets();
}
}catch(ConcurrentModificationException e) {

}
}

/**
Expand Down
Loading

0 comments on commit 91bf0b9

Please sign in to comment.