[MOD] Shipyard and Player Shipyard - Ship recycling v0.07 (6 Apr 2017)

The place to discuss scripting and game modifications for X Rebirth.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

[MOD] Shipyard and Player Shipyard - Ship recycling v0.07 (6 Apr 2017)

Post by jth » Tue, 16. Dec 14, 16:57

6 Apr 2017

Changes from v0.06

Compensate for format of game version string changing in 4.10 RC3 and add extra paranoia when checking version to prevent crashing the GUI

Changes from v0.05

Got the calculator out to check the sums on recycling and found that they were actually broken as of v0.04 and far too generous. Fixed.

Add remote logging via md script to remove false positive Error messages, caused by lua DebugError logging commands, in debug.log that were actually informational
Compensate for parameter changes to Encyclopaedia API in 4.00 RC2 to prevent Encyclopaedia buttons crashing the GUI
Apply a 90% recycling factor to ship hull wares
Rebalance prices to track what shipbuilders pay to buy back ships (80%), drones (85%) and ammunition (90%)
Add an extra 10% handling charge to wares that could be sold to the station by the player before the ship is recycled. As the Teladi say "time is money".
Changed API call used for calculating free space to take into account the available space for the ware instead of total available space
Fix issue with calculating refund when recycling where there is no storage space for a specific ware. Now correctly refunds 50%
Adjusted on screen messages a litle for when ware doesn't all fit into shipyard storage
Suppress Drone section when there are no drones

I have just uploaded version 0.06 to the Nexus mod site. Steam also updated

www.nexusmods.com/xrebirth/mods/428/

This mod adds the ability to Recycle a ship. It changes the ShipTrader menu option Sell a ship to Sell or recycle a ship

This should allow you to operate in Pirate mode and use the recycled wares to build your own ships.

It will also integrate the NPC shipyards better into the local economy as the wares from ship recycling will be used by NPC shipyards rather than the sold ship just sailing off and never being seen again.

The mod patches Egosoft's ShipTrader.xml file to add the extra option and back end code.

How to Use

Fly to the zone that contains the shipyard that you want to use to recycle your ship
Open communications with the right Ship Trader for the size of vessel that you are recycling
Pick the "Sell or recycle a ship" menu option
Select the ship and then click on either the Recycle or Sell button.
The Sell button sells the ship in the normal way using standard Egosoft code at the standard price
The Recycle button opens up the Recycle Cost menu for the selected ship where you can see the recycling information
Then pick "Yes, recycle this ship"
Sit back and watch the ship move into the docking cradle and then observe the hull and weapons getting recycled

Features

Allows recycling of L and XL ships in Player Shipyards and NPC Shipyards
Uses a customised version of Egosoft's PropertyMenu and BuildCostMenu GUI menus to select the ship to be recycled and show you what wares will be recovered
Checks a number of pre-requisites to make sure that recycling can proceed and notifies player if there are any problems before allowing the player to continue.
PropertyMenu checks that the recycling ship will fit into the individual ShipTrader's ship cradle.
BuildCostMenu checks that the shipyard has enough food, energy and construction drones present and that the recycling ship is in the same zone as the player (needed if you want the weapons and shields back).
Recycles hull wares taking into account the state of the hull at the time
Recycles operational Weapons and Shields plus installed drones, ammunition and cargo
When recycling cargo it pays the full price for any wares that will fit in station storage and 50% if they do not fit or are not standard wares for a shipyard
If the Shipyard is NPC owned then the player is paid for the ship in the same way as the current Sell a ship
Consumes energy and food rations to carry out recycling
Moves ship into appropriate ship cradle and chops the hull up piece by piece
Pays player for crew and recreates NPC's with same skills as ship crew on shipyard where they can be hired by player. This means that if you spend time training crew then their replacement will also have the benefit of the training.
The types of NPC that are recycled are the ship Control Entities which include pilot, captain, defense officer, engineer and architect.
Will try to put recreated crew in the bar if it can find it and there is room otherwise picks any personnel docking bay that has space.
Maintains individual ShipTrader locking so that an individual ship trader can only do one thing at a time
Aborts recycle if ship is destroyed before it gets into dock just like the other ShipTrader operations.
Logs ship recycling in player log book
Logs a lot of information to debug.log so that the recycling process can be checked and diagnosed


