Skip to content

Commit

Permalink
removed WorldListListener (no ListMoves anymore anyway), moved code f…
Browse files Browse the repository at this point in the history
…rom move generators to model
  • Loading branch information
Trilarion committed Aug 23, 2018
1 parent e37b2f4 commit 0682914
Show file tree
Hide file tree
Showing 135 changed files with 678 additions and 955 deletions.
4 changes: 4 additions & 0 deletions docs/specification.rst
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ The more wagons a train is pulling, the slower it moves. The greater the amount
The gradient of the track also affects speed. When trains arrive at a station it stops for a few moments to load
and unload cargo. Trains stop instantly (this is a simplification so we don't need to look ahead) but speed up slowly.

Path finding is automatic. That means that trains take the slowest perceived route and priority trains having priority.
(This may change at some point with the player being able to choose between several possible routes between two stations.
It would be implemented using way points, maybe even changing routes depending on the traffic.)

Stations
++++++++

Expand Down
75 changes: 73 additions & 2 deletions docs/specification_rt1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Sid Meier's Railroad Tycoon (1990)
This is a summary of the game model of the original Railroad Tycoon (RRT).

Start condition
+++++++++++++++

- $1 million (half in equity, half as loan)

Expand All @@ -16,6 +17,7 @@ Start condition
- Buy or sell shares

Stations
++++++++

Max. 32 stations per player. First stations gets an engine shop for free. Stations can be up- or downgraded.
During an accounting period built or re-built stations pay double for freight.
Expand All @@ -25,36 +27,98 @@ During an accounting period built or re-built stations pay double for freight.
- Station (4x4 squares influence area)
- Terminal (5x5 squares influence area)

Station buildings
Station improvements
++++++++++++++++++++

- Engine shop
- Store
- Hotel
- Switching yard
- maintenance shop
- cold storage
- livestock pens
- goods storage
- post office
- restaurant

Trains
++++++

Max. 32 trains per player.

- Change "consist" (number and type of cars/wagons
- Types include: mail, passenger, freight

Engines
.......

- 0-4-0 Grasshopper
- 4-2-0 Norris
- 4-4-0 American
- 2-6-0 Mogul
- 4-6-0 Ten-Wheeler
- 2-8-0 Consolidation
- 4-6-2 Pacific
- 2-8-2 Mikado
- 2-6-6-4 Mallet (Challenger class)
- F3-A Diesel-Electric
- EMD GP Diesel-Electric
- 2-2-0 Planet
- 2-2-2 Patentee
- 4-2-0 Iron Duke
- 0-6-0 DX Goods
- 4-2-2 Stirling
- 0-8-0 Webb Compund
- 4-2-2 Johnson Midland Spinner
- 4-4-0 Claud Hamilton
- 4-6-2 A1 Class
- 4-6-2 A4 Class
- 6/6 GE Class Crocodile
- 1-Do-1 Class E18
- 4-8-4 242 A1
- V200 B-B
- Bo-Bo-Bo RE Class 6/6
- TGV

Cars
....

- mail
- passenger
- beer
- livestock
- goods
- hops
- textiles
- steel
- chemicals
- cotton
- coal



Supply and demand
+++++++++++++++++

Stock market
++++++++++++

Time
++++

- 100 years running time (starting year depends on the scenario)
- Accounting period two years long

Difficulty levels
+++++++++++++++++

The chosen difficulty level remains in effect for the whole duration of a game.

Levels are "Investor", "Financier", "Mogul", "Tycoon". The level of difficulty affects revenue earned by each delivery
as well as the tycoon rating at the end.

Reality levels
++++++++++++++

- "No Collision Operation/Dispatcher Operation" In the dispatcher operation, the movement of trains is controlled by block
signals and collisions are possible.
Expand All @@ -63,11 +127,13 @@ Reality levels
- "Basic economy/Complex economy"

Economy
+++++++

- Simple: Stations with two or more cities will buy everything
- Complex: Specialized rules

Other features
++++++++++++++

- If the share price of a competing railroad falls below $5 and stays there for too long, it can be dissolved and be
removed from the game
Expand All @@ -79,10 +145,15 @@ Other features


Supplied scenarios
++++++++++++++++++

- Western United States
- Northeast United States
- Great Britain
- Continental Europe

https://en.wikipedia.org/wiki/Railroad_Tycoon
Links
+++++

- https://en.wikipedia.org/wiki/Railroad_Tycoon

2 changes: 1 addition & 1 deletion src/main/java/freerails/client/ActionRoot.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import freerails.client.model.StationBuildModel;
import freerails.client.renderer.RendererRoot;
import freerails.client.view.DialogueBoxController;
import freerails.move.StationBuilder;
import freerails.controller.StationBuilder;
import freerails.controller.TrackMoveProducer;
import freerails.model.world.UnmodifiableWorld;

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/freerails/client/FreerailsClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import freerails.move.TryMoveStatus;
import freerails.move.generator.MoveGenerator;
import freerails.network.*;
import freerails.server.GameServer;
import freerails.network.command.*;
import freerails.move.receiver.MoveChainFork;
import freerails.move.receiver.UntriedMoveReceiver;
Expand Down Expand Up @@ -92,7 +91,7 @@ public final LogOnResponse connect(String address, int port, String username, St
/**
* Connects this client to a local server.
*/
public final LogOnResponse connect(GameServer server, String username, String password) {
public final LogOnResponse connect(String username, String password) {
try {
Serializable request = new LogOnCredentials(username, password);
connectionToServer = Connection.make(new InetSocketAddress(InetAddress.getLoopbackAddress(), 55000)); // TODO get selected port
Expand Down
8 changes: 0 additions & 8 deletions src/main/java/freerails/client/ModelRootImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import freerails.util.Vec2D;
import freerails.util.Utils;
import freerails.model.world.UnmodifiableWorld;
import freerails.model.world.WorldListListener;
import freerails.model.world.WorldMapListener;
import freerails.model.player.Player;
import freerails.util.ui.SoundManager;
Expand Down Expand Up @@ -82,13 +81,6 @@ public void addCompleteMoveReceiver(MoveReceiver moveReceiver) {
moveFork.addCompleteMoveReceiver(moveReceiver);
}

/**
* @param listener
*/
public void addListListener(WorldListListener listener) {
moveFork.addListListener(listener);
}

/**
* @param listener
*/
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/freerails/client/UserInputOnMapController.java
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public void keyPressed(KeyEvent e) {
}

private void cursorOneTileMove(Vec2D oldPosition, TileTransition vector) {
boolean b = (modelRoot.getProperty(ModelRootProperty.CURSOR_MODE) == ModelRootValue.BUILD_TRACK_CURSOR_MODE);
boolean b = modelRoot.getProperty(ModelRootProperty.CURSOR_MODE) == ModelRootValue.BUILD_TRACK_CURSOR_MODE;

if (null != trackMoveProducer && b) {
trackMoveProducer.setBuildTrackStrategy(getBts());
Expand Down Expand Up @@ -438,8 +438,8 @@ public void mouseDragged(MouseEvent e) {
* station.
*/
// TODO pull these next bits out into method
boolean trackBuildingOn = (trackBuilderMode == BuildMode.BUILD_TRACK) || (trackBuilderMode == BuildMode.REMOVE_TRACK) || (trackBuilderMode == BuildMode.UPGRADE_TRACK);
trackBuildingOn = trackBuildingOn && (modelRoot.getProperty(ModelRootProperty.CURSOR_MODE) == ModelRootValue.BUILD_TRACK_CURSOR_MODE);
boolean trackBuildingOn = trackBuilderMode == BuildMode.BUILD_TRACK || trackBuilderMode == BuildMode.REMOVE_TRACK || trackBuilderMode == BuildMode.UPGRADE_TRACK;
trackBuildingOn = trackBuildingOn && modelRoot.getProperty(ModelRootProperty.CURSOR_MODE) == ModelRootValue.BUILD_TRACK_CURSOR_MODE;

if (SwingUtilities.isLeftMouseButton(e) && pressedInside && trackBuildingOn && !ignoreDragging) {

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/freerails/client/UserMessageGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,22 +81,23 @@ public void process(Move move) {
/**
* Generates a message giving details of any cargo delivered and plays a
* cash register sound to indicate that revenue is coming in.
* @param moves
* @param mov
*/
private void trainArrives(Move mov) {
/*
CompositeMove moves = (CompositeMove) mov;
// TODO does this work anymore, was a WorldDiffMove before
List<CargoDeliveryTransaction> cargoDelivered = new ArrayList<>();
for (int i = 0; i < moves.size(); i++) {
Move move = moves.getMoves().get(i);
if (move instanceof AddTransactionMove) {
AddTransactionMove atm = (AddTransactionMove) move;
if (!atm.getPlayer().equals(modelRoot.getPlayer())) {
AddTransactionMove addTransactionMove = (AddTransactionMove) move;
if (!addTransactionMove.getPlayer().equals(modelRoot.getPlayer())) {
// We don't want to know about other players' income!
return;
}
Transaction transaction = atm.getTransaction();
Transaction transaction = addTransactionMove.getTransaction();
if (transaction instanceof CargoDeliveryTransaction) {
CargoDeliveryTransaction receipt = (CargoDeliveryTransaction) transaction;
cargoDelivered.add(receipt);
Expand Down Expand Up @@ -140,6 +141,7 @@ private void trainArrives(Move mov) {
int loops = (int) revenue.amount / 4000;
soundManager.playSound(ClientConstants.SOUND_CASH, loops);
}
*/
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
/**
* Creates and wires up the GUI components.
*/
public class GUIComponentFactoryImpl implements GUIComponentFactory, WorldMapListener, WorldListListener {
public class GUIComponentFactoryImpl implements GUIComponentFactory, WorldMapListener {

/**
* Whether to show certain 'cheat' menus used for testing.
Expand Down Expand Up @@ -395,41 +395,7 @@ public BuildTrackController getBuildTrackController() {
return buildTrackController;
}

/**
* @param index
* @param player
*/
@Override
public void itemAdded(int index, Player player) {
boolean rightPlayer = player.equals(modelRoot.getPlayer());

// TODO when is this called? when a station is added?
if (rightPlayer) {
countStations();
}
}

/**
* @param index
* @param player
*/
@Override
public void itemRemoved(int index, Player player) {
}

/**
* @param index
* @param player
*/
@Override
public void listUpdated(int index, Player player) {
boolean rightPlayer = player.equals(modelRoot.getPlayer());

// TODO when is this called? when a station is added/removed?
if (rightPlayer) {
countStations();
}
}
// TODO when is this called? when a station is added? need to listen to world changes again (mostly call to countStations())

/**
* Called when a new game is started or a game is loaded.
Expand All @@ -453,7 +419,6 @@ public void setup(RendererRoot rendererRoot, UnmodifiableWorld world) throws IOE
}
this.world = world;
modelRoot.addMapListener(this);
modelRoot.addListListener(this);

// TODO this should be a test, all rendererroots should be compatible
if (!rendererRoot.validate(this.world)) {
Expand Down Expand Up @@ -544,8 +509,8 @@ public void tilesChanged(Rectangle tilesChanged) {
Rectangle mapRect = new Rectangle(0, 0, mapSize.x, mapSize.y);
tilesChanged = tilesChanged.intersection(mapRect);

for (int tileX = tilesChanged.x; tileX < (tilesChanged.x + tilesChanged.width); tileX++) {
for (int tileY = tilesChanged.y; tileY < (tilesChanged.y + tilesChanged.height); tileY++) {
for (int tileX = tilesChanged.x; tileX < tilesChanged.x + tilesChanged.width; tileX++) {
for (int tileY = tilesChanged.y; tileY < tilesChanged.y + tilesChanged.height; tileY++) {
Vec2D p = new Vec2D(tileX, tileY);
mainMap.refreshTile(p);
overviewMap.refreshTile(p);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/freerails/client/launcher/GameLoop.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public void run() {
} else if (ClientConstants.LIMIT_FRAME_RATE) {
long deltatime = System.currentTimeMillis() - frameStartTime;

while (deltatime < (1000 / ClientConstants.TARGET_FPS)) {
while (deltatime < 1000 / ClientConstants.TARGET_FPS) {
try {
long sleeptime = (1000 / ClientConstants.TARGET_FPS) - deltatime;
long sleeptime = 1000 / ClientConstants.TARGET_FPS - deltatime;
Thread.sleep(sleeptime);
} catch (Exception ignored) {
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/freerails/client/launcher/LauncherFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ private void nextButtonActionPerformed(ActionEvent evt) {

prepareToHostNetworkGame(msp.getServerPort());
client = new LauncherClient(cop.getPlayerName(), mode, cop.getDisplayMode());
client.connect(server, cop.getPlayerName(), "password");
client.connect(cop.getPlayerName(), "password");
}
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import freerails.client.renderer.track.TrackPieceRenderer;
import freerails.client.ModelRoot;
import freerails.model.track.TrackType;
import freerails.move.StationBuilder;
import freerails.controller.StationBuilder;
import freerails.move.Status;
import freerails.util.Vec2D;
import freerails.model.world.UnmodifiableWorld;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public TrainOrdersListModel(UnmodifiableWorld world, int trainNumber, Player pla
this.trainNumber = trainNumber;
this.world = world;
this.player = player;
assert (null != getSchedule());
assert null != getSchedule();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
*/
public class RendererRootImpl implements RendererRoot {

private static final Logger logger = Logger.getLogger(RendererRootImpl.class.getName());
private final TileRendererList tileRendererList;
private final TrackPieceRendererList trackPieceViewList;
private final ImageManager imageManager;
Expand Down
Loading

0 comments on commit 0682914

Please sign in to comment.