Class manufacturingState

java.lang.Object
com.jme3.app.state.BaseAppState
name.moore.kevin.ze.game.states.manufacturingState
All Implemented Interfaces:
com.jme3.app.state.AppState, iZodiacState

public class manufacturingState extends com.jme3.app.state.BaseAppState implements iZodiacState
This JMonkeyEngine application state handles the various buildQueues and industry manufacturing things.

'Builders' build things... each builder has a buildQueue of build tickets.

New manufacturing facilities are added to the planetary buildQueue, one exists per planet. Once completed such facilities are commissioned and become available to use. Equipment such as engines will be built using an industry and added to that industries buildQueue. Once completed items are delivered to the planets warehouse.

Author:
Kevin Moore <dev@kevin.moore.name>
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private Map<com.simsilica.es.EntityId,​buildQueue>
    Map builder ->buildqueue.
    private Map<com.simsilica.es.EntityId,​warehouse>
    Map of planet entityid ->warehouse.
    private com.jme3.asset.AssetManager
     
    private com.google.common.collect.EvictingQueue<build>
    The completed tickets waiting to be processed.
    private com.google.common.collect.EvictingQueue<build>
     
    private com.jme3.input.InputManager
     
    private Map<build,​build>
    These tickets involve multiple parts.
    private static org.slf4j.Logger
     
    private Map<build,​com.simsilica.es.EntityId>
    Incoming ticket requests.
    private com.jme3.scene.Node
     
    private com.jme3.app.state.AppStateManager
     
    private com.jme3.renderer.ViewPort
     
    private iZodiacApp
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private com.simsilica.es.EntityId
    addToIndustryQueue​(build bticket, com.simsilica.es.EntityId peid)
     
    private com.simsilica.es.EntityId
    addToOrbitalQueue​(build bticket, com.simsilica.es.EntityId peid)
    Find shipyards orbiting this planet and choose one.
    private com.simsilica.es.EntityId
    addToPlanetQueue​(build bticket, com.simsilica.es.EntityId peid)
     
    private buildQueue
    addtoQueue​(build bticket, com.simsilica.es.EntityId buildereid, com.simsilica.es.EntityId peid)
    Utility function to add a build ticket to a specific buildQueue.
    private boolean
    assignTicket​(build bticket, com.simsilica.es.EntityId peid)
    Assign a build request into the correct buildqueue.
    protected void
    cleanup​(com.jme3.app.Application app)
     
    private void
    construct​(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)
    Request manufacture of new equipment or facilities with the specified specification on the specified planet.
    private void
    construct_request​(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)
    Request manufacture of new equipment or facilities with the specified specification on the specified planet.
    void
    gameEvent​(gameEvent event)
    Respond to gameEvents broadcast on the eventbus.
    getWarehouse​(com.simsilica.es.EntityId planeteid)
    Find the warehouse associated with a planet, create it if not present.
    void
    initialize​(com.jme3.app.Application a)
    Called once when attached, copies the JME application for local use, loads XML specifications and a default game.
    private void
    install_request​(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId installinto)
    Request an install of equipment into an existing entity.
    private boolean
    isBuilder​(com.simsilica.es.EntityId s)
     
    protected void
     
    protected void
     
    private com.simsilica.es.EntityId
    requestWhere​(com.simsilica.es.EntityId wherewhat)
    Where is this request taking place? Needed to identify the correct buildqueue.
    void
    setwarehouse​(com.simsilica.es.EntityId planeteid, List<com.simsilica.es.EntityId> items)
    TEMP to add things directly to a warehouse for testing.
    private void
    toBlocked​(build req, com.simsilica.es.EntityId wherewhat)
    Process an initial request ticket into the fully structured series of tickets/prerequisites required to fulfill that request.
    private void
    toCompleted​(build ticket, com.simsilica.es.EntityId planet)
    Ticket final destination, the ticket HAS just completed.
    private void
    toInprogress​(build ticket, com.simsilica.es.EntityId planet)
    Can this ticket be moved from BLOCKED -> INPROGRESS?
    void
    Output a detailed report to LOGGER.trace appropriate to this state - typically of the contents of the entity repository.
    void
    update​(float tpf)
    Called automatically and repeatedly while the state is enabled and attached.

    Methods inherited from class com.jme3.app.state.BaseAppState

    cleanup, getApplication, getId, getState, getState, getState, getState, getStateManager, initialize, isEnabled, isInitialized, postRender, render, setEnabled, setId, stateAttached, stateDetached

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface name.moore.kevin.ze.game.states.iZodiacState

    trace, windowEvent
  • Field Details

    • LOGGER

      private static final org.slf4j.Logger LOGGER
    • zapp

      private iZodiacApp zapp
    • rootNode

      private com.jme3.scene.Node rootNode
    • assetManager

      private com.jme3.asset.AssetManager assetManager
    • stateManager

      private com.jme3.app.state.AppStateManager stateManager
    • inputManager

      private com.jme3.input.InputManager inputManager
    • viewPort

      private com.jme3.renderer.ViewPort viewPort
    • requestedTickets

      private Map<build,​com.simsilica.es.EntityId> requestedTickets
      Incoming ticket requests.

      Since the message will be on the async event bus we should make access to this list synchronized between different threads.

      Maps build ticket -> planet entity
    • isComposite

      private Map<build,​build> isComposite
      These tickets involve multiple parts. new ticket -> parent delivery ticket
    • allBuildqueues

      private Map<com.simsilica.es.EntityId,​buildQueue> allBuildqueues
      Map builder ->buildqueue. Each unique builder entity (planet/shipyard/industry) has a queue to hold tickets. Populated lazily as we manufacture items and locate builders.
    • allWarehouses

      private Map<com.simsilica.es.EntityId,​warehouse> allWarehouses
      Map of planet entityid ->warehouse. Each planet has it's own warehouse where some constructed items are stored once completed.
    • completedSent

      private com.google.common.collect.EvictingQueue<build> completedSent
      The completed tickets waiting to be processed. Done since the COMPLETED message is sent async, and this avoids sending the message twice. The queue gives us some breathing space between different threads, but cleans up itself.
    • constructSent

      private com.google.common.collect.EvictingQueue<build> constructSent
  • Constructor Details

    • manufacturingState

      public manufacturingState(String id)
      Parameters:
      id -
  • Method Details

    • initialize

      public void initialize(com.jme3.app.Application a)
      Called once when attached, copies the JME application for local use, loads XML specifications and a default game.
      Specified by:
      initialize in class com.jme3.app.state.BaseAppState
      Parameters:
      a - A zodiac object.
      See Also:
      zodiac
    • cleanup

      protected void cleanup(com.jme3.app.Application app)
      Specified by:
      cleanup in class com.jme3.app.state.BaseAppState
    • onEnable

      protected void onEnable()
      Specified by:
      onEnable in class com.jme3.app.state.BaseAppState
    • onDisable

      protected void onDisable()
      Specified by:
      onDisable in class com.jme3.app.state.BaseAppState
    • update

      public void update(float tpf)
      Called automatically and repeatedly while the state is enabled and attached. Process any tickets in the buildqueues.
      Specified by:
      update in interface com.jme3.app.state.AppState
      Overrides:
      update in class com.jme3.app.state.BaseAppState
      Parameters:
      tpf -
    • gameEvent

      public void gameEvent(gameEvent event)
      Respond to gameEvents broadcast on the eventbus.

      Since the bus is async the code will run on a different thread from the main application. best to make the event handling short and sharp!

      Handle requested manufacturing events, which may have been generated by this manufacturingState.
      Specified by:
      gameEvent in interface iZodiacState
      Parameters:
      event -
    • construct_request

      @AsyncThread private void construct_request(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)
      Request manufacture of new equipment or facilities with the specified specification on the specified planet.

      Construct an initial ticket and add the ticket to the generic REQUEST buildQueue, it will then be processed by update(float).

      Parameters:
      speceid - the spec of the thing to be built
      peid - the planet where we are building
    • install_request

      @AsyncThread private void install_request(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId installinto)
      Request an install of equipment into an existing entity.
      Parameters:
      speceid - the spec to try installing, we will try to getEntityComponent this from a warehouse or by construction.
      targetid - the entity to receive the installation - it's location determines the planet
    • toBlocked

      private void toBlocked(build req, com.simsilica.es.EntityId wherewhat)
      Process an initial request ticket into the fully structured series of tickets/prerequisites required to fulfill that request.

      creates other tickets and organises prerequisites.

    • requestWhere

      private com.simsilica.es.EntityId requestWhere(com.simsilica.es.EntityId wherewhat)
      Where is this request taking place? Needed to identify the correct buildqueue.
    • toInprogress

      private void toInprogress(build ticket, com.simsilica.es.EntityId planet)
      Can this ticket be moved from BLOCKED -> INPROGRESS?

      This can be done by all the prerequisites being completed, or being able to reserve from the warehouse.

      Parameters:
      ticket -
    • toCompleted

      private void toCompleted(build ticket, com.simsilica.es.EntityId planet)
      Ticket final destination, the ticket HAS just completed.
      Parameters:
      ticket -
      planet -
    • construct

      @AsyncThread private void construct(com.simsilica.es.EntityId speceid, com.simsilica.es.EntityId peid)
      Request manufacture of new equipment or facilities with the specified specification on the specified planet.

      Construct a buildticket to track construction and add the ticket to the generic REQUEST buildQueue, it will then be processed by update(float).

      Parameters:
      speceid - the spec of the thing to be built
      peid - the planet where we are building
    • assignTicket

      private boolean assignTicket(build bticket, com.simsilica.es.EntityId peid)
      Assign a build request into the correct buildqueue. If the assignment fails, return false so the ticket can be removed.

      REQUEST ->BLOCKED,

      Parameters:
      ticket -
      peid - planet where this activity is happening
    • addToPlanetQueue

      private com.simsilica.es.EntityId addToPlanetQueue(build bticket, com.simsilica.es.EntityId peid)
    • addToOrbitalQueue

      private com.simsilica.es.EntityId addToOrbitalQueue(build bticket, com.simsilica.es.EntityId peid)
      Find shipyards orbiting this planet and choose one.
      Parameters:
      bticket -
      peid -
      Returns:
    • isBuilder

      private boolean isBuilder(com.simsilica.es.EntityId s)
    • addToIndustryQueue

      private com.simsilica.es.EntityId addToIndustryQueue(build bticket, com.simsilica.es.EntityId peid)
    • addtoQueue

      private buildQueue addtoQueue(build bticket, com.simsilica.es.EntityId buildereid, com.simsilica.es.EntityId peid)
      Utility function to add a build ticket to a specific buildQueue.

      If the queue doesn't yet exist it will be created and associated with the builder.

      Parameters:
      bticket -
      buildereid -
      peid - planet this builder is located on
      Returns:
      See Also:
      allBuildqueues
    • setwarehouse

      public void setwarehouse(com.simsilica.es.EntityId planeteid, List<com.simsilica.es.EntityId> items)
      TEMP to add things directly to a warehouse for testing. Dont use in live code.
      Parameters:
      planeteid -
      items -
    • getWarehouse

      public warehouse getWarehouse(com.simsilica.es.EntityId planeteid)
      Find the warehouse associated with a planet, create it if not present.
      Parameters:
      planeteid -
      Returns:
    • trace

      public void trace()
      Description copied from interface: iZodiacState
      Output a detailed report to LOGGER.trace appropriate to this state - typically of the contents of the entity repository.
      Specified by:
      trace in interface iZodiacState