Known issues
If there is no space on the shipyard for recreating the crew then they will not be recreated but you will still be paid for the old crew.
The amount that is paid for a crew contract is calculated by calling the Egosoft FeeCalculation cue from NPC_Staff without applying any recycling factors as its going to be pretty random anyway. To quote from the code <!-- 1/4 = skill based, 3/4 = random -->. It will almost definitely be different to what you paid for that crew member in the first place.
If you leave recycled crew on the shipyard for too long then they will eventually get cleaned up by the Egosoft station crew script and replaced by someone else with different skills.
Using multiple ShipTraders from the same shipyard at the same time may have unfortunate consequences, do not attempt to recycle two ships at the same time.
When recycling there is no check that recycled wares can fit in station storage for anything except ship cargo. There were no checks at all before v0.04

To Do

Small ShipTraders if suitable case made by players and enough demand, ware amounts are rather small for m ships.
Fly some construction drones around during chop up phase
Look at simultaneous multi ship recycling

=== Release history ===
- [24.2.2016 - V0.06 Public Beta]
shiprecycle_menu_cost gui - Add remote logging via md script to remove false positive Error messages, caused by DebugError logging commands, in debug.log that were actually informational
shiprecycle_menu_cost gui - Compensate for parameter changes to Encyclopaedia API in 4.00 RC2 to prevent Encyclopaedia buttons crashing the GUI
shiprecycle_menu_cost gui - Apply a 90% recycling factor to ship hull wares
shiprecycle_menu_cost gui - Rebalance prices to track what shipbuilders pay to buy back ships (80%), drones (85%) and ammunition (90%)
shiprecycle_menu_cost gui - Add an extra 10% handling charge to wares that could be sold to the station by the player before the ship is recycled. As the Teladi say "time is money".
shiprecycle_menu_cost gui - Changed API call used for calculating free space to take into account the available space for the ware instead of total available space
shiprecycle_menu_cost gui - Fix issue with calculating refund when recycling where there is no storage space for a specific ware. Now correctly refunds 50%
shiprecycle_menu_cost gui - Adjusted on screen messages a litle for when ware doesn't all fit into shipyard storage
shiprecycle_menu_cost gui - Suppress Drone section when there are no drones

- [11.1.2016 - V0.05 Public Beta]
shiprecycle_menu_cost gui - Fixed failure to recycle any ships when there was zero energycells or foodrations on the shipyard which will happen with a brand new player shipyard

- [10.12.2015 - V0.04 Public Beta]
Completely rewrote the ship selection user interface using customised versions of menu_property.lua and menu_buildcost.lua
Moved ship selection logic out of md script and into the GUI
This means that you cannot select a ship for recycling that does not fit in the ShipTraders cradle unlike previous versions where this was allowed initially but detected later and the process aborted
RecycleCostMenu checks the shipyard prerequisites before allowing you to OK which again avoids a later abort for lack of ShipTrader resources
The GUI API calls can get the shields and turrets from a ship that is Out Of Zone (OOZ) so the restriction on the recycled ship being in the same zone as the player has gone
No longer shares the sellship confirm menu so it makes one less change to ShipTrader.xml
Now recycles installed drones, ammunition and cargo
When recycling cargo it pays the full price for any wares that will fit in station storage and 50% if they do not fit or are not standard wares for a shipyard
When cloning the crew to the shipyard bar it now keeps their original names
Now multi lingualwhich means that a lot of the messages will have changed subtly to fit existing translated words
Now makes a single fund transfer for all crew contracts to cut down on event monitor messages
Now uses the FormatThousands library to format the money amounts with a separator between thousands
Removed ship selection logic and its event monitor messages from md script
Removed ship building ware estimate code from md script as this is now done in the RecycleCostMenu lua script which means that it no longer builds a dummy ship to find the necessary wares
Removed ship turret and shields finding code from md script as this is now done in the RecycleCostMenu lua script
Modified the station stocking code to use the less complicated array that RecycleCostMenu creates
Replaced the turret and shields stocking code with a simple loop that adds the drones, ammunition and cargo to the station from another array that RecycleCostMenu creates
Checks selling price of NPC's and if greater than max allowed then compensates by dividing by 100

- [27.3.2015 - V0.03 Public Beta]
Interoperability - added support for Combined Docks example code by UniTrader even though its not on Steam or Nexus

- [13.3.2015 - V0.02 Public Beta]
Major change - Removed use of boarding pods to transport crew onto shipyard, crew contracts now sold to the shipdealer and they stay on board ship
Pays player for crew and recreates NPC's with same skills as ship crew on shipyard where they can be hired by player.
Tries to put recreated crew in the bar if there is room otherwise picks any docking bay that has space.
Converts the player owned NPC's that were transported to the shipyard via boarding pod while running version 1 of this script into hireable NPC's and pays player for them
Fixes an issue where recycling was refused due to insufficient shipyard resources caused the commander of the ship that was being recycled to get a blackboard entry of $shiptrader_docking added which prevented that ship from ever being recycled or sold.

