Campaign mechanics

This commit is contained in:
Anuken
2020-07-06 21:53:34 -04:00
parent a6523630bf
commit 56ffe5aea8
22 changed files with 196 additions and 54 deletions
+1
View File
@@ -45,6 +45,7 @@ public class EventType{
public static class PlayEvent{}
public static class ResetEvent{}
public static class WaveEvent{}
public static class TurnEvent{}
/** Called when the player places a line, mobile or desktop.*/
public static class LineConfirmEvent{}
/** Called when a turret recieves ammo, but only when the tutorial is active! */
+13
View File
@@ -17,6 +17,7 @@ public class SectorInfo{
private static final int valueWindow = 60;
/** refresh period of export in ticks */
private static final float refreshPeriod = 60;
/** Core input statistics. */
public ObjectMap<Item, ExportStat> production = new ObjectMap<>();
/** Export statistics. */
@@ -31,6 +32,8 @@ public class SectorInfo{
public boolean hasCore = true;
/** Sector that was launched from. */
public @Nullable Sector origin;
/** Time spent at this sector. Do not use unless you know what you're doing. */
public transient float internalTimeSpent;
/** Counter refresh state. */
private transient Interval time = new Interval();
@@ -73,11 +76,21 @@ public class SectorInfo{
hasCore = entity != null;
bestCoreType = !hasCore ? Blocks.air : state.rules.defaultTeam.cores().max(e -> e.block.size).block;
storageCapacity = entity != null ? entity.storageCapacity : 0;
//update sector's internal time spent counter1
state.rules.sector.setTimeSpent(internalTimeSpent);
}
/** Update averages of various stats.
* Called every frame. */
public void update(){
internalTimeSpent += Time.delta();
//time spent exceeds turn duration!
if(internalTimeSpent >= turnDuration && internalTimeSpent - Time.delta() < turnDuration){
universe.displayTimeEnd();
}
//create last stored core items
if(lastCoreItems == null){
lastCoreItems = new int[content.items().size];
+40 -16
View File
@@ -5,6 +5,8 @@ import arc.math.*;
import arc.struct.*;
import arc.util.*;
import mindustry.content.*;
import mindustry.core.GameState.*;
import mindustry.game.EventType.*;
import mindustry.type.*;
import mindustry.world.blocks.storage.*;
@@ -14,8 +16,7 @@ import static mindustry.Vars.*;
public class Universe{
private long seconds;
private float secondCounter;
private int event;
private float eventCounter;
private int turn;
private Schematic lastLoadout;
private Seq<ItemStack> lastLaunchResources = new Seq<>();
@@ -30,6 +31,10 @@ public class Universe{
updatePlanet(Planets.sun);
}
public int turn(){
return turn;
}
private void updatePlanet(Planet planet){
planet.position.setZero();
planet.addParentOffset(planet.position);
@@ -41,6 +46,14 @@ public class Universe{
}
}
public void displayTimeEnd(){
if(!headless){
state.set(State.paused);
ui.announce("Next turn incoming.");
}
}
/** Update planet rotations, global time and relevant state. */
public void update(){
secondCounter += Time.delta() / 60f;
@@ -55,13 +68,6 @@ public class Universe{
}
}
//update event counter - happens only in-game
eventCounter += Time.delta();
if(eventCounter >= eventRate){
runEvents();
}
if(state.hasSector()){
//update sector light
float light = state.getSector().getLight();
@@ -110,11 +116,31 @@ public class Universe{
}
/** Runs possible events. Resets event counter. */
public void runEvents(){
event++;
eventCounter = 0;
public void runTurn(){
turn++;
int newSecondsPassed = (int)(turnDuration / 60);
//update relevant sectors
for(Planet planet : content.planets()){
for(Sector sector : planet.sectors){
if(sector.hasSave()){
int spent = (int)(sector.getTimeSpent() / 60);
int actuallyPassed = Math.max(newSecondsPassed - spent, 0);
//increment seconds passed for this sector by the time that just passed with this turn
if(!sector.isBeingPlayed()){
sector.setSecondsPassed(sector.getSecondsPassed() + actuallyPassed);
}
//reset time spent to 0
sector.setTimeSpent(0f);
}
}
}
//TODO events
Events.fire(new TurnEvent());
}
public float secondsMod(float mod, float scale){
@@ -131,14 +157,12 @@ public class Universe{
private void save(){
Core.settings.put("utime", seconds);
Core.settings.put("event", event);
Core.settings.put("eventtime", eventCounter);
Core.settings.put("turn", turn);
}
private void load(){
seconds = Core.settings.getLong("utime");
event = Core.settings.getInt("event");
eventCounter = Core.settings.getFloat("eventtime");
turn = Core.settings.getInt("turn");
}
}