Skip to content

Commit

Permalink
#56 Adds news generation data actually into newsCorpData.
Browse files Browse the repository at this point in the history
  • Loading branch information
tuomount committed Jul 30, 2017
1 parent ae6a5e1 commit 1a4c7eb
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openRealmOfStars.starMap.Route;
import org.openRealmOfStars.starMap.StarMap;
import org.openRealmOfStars.starMap.Sun;
import org.openRealmOfStars.starMap.newsCorp.NewsFactory;
import org.openRealmOfStars.starMap.planet.Planet;
import org.openRealmOfStars.utilities.DiceGenerator;

Expand Down Expand Up @@ -442,6 +443,12 @@ public static void handleDiplomacyBetweenAis(final Game game,
|| trade.getFirstOffer().isTypeInOffer(NegotiationType.WAR)) {
// Another party accepts it or it is war
trade.doTrades();
if (trade.getFirstOffer().isTypeInOffer(NegotiationType.WAR)) {
//TODO Add reputation loss for info
PlayerInfo defender = game.getStarMap().getPlayerByIndex(secondIndex);
game.getStarMap().getNewsCorpData().addNews(
NewsFactory.makeWarNews(info, defender, fleet, game.getStarMap()));
}
} else {
SpeechType type = trade.getSpeechTypeByOffer();
Attitude attitude = info.getAiAttitude();
Expand All @@ -452,7 +459,10 @@ public static void handleDiplomacyBetweenAis(final Game game,
if (value < warChance) {
trade.generateEqualTrade(NegotiationType.WAR);
trade.doTrades();
//TODO Add NewCorp about the war
//TODO Add reputation loss for info
PlayerInfo defender = game.getStarMap().getPlayerByIndex(secondIndex);
game.getStarMap().getNewsCorpData().addNews(
NewsFactory.makeWarNews(info, defender, fleet, game.getStarMap()));
}
}
trade.updateMeetingNumbers();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/openRealmOfStars/game/Game.java
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ public void showStarMap(final Object object) {
public void showDiplomacyView(final Object dataObject) {
PlayerInfo info = starMap.getPlayerByIndex(1);
Fleet fleet = null;
Planet planet = null;
int type = DiplomacyView.HUMAN_REGULAR;
if (dataObject != null) {
if (dataObject instanceof Fleet) {
Expand Down Expand Up @@ -496,6 +497,7 @@ public void showDiplomacyView(final Object dataObject) {
PlanetView view = (PlanetView) dataObject;
if (view.getPlanet().getPlanetPlayerInfo() != null) {
info = view.getPlanet().getPlanetPlayerInfo();
planet = view.getPlanet();
}
}
if (dataObject instanceof PlayerInfo) {
Expand All @@ -504,7 +506,7 @@ public void showDiplomacyView(final Object dataObject) {
}
}
diplomacyView = new DiplomacyView(starMap.getPlayerByIndex(0), info,
starMap, type, fleet, this);
starMap, type, fleet, planet, this);
this.updateDisplay(diplomacyView);
}

Expand Down
42 changes: 33 additions & 9 deletions src/main/java/org/openRealmOfStars/game/States/DiplomacyView.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.openRealmOfStars.player.fleet.Fleet;
import org.openRealmOfStars.player.tech.Tech;
import org.openRealmOfStars.starMap.StarMap;
import org.openRealmOfStars.starMap.newsCorp.NewsFactory;
import org.openRealmOfStars.starMap.planet.Planet;
import org.openRealmOfStars.utilities.DiceGenerator;

Expand Down Expand Up @@ -190,6 +191,10 @@ public class DiplomacyView extends BlackPanel {
*/
private SpaceButton endBtn;

/**
* Meeting place for news generator
*/
private Object meetingPlace;
/**
* Diplomacy View constructor
* @param info1 Human player PlayerInfo
Expand All @@ -201,18 +206,26 @@ public class DiplomacyView extends BlackPanel {
* HUMAN_BORDER_CROSS
* AI_BORDER_CROSS
* @param fleet Fleet which has crossed the border. Can be null
* @param planet Planet where meeting happended. Can be null
* @param listener ActionListener
*/
public DiplomacyView(final PlayerInfo info1, final PlayerInfo info2,
final StarMap map, final int startType, final Fleet fleet,
final ActionListener listener) {
final Planet planet, final ActionListener listener) {
this.setLayout(new BorderLayout());
human = info1;
borderCrossedFleet = fleet;
ai = info2;
starMap = map;
humanCredits = 0;
aiCredits = 0;
meetingPlace = null;
if (fleet != null) {
meetingPlace = fleet;
}
if (planet != null) {
meetingPlace = planet;
}
int humanIndex = starMap.getPlayerList().getIndex(human);
int aiIndex = starMap.getPlayerList().getIndex(ai);
if (startType == AI_REGULAR || startType == AI_BORDER_CROSS) {
Expand Down Expand Up @@ -788,7 +801,10 @@ public void handleAction(final ActionEvent arg0) {
trade.doTrades();
updatePanel(SpeechType.MAKE_WAR);
resetChoices();
//TODO Add NewCorp about the war
//TODO Add diplomacy bonus for attacker
starMap.getNewsCorpData().addNews(
NewsFactory.makeWarNews(ai, human, meetingPlace, starMap));

} else {
if (speechSelected.getType() == SpeechType.DECLINE_ANGER) {
updatePanel(SpeechType.INSULT_RESPOND);
Expand All @@ -814,7 +830,8 @@ public void handleAction(final ActionEvent arg0) {
trade.doTrades();
updatePanel(SpeechType.AGREE);
resetChoices();
//TODO add news corp that human made trade alliance with AI
starMap.getNewsCorpData().addNews(
NewsFactory.makeTradeAllianceNews(human, ai, meetingPlace));
} else {
updatePanel(SpeechType.DECLINE);
}
Expand All @@ -826,13 +843,14 @@ public void handleAction(final ActionEvent arg0) {
trade.doTrades();
updatePanel(SpeechType.MOVE_FLEET);
resetChoices();
//TODO add news corp that human made trade alliance with AI
} else {
trade.generateEqualTrade(NegotiationType.WAR);
trade.doTrades();
//TODO Add NewCorp about the war
updatePanel(SpeechType.DECLINE_WAR);
resetChoices();
//TODO Add diplomacy bonus for attacker
starMap.getNewsCorpData().addNews(
NewsFactory.makeWarNews(ai, human, meetingPlace, starMap));
}
}
if (speechSelected != null
Expand All @@ -851,7 +869,8 @@ public void handleAction(final ActionEvent arg0) {
trade.doTrades();
updatePanel(SpeechType.AGREE);
resetChoices();
//TODO add news corp that human made trade alliance with AI
starMap.getNewsCorpData().addNews(
NewsFactory.makeAllianceNews(human, ai, meetingPlace));
} else {
updatePanel(SpeechType.DECLINE);
}
Expand Down Expand Up @@ -880,9 +899,11 @@ public void handleAction(final ActionEvent arg0) {
if (value < warChance) {
trade.generateEqualTrade(NegotiationType.WAR);
trade.doTrades();
//TODO Add NewCorp about the war
updatePanel(SpeechType.DECLINE_WAR);
resetChoices();
//TODO Add diplomacy bonus for attacker
starMap.getNewsCorpData().addNews(
NewsFactory.makeWarNews(ai, human, meetingPlace, starMap));
} else {
updatePanel(SpeechType.DECLINE_ANGER);
resetChoices();
Expand Down Expand Up @@ -911,12 +932,14 @@ public void handleAction(final ActionEvent arg0) {
&& speechSelected.getType() == SpeechType.MAKE_WAR) {
int humanIndex = starMap.getPlayerList().getIndex(human);
int aiIndex = starMap.getPlayerList().getIndex(ai);
//TODO add news corp that human declared war on AI
ai.getDiplomacy().getDiplomacyList(humanIndex).addBonus(
DiplomacyBonusType.IN_WAR, ai.getRace());
human.getDiplomacy().getDiplomacyList(aiIndex).addBonus(
DiplomacyBonusType.IN_WAR, human.getRace());
updatePanel(SpeechType.MAKE_WAR);
//TODO Add diplomacy bonus for attacker
starMap.getNewsCorpData().addNews(
NewsFactory.makeWarNews(human, ai, meetingPlace, starMap));
}
if (speechSelected != null
&& speechSelected.getType() == SpeechType.PEACE_OFFER) {
Expand All @@ -934,7 +957,8 @@ public void handleAction(final ActionEvent arg0) {
trade.doTrades();
updatePanel(SpeechType.AGREE);
resetChoices();
//TODO add news corp that human made peace with AI
starMap.getNewsCorpData().addNews(
NewsFactory.makePeaceNews(human, ai, meetingPlace));
} else {
updatePanel(SpeechType.DECLINE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1239,7 +1239,6 @@ private int doTrade(final NegotiationList offerList, final PlayerInfo info,
int index = starMap.getPlayerList().getIndex(giver);
info.getDiplomacy().getDiplomacyList(index).addBonus(
DiplomacyBonusType.IN_WAR, info.getRace());
//TODO Add news corp new that giver has made a war between info
break;
}
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public void test() {
PlayerInfo human = starMap.getPlayerByIndex(0);
PlayerInfo ai = starMap.getPlayerByIndex(1);
DiplomacyView diplomacyView = new DiplomacyView(human, ai, starMap,
DiplomacyView.HUMAN_REGULAR, null, listener);
DiplomacyView.HUMAN_REGULAR, null, null, listener);
assertEquals(SpeechType.NEUTRAL_GREET, diplomacyView.getGreetLine());
assertNotEquals(null, diplomacyView);
assertNotEquals(null, diplomacyView.getTrade());
diplomacyView.resetChoices();
diplomacyView = new DiplomacyView(human, ai, starMap,
DiplomacyView.AI_REGULAR, null, listener);
DiplomacyView.AI_REGULAR, null, null, listener);
assertEquals(SpeechType.NEUTRAL_GREET, diplomacyView.getGreetLine());
assertNotEquals(null, diplomacyView);
assertNotEquals(null, diplomacyView.getTrade());
Expand Down Expand Up @@ -86,7 +86,7 @@ public void testCreditsSettings() {
PlayerInfo human = starMap.getPlayerByIndex(0);
PlayerInfo ai = starMap.getPlayerByIndex(1);
DiplomacyView diplomacyView = new DiplomacyView(human, ai, starMap,
DiplomacyView.HUMAN_REGULAR, null, listener);
DiplomacyView.HUMAN_REGULAR, null, null, listener);
assertEquals(0, diplomacyView.getAiCredits());
assertEquals(0, diplomacyView.getHumanCredits());
ActionEvent action = Mockito.mock(ActionEvent.class);
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testTradeOffer() {
PlayerInfo human = starMap.getPlayerByIndex(0);
PlayerInfo ai = starMap.getPlayerByIndex(1);
DiplomacyView diplomacyView = new DiplomacyView(human, ai, starMap,
DiplomacyView.HUMAN_REGULAR, null, listener);
DiplomacyView.HUMAN_REGULAR, null, null, listener);
assertEquals(0, diplomacyView.getAiCredits());
assertEquals(0, diplomacyView.getHumanCredits());
ActionEvent action = Mockito.mock(ActionEvent.class);
Expand Down

0 comments on commit 1a4c7eb

Please sign in to comment.