- [14.12.2014 - V0.01 Public Beta]
Initial Release

Regards

jth
Last edited by jth on Thu, 6. Apr 17, 15:54, edited 9 times in total.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Tue, 16. Dec 14, 17:11

Sweet, will test with an NPC shipyard this evening. Thanks :)

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Re: [MOD] Shipyard and Player Shipyard - Ship recycling

Post by w.evans » Tue, 16. Dec 14, 17:15

Sounds cool! Proof that environmentally friendly measures can be good for the economy! (at least in space)

Have a question about this though:
jth wrote:Evacuates crew via boarding pod to the Shipyard
If I were to recycle a ship in an NPC shipyard (not ready to make the leap to Player Shipyards yet) will my crew remain hired? Can they act as trade agents/spies in the Shipyard? Will I have to re-hire them?

edit: "friendly"

dez505
Posts: 172
Joined: Wed, 6. Nov 02, 20:31
x4

Post by dez505 » Tue, 16. Dec 14, 17:26

As cool as this is I think it needs a recycle penalty like -20%/30% on return otherwise it may very much unbalance the economies only sink-hole :P


Other than that this is an amazing peace of work!

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Post by BlackRain » Tue, 16. Dec 14, 20:29

dez505 wrote:As cool as this is I think it needs a recycle penalty like -20%/30% on return otherwise it may very much unbalance the economies only sink-hole :P


Other than that this is an amazing peace of work!

This is really intended for player shipyards so no penalty is needed. While you can recycle ships at an NPC shipyard, you do not have to. If you do not want to recycle at an NPC shipyard you can just sell it. It is your choice.

User avatar
NZ-Wanderer
Posts: 1623
Joined: Thu, 5. Aug 04, 01:57
x4

Post by NZ-Wanderer » Tue, 16. Dec 14, 20:34

Oooo, I like the sound of this...
One silly question tho, I still have blackrains player shipyard installed as well as this one right :) (told ya it was silly question)
Link to the list of Mods working in X4-Foundations and also Link to the list of Mods working in X-Rebirth

NOTE: I play with a modded game, so any reports I make outlining suggestions/problems/bugs/annoyances, are made with mods installed and running.

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Tue, 16. Dec 14, 21:24

dez505 wrote:As cool as this is I think it needs a recycle penalty like -20%/30% on return otherwise it may very much unbalance the economies only sink-hole :P


Other than that this is an amazing peace of work!
The state of the hull is also used to limit recycling, so if your hull is 70% then you only get 70% of the wares. That stops you getting paid for the missing 30%.

You do get charged the full food and energy requirements independent of hull state. Not sure what that is as a percentage.

Bit undecided about whether to also add say an 80% factor on top of that like the station recycling. As you would only get 56% if you started with a 70% hull and then added a recycling efficiency of 80%. A shipyard ought to be better at recycling that a Construction Vessel.

The station recycling has the bonus that 80% gets everything to fit in the CV even for big stations :)

Might give 90% some thought. What do you think ?
Last edited by jth on Tue, 16. Dec 14, 21:32, edited 1 time in total.

User avatar
NZ-Wanderer
Posts: 1623
Joined: Thu, 5. Aug 04, 01:57
x4

Post by NZ-Wanderer » Tue, 16. Dec 14, 21:27

Personally, I would say, if the ship is damaged at all, then you get the % that the ship is..
If the ship is 100% then maybe you get 80% recycled..

This IMHO would be the fairest thing to do :)
Link to the list of Mods working in X4-Foundations and also Link to the list of Mods working in X-Rebirth

NOTE: I play with a modded game, so any reports I make outlining suggestions/problems/bugs/annoyances, are made with mods installed and running.

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Re: [MOD] Shipyard and Player Shipyard - Ship recycling

Post by jth » Tue, 16. Dec 14, 21:31

w.evans wrote:Sounds cool! Proof that environmentally friendly measures can be good for the economy! (at least in space)

Have a question about this though:
jth wrote:Evacuates crew via boarding pod to the Shipyard
If I were to recycle a ship in an NPC shipyard (not ready to make the leap to Player Shipyards yet) will my crew remain hired? Can they act as trade agents/spies in the Shipyard? Will I have to re-hire them?

edit: "friendly"
I have to admit that I don't know. I was more concerned with keeping them around even if I had to rehire them.

