SEPR-EEP / taxe-game-3

0 stars 0 forks source link

Removing a connection with a train travelling along it #11

Closed rc1035 closed 9 years ago

rc1035 commented 9 years ago

The following condition is currently checked for as to whether a connection being removed has a train travelling along it:

train.getHistory().get(train.getHistory().size()-1).getFirst().equals(origin.getName()) ||
            train.getHistory().get(train.getHistory().size()-1).getFirst().equals(destination.getName()) &&
            train.isMoving()

This condition can be true even if a train is not travelling along the connection being removed. It is simply testing to see if the last station the train passed is either the origin or the destination station of the connection. If a station has a node with an order of at least two (i.e. there are multiple connections to the station), this condition could be true if any train is travelling along any of these connections (after having passed the station).

Is this right, or have I misunderstood something?


As for a possible solution (if this is a problem), we need to find a way of testing whether:

(1) A train has passed one station (e.g. 'origin') of the connection. (2) Also, the trains route specifies the other station (e.g. 'destination') of the connection as the next station the train is moving towards.

Based upon those tests we can be certain that the train is travelling along the connection that a player is attempting to remove.

The Train class currently has no attribute containing the station which the train is currently heading towards. Therefore, we may need to make some modification to TrainMoveController to update each train when it passes a station. Perhaps the method perStationAction could instead be passed two arguments stationReached and nextStationOfRoute. stationReached will be added to the trains history (as is currently the case) and nextStationOfRoute will update a new attribute belonging to the Train.

rc1035 commented 9 years ago

Attempted a fix in 2f5ad5be84d447dfc023e2e70ad9aecae55e4d95 (on a new branch for now). Will test and see if it works as intended.

rc1035 commented 9 years ago

Working in b73442eb2e2c1c47cc7d5a226cb3c9e698ec4763

There are still a few bugs such as:

kokoff commented 9 years ago

The game crashes when adding a connection involving a junction because StationActor and CollisionStationActor do not use inheritance. I will merge your branch into the modifying connections branch and attempt to fix the inheritance issue.

I don't understand what you mean by "Removing a connection that is part of a trains upcoming route results in the train immediately reaching its final destination."

Another issue we need to consider is what happens to incomplete-able goals. When a connection is removed a player could be left with three goals which he is not able to complete, because there is no route between the goal start and end stations, and no connection modifications. In this case the player can't earn any new modifications because he cannot complete a goal and also he cannot complete a goal due to having no modifications available. One solution is to regenerate all incomplete-able goals and replace them with new ones. However if a player is close to completing a goal and has modifications available, he might want to add a connection and complete his goal. So the better solution might be to allow a player to remove goals himself. This way we don't have to worry for incomplete-able goals, because the player will be responsible for removing them whenever he wants.

kokoff commented 9 years ago

Fixed game crash issue

rc1035 commented 9 years ago

This is an example scenario of the issue:

1) Place a train at Madrid 2) Set the route to go Madrid -> Paris -> Lille -> Amsterdam 3) End Turn 4) Now, before the train reaches Paris, remove the connection between Paris -> Lille 5) Once the train reaches Paris it immediately arrives at Amsterdam

By removing a connection that the train was due to travel along, it ends up immediately arriving at the final destination of its route. If I set an extended route from Madrid, with the final destination being Kiev - then it would arrive immediately at Kiev upon reaching Paris.

As for incomplete-able goals, I agree that being able to remove goals would be the better (and easier to implement) solution. If we have the time we could find some way of informing the player that their goal is currently incomplete-able, based upon current connections.

kokoff commented 9 years ago

Fixed teleporting trains with 1cf3f0d2fc1004e5e78b1f79cb5e23d980b264be