/* This file is part of CivQuest.
*
* CivQuest is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* CivQuest is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with CivQuest; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: $
*/
package civquest.map.realReader;
import civquest.core.Game;
import civquest.map.resource.ResourceNode;
import civquest.map.resource.ResourceNodeManager;
import civquest.map.resource.ResourceReader;
import civquest.map.resource.ResourceSet;
/** Resource reader implementation always returning the reality. <p>
*
* General note concerning runtime exceptions: You fetch for example a
* resource node using a key. If you make some mistake, you might use an
* invalid key. But we don't have to check for this here, since
* classes like ResourceNodeManager do the job - they throw an appropriate
* RuntimeException anyway.
*/
public class RealResourceReader implements ResourceReader {
private Game game;
public RealResourceReader(Game game) {
this.game = game;
}
public boolean isResourceNodeAvailable(Long resourceNodeManagerID,
String key) {
return true;
}
public Long getResourceNode(Long resourceNodeManagerID, String key) {
ResourceNodeManager manager
= game.getResourceNodeManager(resourceNodeManagerID);
return manager.getResourceNode(key).getID();
}
public boolean isResourceEdgeAvailable(Long sourceResourceNodeID,
Long destResourceNodeID) {
return true;
}
public Long getResourceEdge(Long sourceResourceNodeID,
Long destResourceNodeID) {
ResourceNode sourceNode = game.getResourceNode(sourceResourceNodeID);
ResourceNode destNode = game.getResourceNode(destResourceNodeID);
return sourceNode.getOutResourceEdge(destNode).getID();
}
public boolean isResourceEdgeAmountAvailable(Long resourceEdgeID) {
return true;
}
public ResourceSet getResourceEdgeAmount(Long resourceEdgeID) {
return game.getResourceEdge(resourceEdgeID).getAmount();
}
}