What happens with the station recycle (uses the same API call) is that they end up on the Skunk and retain their loyalty to you and can be told to work elsewhere, so no rehire fees. I don't think that they will act as trade agents/spies.

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Tue, 16. Dec 14, 21:45

Sounds good. Thanks for taking the time to answer. Will take 'er for a spin.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Tue, 16. Dec 14, 22:31

jth wrote: You do get charged the full food and energy requirements independent of hull state. Not sure what that is as a percentage.
Funnily enough, I was thinking about the same thing this afternoon and did some quick calculations for all the non-TO civilian M-XL ships as I had all their build requirements in a spreadsheet. Food+ECs is typically about 0.3-0.8% of base build costs. I agree it is a good idea to retain the ECs and Food as they sound like construction costs but it isn't a substantial amount.
jth wrote: Might give 90% some thought. What do you think ?
Tricky question since as I understand things, shipyards essentially work for free because ships only seem to cost 'resources' rather than 'resources+build fee'. If that is correct, it might be most logical to factor that it first. Although in any case, since no process is 100% efficient, loosing a few % of each resource would be logical.

I guess what I would imagine as nice in an idea world would be that you add a cost to all ships in the game equal to x% that a shipyard charges as a profit on ship construction. Then have that fee be waved at player-owned shipyards when players build stuff and have that fee not given to the player when they recycle a ship at an NPC station. As long as their is a suitable penalty applied when ships are sold to NPC stations (as is currently), it should prevent generating free money though building and selling.

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Post by BlackRain » Wed, 17. Dec 14, 02:09

Sparky Sparkycorp wrote:
jth wrote: You do get charged the full food and energy requirements independent of hull state. Not sure what that is as a percentage.
Funnily enough, I was thinking about the same thing this afternoon and did some quick calculations for all the non-TO civilian M-XL ships as I had all their build requirements in a spreadsheet. Food+ECs is typically about 0.3-0.8% of base build costs. I agree it is a good idea to retain the ECs and Food as they sound like construction costs but it isn't a substantial amount.
jth wrote: Might give 90% some thought. What do you think ?
Tricky question since as I understand things, shipyards essentially work for free because ships only seem to cost 'resources' rather than 'resources+build fee'. If that is correct, it might be most logical to factor that it first. Although in any case, since no process is 100% efficient, loosing a few % of each resource would be logical.

I guess what I would imagine as nice in an idea world would be that you add a cost to all ships in the game equal to x% that a shipyard charges as a profit on ship construction. Then have that fee be waved at player-owned shipyards when players build stuff and have that fee not given to the player when they recycle a ship at an NPC station. As long as their is a suitable penalty applied when ships are sold to NPC stations (as is currently), it should prevent generating free money though building and selling.
You aren't getting free money from building and selling. Again, the idea was to capture ships and recycle them at your own station. You would make more money by just selling ships you captured once their hull was mostly repaired.

Also, the amount of resources you get is not substantial. You have to consider the following, the idea was that you could play as a pirate, completely independent from any faction. This means, you could build ships, and stations, all without ever buying any resources (except for initial start up cost of food and energy but later you could build stations to give you this).

