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

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");
}
}