Fractal Softworks Forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Starsector 0.9.1a is out! (05/10/19); Blog post: Personal Contacts (08/13/20)

Pages: 1 ... 92 93 [94] 95 96 ... 281

Author Topic: Project Ironclads TC (28 of April, 2017) Source files for the mod  (Read 1430531 times)

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1395 on: August 15, 2013, 12:46:16 AM »

I have a request for a script that imitates mining operations.

Here is what i need it to do:

1. check if the fleet is near the asteroid body (orbiting it for some clicks)

2. check if the fleet has miner ships in it (checks specific hulls and their numbers)

3. check if player has enough supplies for mining operations (25 per miner) + per day consumption. If he has enough - generate a message 'Mining in progress', else - 'Not enough supplies for mining operations'.

4. generate a random amount of materials at the end of the day if the fleet kept orbiting the asteroid for the whole day

- there are three types of materials that i have already created: basic, rare and exotic
- numbers of generated materials should depend on the amount of the crewed miners in the fleet
- chances of getting rare and exotic materials should be made by a simple randomiser (basic 75, rare 20, exotic 5)

5. a message should prompt once materials are generated and fleet should lose the aforementioned supplies for the mining operations

It would be great to have some skills in 'Industrial' that have impact on supplies consumption rates, chances to get rare materials, number of materials generated etc. I see this as a check in the script that looks for player`s skills and adds bonuses to certain formulas.

All the IDs for hulls and materials i`ll provide later.

The Exerelin mod pretty much does this, minus the part about skills (still a WIP) and specific resources (it just generates Supplies at the moment).

It would be fairly simple to re-purpose what is there to what you want, or I can post examples here if you like?

Tried to look for this part of Exerelin mod`s scripts, but my coding skills are far beyond the ability to clearly figure out what is what.

So yes, if it wont be difficult for you - i`d like to see some examples of the code. Mainly the part with getting to an asteroid and starting harvesting the resources. Oh and this is for player fleet only - no need to put AI controlled fleets here.

Thanks in advance.

Zaphide

  • Admiral
  • *****
  • Posts: 799
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1396 on: August 15, 2013, 02:40:38 AM »

OK I have attached a class (TimeManager) that runs methods at set intervals. I think it was originally made by LazyWizard?

Anyway, I have added a few methods at the bottom to illustrate the player mining supplies. It should all be functional as is but you will need to change it if you wish to have it mine different resources and for it to remove supplies for mining those resources. There are also a couple of methods to check if it is a mining fleet, and to get the number of mining wings.

I have also added a method to move the player fleet on game creation, currently into the middle of the sun... :P

You will need to add a new TimeManager object in your sector generation:
Code
public class ExampleSectorGen implements SectorGeneratorPlugin
{
public void generate(SectorAPI sector)
{
// Build and add a time manager
TimeManager timeManger = new TimeManager();
sector.getStarSystem("Corvus").addSpawnPoint(timeManger); //TODO - change if your star system has a different name
}
}

Hopefully it is what you are after :)

[attachment deleted by admin]
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1397 on: August 15, 2013, 04:37:30 AM »

Thanks!