In order to build stations, you need to capture and recycle ships. You can then shift resources around (with your transports by moving them from shipyard to ship and then to CV's when constructing, etc.). This requires a lot of resources. Given that boarding is difficult to begin with and takes a lot of time, plus the requirements of resources when building ships and stations, it will take a substantial amount of time and energy to build up a real empire but this is part of the fun in my opinion. However, lowering the amount of resources received further would be to the detriment of this play style. I assure you, it already is difficult enough with the current resources given but I think it is just right.

To add further to my point, you would make more money by selling the captured and repaired ships then by selling the resources you obtain from recycling. It would be much more profitable to just sell all the ships you board given the fact that you would have to trade in various resources and always at substantial gain. It is just much more profitable to board and quickly sell, rinse and repeat. Therefore, no change is necessary in limiting resources gained any further.

Now, I can just easily change the script to my own liking, but it is in my opinion that the way it is now is sufficient for good game play.

Sparky Sparkycorp
Moderator (English)
Moderator (English)
Posts: 8074
Joined: Tue, 30. Mar 04, 12:28
x4

Post by Sparky Sparkycorp » Wed, 17. Dec 14, 08:19

Thank you very much for taking the time to reply in detail. I didn't understand the system properly and appreciate the info. Sound's great.

Aranov
Posts: 134
Joined: Mon, 3. Jun 13, 23:08
x4

Post by Aranov » Wed, 17. Dec 14, 21:33

Hi, just wanted to thank you and everyone who helped for making and releasing this mod.

My biggest problem with X:R was being unable to build or repair my ships do to a faulty economy, while the AI got ships spawned in for free most of the time(I'm Looking at you, Marauder Titurels and PMC Wardens).

I've tested it out in the HoA shipyard, everything worked perfectly. Soon I'll have my own shipyard and I'll be seeing how it works there.

Thank you again!

dez505
Posts: 172
Joined: Wed, 6. Nov 02, 20:31
x4

Post by dez505 » Wed, 17. Dec 14, 21:44

Question can it be done so hull% = resource amount returned?

BlackRain
Moderator (Script&Mod)
Moderator (Script&Mod)
Posts: 7406
Joined: Mon, 15. Dec 03, 18:53
x4

Post by BlackRain » Wed, 17. Dec 14, 22:28

dez505 wrote:Question can it be done so hull% = resource amount returned?

It already is that way.

dez505
Posts: 172
Joined: Wed, 6. Nov 02, 20:31
x4

Post by dez505 » Wed, 17. Dec 14, 22:38

hats off to you good sir! :o

Aranov
Posts: 134
Joined: Mon, 3. Jun 13, 23:08
x4

Post by Aranov » Mon, 5. Jan 15, 01:34

So I've been using this mod for awhile(great mod btw), and I've noticed a small but rather annoying bug concerning a ship's crew.

Crew that have been recycled have a habit of disappearing at some point after they've been assigned to a new ship.

In the most recent case of this happening a captain and defense officer disappeared from one of my bulk rahanas.

The engineer interestingly, did not disappear. When I asked him to board the Skunk he did charge me, as if I was hiring him for the first time.
The captain and defense officer did not do this. This might be connected to the disappearing crew.

Other then this the mod works great, but the growing number of crew on my shipyard the may disappear if I try to use them does concern me.

jth
Posts: 296
Joined: Tue, 3. Jan 06, 23:31
x3

Post by jth » Tue, 6. Jan 15, 14:20

Aranov wrote:So I've been using this mod for awhile(great mod btw), and I've noticed a small but rather annoying bug concerning a ship's crew.

Crew that have been recycled have a habit of disappearing at some point after they've been assigned to a new ship.

In the most recent case of this happening a captain and defense officer disappeared from one of my bulk rahanas.

The engineer interestingly, did not disappear. When I asked him to board the Skunk he did charge me, as if I was hiring him for the first time.
The captain and defense officer did not do this. This might be connected to the disappearing crew.

Other then this the mod works great, but the growing number of crew on my shipyard the may disappear if I try to use them does concern me.
Interesting. Thanks for reporting this. I have a feeling that there are a few subtleties lurking under the surface. Maybe a clean up script in action.

I think that this will only happen for player owned shipyards as NPC ones have no space for more crew so they never get there. The boarding pod AI script zaps them when it works out there is no room :(

I do feel that we need to retain the crew somehow or it creates a shortage locally.

Having decided to be nice to the crew (and the players wallet) I had two options on how to deal with them for ship and station recycling.

1) Keep them as player owned and let the boarding pod AI script do the work

This obviously avoids re-hiring them and is roughly equivalent to telling them to re-board the Skunk but without filling up the Skunk. Popping crew back into the Skunk is vanilla game stuff but popping them onto a station cannot be done. Egosoft's solution to popping them back onto a station is to destroy them when you fire them which seems a bit mean :( but it is a nice simple solution :)

I have been toying with creating an NPC Recycling mod to stop them being destroyed but it would have to make sure that there was room.

2) Turn them back into non player owned and make them re-hireable

This one will obviously cost you a re-hire fee and I suspect that I would need to do a few extra things to make them re-hireable

2a) Recreate them as non player owned and make them hireable

The names would change but their job role would be retained, again there would be a re-hire fee . I suspect that this would be cleaner and more likely to work over a longer period than option 2



I guess that option 2a is more compatible with a vanilla game than option 1 or 2 and it might be possible to give the player back half the hiring fee to cushion the effect on their wallets.

Anybody see any problems with this ?

Regards

jth

w.evans
Posts: 2963
Joined: Tue, 18. Nov 14, 16:23
x4

Post by w.evans » Tue, 6. Jan 15, 14:24

2a looks good. Is there a reason why it wouldn't be good to give back the full hiring fee?

edit: And if an NPC were trained before the ship were recycled, would the hiring price go up? And would the refund go up as well?

Post Reply

Return to “X Rebirth - Scripts and Modding”