I`ll try to do that as soon as i get home.

Meanwhile - here is an ISA Harvester-class miner.



It blasts asteroids with its powerful mining blaster and then harvests the materials by moving through the debris field. Large rotary wheels positioned on the sides of this ship`s 'mouth' are powerful enough to break down large chunks and direct the others inside the ship`s refinery where materials are being processed and sorted out.

Large docking port on the left is used by Crawler-XT variants to attach their cargo containers to the miner. The miner itself has low cargo capacity and requires assistance of freighters to operate at full capacity.

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1398 on: August 15, 2013, 06:14:44 AM »

ISA Space Bus-class passenger shuttle.

Jonlissla

  • Commander
  • ***
  • Posts: 227
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1399 on: August 15, 2013, 06:29:53 AM »

Just as ever, incredibly well-made sprites. You're doing a great job. Can't wait until the next update comes and this mod get compatible with it.

I'M PUMPED.
Logged

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1400 on: August 15, 2013, 07:51:37 AM »

OK I have attached a class (TimeManager) that runs methods at set intervals. I think it was originally made by LazyWizard?

Anyway, I have added a few methods at the bottom to illustrate the player mining supplies. It should all be functional as is but you will need to change it if you wish to have it mine different resources and for it to remove supplies for mining those resources. There are also a couple of methods to check if it is a mining fleet, and to get the number of mining wings.

I have also added a method to move the player fleet on game creation, currently into the middle of the sun... :P

You will need to add a new TimeManager object in your sector generation:
Code
public class ExampleSectorGen implements SectorGeneratorPlugin
{
public void generate(SectorAPI sector)
{
// Build and add a time manager
TimeManager timeManger = new TimeManager();
sector.getStarSystem("Corvus").addSpawnPoint(timeManger); //TODO - change if your star system has a different name
}
}

Hopefully it is what you are after :)

Based on your code, made a class for the mining ships, this allows you guys to set any number of ships and their effectiveness in mining without needing to do it one by one, feel free to use it:

Code
package data.scripts.world.init;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.*;
import com.fs.starfarer.api.fleet.FleetMemberAPI;
import java.awt.*;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import org.lazywizard.lazylib.MathUtils;
import org.lwjgl.util.vector.Vector2f;

public class TimeManager implements SpawnPointPlugin
{
private static final float BASE_INTERVAL = 1.0f;
private static final int FIRST_DAY_IN_WEEK = GregorianCalendar.SUNDAY;
private float heartbeatInterval;
private long lastHeartbeat;
private GregorianCalendar calendar = new GregorianCalendar();
        private static final List<MiningShip> MININGSHIP_IDS = new ArrayList<MiningShip>();
        static
        {
            MININGSHIP_IDS.add(new MiningShip("", "mining_drone_wing", 1));
        }

private Boolean playerMoved = false;

public TimeManager()
{
lastHeartbeat = Global.getSector().getClock().getTimestamp();
heartbeatInterval = (1.0f - (Global.getSector().getClock().getHour() / 24f));
}

private void runHourly()
{

}

private void runDaily()
{
// Handle player mining at the end of each day
handlePlayerFleetMining();
}

private void runWeekly()
{

}

private void runMonthly()
{

}

private void runYearly()
{

}

@Override
public void advance(SectorAPI sectorAPI, LocationAPI locationAPI)
{
// Move player if needed
movePlayer();

if (sectorAPI.getClock().getElapsedDaysSince(lastHeartbeat) >= heartbeatInterval)
{
doIntervalChecks(sectorAPI.getClock().getTimestamp());
checkSynched();
}
}

private void doIntervalChecks(long time)
{
lastHeartbeat = time;
runDaily();

calendar.setTimeInMillis(time);

if (calendar.get(GregorianCalendar.DAY_OF_WEEK) == FIRST_DAY_IN_WEEK)
{
runWeekly();
}

if (calendar.get(GregorianCalendar.DAY_OF_MONTH) == 1)
{
runMonthly();

if (calendar.get(GregorianCalendar.DAY_OF_YEAR) == 1)
{
runYearly();
}
}
}

private void checkSynched()
{
// Compensate for day-synch code in constructor
if (heartbeatInterval != BASE_INTERVAL)
{
heartbeatInterval = BASE_INTERVAL;
}
}

private void movePlayer()
{
if(!playerMoved)
{
CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();
playerFleet.setLocation(0, 0); //TODO - CHANGE
playerMoved = true;
}
}

private void handlePlayerFleetMining()
{
CampaignFleetAPI playerFleet = Global.getSector().getPlayerFleet();

if(!isValidMiningFleet(playerFleet))
{
System.out.println("Not a valid mining fleet");
return; // Don't mine anything
}

StarSystemAPI system = (StarSystemAPI)playerFleet.getContainingLocation();

// Need to allow some variance for transversal
Vector2f playerLocation = playerFleet.getLocation();
float xMax = playerLocation.getX() + 5;
float xMin = playerLocation.getX() - 5;
float yMax = playerLocation.getY() + 5;
float yMin = playerLocation.getY() - 5;

List asteroids = system.getAsteroids();

// Check each asteroid to see if fleet is on top of it
for(int i = 0; i < asteroids.size(); i++)
{
SectorEntityToken asteroid = (SectorEntityToken)asteroids.get(i);
Vector2f asteroidLocation = asteroid.getLocation();

if(asteroidLocation.getX() > xMin
&& asteroidLocation.getX() < xMax
&& asteroidLocation.getY() > yMin
&& asteroidLocation.getY() < yMax)
{
// Mine supplies
int miningPower = getMiningPower(playerFleet);
if(miningPower > 0)
{
System.out.println(MathUtils.getDistanceSquared(playerFleet.getLocation(), asteroidLocation));
playerFleet.getCargo().addSupplies(50*miningPower) ;
Global.getSector().addMessage("Mined " + 50*miningPower + " supplies", Color.green);
System.out.println("Mined " + 50*miningPower + " supplies");
}
return;
}
}
}

public boolean isValidMiningFleet(CampaignFleetAPI fleet)
{
List members = fleet.getFleetData().getMembersListCopy();
Boolean hasMiningShip = false;
for(int i = 0; i < members.size(); i++)
{
FleetMemberAPI fmAPI = (FleetMemberAPI)members.get(i);
                       
                        for(int m = 0; m < MININGSHIP_IDS.size(); m++)
                        {
                            if(fmAPI.getSpecId().equals(((MiningShip)MININGSHIP_IDS.get(m)).getVariantID()))
                            {
                                hasMiningShip = true;
                            }
                        }
}

return hasMiningShip;
}

public int getMiningPower(CampaignFleetAPI fleet)
{
int power = 0;

List members = fleet.getFleetData().getMembersListCopy();
for(int i = 0; i < members.size(); i++)
{
FleetMemberAPI fmAPI = (FleetMemberAPI)members.get(i);

                        for(int m = 0; m < MININGSHIP_IDS.size(); m++)
                        {
                            if(fmAPI.getSpecId().equals(((MiningShip)MININGSHIP_IDS.get(m)).getVariantID())) {
                                power += ((MiningShip)MININGSHIP_IDS.get(m)).getEffectiveValue();
                            }
                        }
}

return power;
}
}
MiningShip.java
Code
package data.scripts.world.init;

import com.fs.starfarer.api.combat.ShipAPI;

public class MiningShip
{
    public String variant_id = null;
    public String hull_id = null;
    public int effectiveness = 1;
    public ShipAPI ship = null;

    public MiningShip(String variant_id,
            String hull_id,
            int effectiveness)
    {
            this.variant_id = variant_id;
            this.hull_id = hull_id;
            this.effectiveness = effectiveness;
    }

    public MiningShip(ShipAPI ship,
            int effectiveness)
    {
            this.variant_id = ship.getVariant().toString();
            this.hull_id = ship.getHullSpec().getHullId();
            this.effectiveness = effectiveness;
    }
   
    public String getVariantID() {
            return variant_id;
    }

    public String getHullID() {
            return hull_id;
    }

    public int getEffectiveValue() {
            return effectiveness;
    }
}

If you find an error please reply so i can go and fix it
« Last Edit: August 15, 2013, 08:01:07 AM by silentstormpt »
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1401 on: August 15, 2013, 11:06:48 AM »

File data/scripts/world/TimeManager.java, Line 20, Column 35: JANINO does not support generics

I`ve just replaced mining drone wing with my miners:

        static
        {
            MININGSHIP_IDS.add(new MiningShip("", "isa7-min-harvester_variant", 2));
            MININGSHIP_IDS.add(new MiningShip("", "rsf7-min-scrapper1_variant", 1));
            MININGSHIP_IDS.add(new MiningShip("", "rsf7-min-scrapper2_variant", 1));
            MININGSHIP_IDS.add(new MiningShip("", "rsf7-min-scrapper3_variant", 1));
        }

P.S.: it crashes even without my variants (even before the check of the missing mining drone wing...)

Wyvern

  • Admiral
  • *****
  • Posts: 2528
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1402 on: August 15, 2013, 12:21:04 PM »

To fix this error
File data/scripts/world/TimeManager.java, Line 20, Column 35: JANINO does not support generics
change
Code
       private static final List<MiningShip> MININGSHIP_IDS = new ArrayList<MiningShip>();
to:
Code
       private static final List MININGSHIP_IDS = new ArrayList();

Only gotcha with changing that is that you'll have to cast objects you get out of the list as MiningShip objects... but I think the code already does that?
Logged
Wyvern is 100% correct about the math.

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1403 on: August 15, 2013, 12:24:30 PM »

Yh gotta love JANINO, thanks, keep posting more errors that might come up pls, if we fine tune this, we might be able to add much more functionality, do you have any intention of adding custom resources, because right now its using supplies?

EDIT: There might be a problem in filtering the Hull ID or Variant ID on the second constructor on the MiningShip.java, asking Alex for some light on the correct methods for the variantid and hullid
« Last Edit: August 15, 2013, 12:30:20 PM by silentstormpt »
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1404 on: August 15, 2013, 12:33:34 PM »

Thanks! Trying it now.

As for resources - yes, i already have a set of raw materials (common, rare and exotic), a set of components (low-tech, high-tech, alien-tech), some valuables and Rock Fly parts (eye crystals, organs, plates etc.).

Currently these are randomly added to AI, Alien and Rock Fly fleets as well as to miners and supply convoys. But due to a bug that Alex is aware off - these do not show up in salvage menu after you defeat the proper fleets.

EDITED: and for the same reason they are not transfered to base with convoys.
« Last Edit: August 15, 2013, 12:36:28 PM by Okim »
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1405 on: August 15, 2013, 12:39:15 PM »

Okkey...

Now i have to install LazyLib :)

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1406 on: August 15, 2013, 12:50:04 PM »

Alright, so far,

When mining, you got 2 choices, asteroids or gas giants, the script is checking for asteroids only:

Code
List asteroids = system.getAsteroids();

Once the fleet is near a asteroid it should everyday generate x numbers of a CargoType, in this particular case, its Supplies (this ofc, after checking if your fleet has a ship capable of mining AND how many ships and how effective each ship can mine):

Code
System.out.println(MathUtils.getDistanceSquared(playerFleet.getLocation(), asteroidLocation));
playerFleet.getCargo().addSupplies(50*miningPower) ;
Global.getSector().addMessage("Mined " + 50*miningPower + " supplies", Color.green);
System.out.println("Mined " + 50*miningPower + " supplies");

The easy way would be to change that addSupplies to addItem and get your custom items, maybe with a x chance of getting certain resources, but there are 2 problems with this:

1st Everytime you add a new resource you have to add more code here, this would be fine with 5 or 6 max, if it grows to 10+ it can become a problem
2nd The asteroids, they are all the same, it matters little to what u picked to be mined, the results are always based on the ships used.

So how do we spice up?
By creating a class for asteroids, each time you get close to one, it creates a new asteroid class, this class add properties to it like, size, type, amount of minerals, chances of x mineral. This list (for now) is filled automatically, this also means it wont be saved sadly. In 0.6a you can create JSON/CSV files to fill these automaticly or even add to the save file so it actually have the same list with no changes.
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1407 on: August 15, 2013, 01:05:36 PM »

I thought to make it all random. I`ll use just these 3 material types with common being the main one to be mined and others having some odds to replace the common one (a simple if + math.random when your script pick the amount of resources generated).


P.S.: now the game says this:
File data/scripts/world/TimeManager.java, Line 23, Column 47: Cannot determine simple type name "MiningShip"

Man, i feel being too dump...

silentstormpt

  • Admiral
  • *****
  • Posts: 1060
    • View Profile
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1408 on: August 15, 2013, 01:16:11 PM »

Dont forget you need to have MiningShip.java on the same folder as the TimeManager.java

if you do have them both, check the MiningShip.java code and see if the

Code
package data.scripts.world;


is like this.
« Last Edit: August 15, 2013, 01:17:50 PM by silentstormpt »
Logged

Okim

  • Admiral
  • *****
  • Posts: 2146
    • View Profile
    • Okim`s Modelling stuff
Re: Project Ironclads, version 5.2 (0.54.1)
« Reply #1409 on: August 15, 2013, 01:22:48 PM »

Source file "data/scripts/world/TimeManager.java" does not declare class "data.scripts.world.TimeManager"

I updated a sectorgen file and renamed Corvus to my star`s name.
Pages: 1 ... 92 93 [94] 95 96 ... 281