Home World Forum
Stars! AutoHost web forums

Jump to Stars! AutoHost


 
 
Home » Stars! Clones, Extensions, Modding » FreeStars » Cargo Transfers from the client
Cargo Transfers from the client Sat, 06 January 2007 12:01 Go to next message
sirgwain is currently offline sirgwain

 
Senior Chief Petty Officer

Messages: 86
Registered: March 2004
Location: Tucson
I have a question about doing cargo transfers from the client. In current Stars!, there are two ways to do it. You can set a waypoint 0 transfer order, or you can open up the fleet transfer dialog and drag cargo from a planet (or other fleets) to your current fleet.

This is easy in old Stars! because the files are encrypted and therefore trusted. You can do all the work on the client side. In a server environment, however, you can't be so trusting. I have to put the fleet transfer dialog cargo transfers into the form of a request you submit to the server. I also have to make it seem like the transfer happens instantly from the client perspective (i.e. you load your colony ship with colonists and it shows up right away).

I would love to have all cargo transfers done as WP0 orders. It makes things simpler from a server perspective and the client just has to use the fleet transfer dialog to set/read the WP0 orders to display correctly. There is a problem with this approach though. You could conceivably transfer cargo from fleet A to fleet B to fleet C to the planet. If you have very minimal resources you have to ensure that these transfers are done in order on the server side, lest you have no resources to transfer when you need them. Right now, my WP0 orders are executed in the order the fleets were created, so it's non-deterministic.

To get around this I've created a CargoTransfer object. As the client performs cargo transfers with the Fleet Transfer dialog, it creates CargoTransfer objects detailing the transfer and adds them to an array. The server processes these transfers in the order they were added.

This is working ok, but it unfortunately means I have to have two methods on the server to do essentially the same operation, transfer cargo. I can't think of a better way to do it, but if anyone has any l33t ideas, please share them. Smile

Report message to a moderator

Re: Cargo Transfers from the client Sat, 06 January 2007 15:36 Go to previous messageGo to next message
gible

 
Commander

Messages: 1343
Registered: November 2002
Location: Wellington, New Zealand

Firstly, keep a separate array for each location.

Second, the way you're doing it by explicitly listing every player-cargo interaction would have to remain intact, but you might consider creating a clientside method to combine multiple transfer orders into a single order to send to the server. Rather like vector arithmetic. You'd have to be careful you don't create a bug tho. A heavy handed but effective security against this would be to have the combinations happen automatically after each transfer action and only combining the new order with the previous order(if valid). If you use location arrays(above) this could reduce orders significantly..depending on the complexity of your transfer order object.

Report message to a moderator

Re: Cargo Transfers from the client Sat, 06 January 2007 22:48 Go to previous messageGo to next message
LEit is currently offline LEit

 
Lt. Commander

Messages: 879
Registered: April 2003
Location: CT
What I did was to do the manual transfers first, in order the player requests them, then the wp0 orders are done in fleet # order. Every transfer is limited to the amount in the fleet that is being transferred from. The only time you need a temporary array is when there is a transfer to space (jettison), since that could be picked up by something else at the same location.


- LEit

Report message to a moderator

Re: Cargo Transfers from the client Mon, 08 January 2007 18:13 Go to previous messageGo to next message
sirgwain is currently offline sirgwain

 
Senior Chief Petty Officer

Messages: 86
Registered: March 2004
Location: Tucson
I don't need an extra array for efficency. Every cargo transfer knows the from/to objects that it is transferring from/to.

LEit, I hadn't thought of the situation where multiple transfers could occur from seperate players. How do you resolve race conditions between players transferring all the available cargo from the same location? Do they divvy it up or is it just first come first serve? I think the way I have it implemented now it would be first come first serve, but it might just crash, haha.

Report message to a moderator

Re: Cargo Transfers from the client Mon, 08 January 2007 21:35 Go to previous messageGo to next message
LEit is currently offline LEit

 
Lt. Commander

Messages: 879
Registered: April 2003
Location: CT
Testing showed that Stars! did it in a race, but it wasn't clear who would win. It's fairly rare, you need two players both with miners at the same location, or a SS with cargo stealing ships and some one else with cargo ships. The SS is more likely, and I think the SS should always win that one. Now, two players with cargo stealing ability should probably be a race.

I think in FreeStars, I made the winner of the race random each turn.



- LEit

Report message to a moderator

Re: Cargo Transfers from the client Thu, 18 January 2007 21:00 Go to previous messageGo to next message
Dogthinkers is currently offline Dogthinkers

 
Commander

Messages: 1316
Registered: August 2003
Location: Hiding from Meklar
LEit wrote on Tue, 09 January 2007 13:35

It's fairly rare, you need two players both with miners at the same location, or a SS with cargo stealing ships and some one else with cargo ships.


Some more common events where races can occur are recovering scrap from a significant battle that occurred in open space or extracting minerals from a mass packet.

Report message to a moderator

Re: Cargo Transfers from the client Mon, 29 January 2007 18:09 Go to previous messageGo to next message
sirgwain is currently offline sirgwain

 
Senior Chief Petty Officer

Messages: 86
Registered: March 2004
Location: Tucson
I did much troublesome implementing of Cargo transfers and got it almost working correctly. Then I realized that my client code for doing dragging of minerals from planets to ships and such was far too complicated to be in Client code. Client code should always be simple.

As such I'm going to implement what I think gible was suggesting. I'll have a list of universe objects keyed off of universe location. Every object that shares a location and an owner will have a pool of resources to pull from (all the resources on the planet and any fleets that are at the same location). The client will just transfer resources willy nilly between objects and submit the objects to the server with new Cargo values.

The server will validate that the "pool" of total resources at each location remains the same for the new client objects, and if so it will take the new client values and put them in the server side objects.

In the case of a race for resources between two or more players at the same location, I think I will disable the ability to drag those resources around on the client side and force the user to put in a waypoint0 order to suck up the resources at that spot. That way I can handle those cases seperately as waypoint0 race conditions. I don't see this being a common enough situation to be a pain for any user. Most of the time I imagine people send ships out to suck up those resources.

This approach ought to simplify things everywhere except the one server function that has to check the new client cargo values. Most of that code for organizing fleets and planets by location is being done anyway to handle battles, so it shouldn't be too big of a complication...

Report message to a moderator

Re: Cargo Transfers from the client Tue, 30 January 2007 08:11 Go to previous messageGo to next message
Kotk

 
Commander

Messages: 1227
Registered: May 2003
sirgwain wrote on Tue, 30 January 2007 01:09

As such I'm going to implement what I think gible was suggesting. I'll have a list of universe objects keyed off of universe location. Every object that shares a location and an owner will have a pool of resources to pull from (all the resources on the planet and any fleets that are at the same location). The client will just transfer resources willy nilly between objects and submit the objects to the server with new Cargo values.

The server will validate that the "pool" of total resources at each location remains the same for the new client objects, and if so it will take the new client values and put them in the server side objects.


NOTE 1: The fleets may be split/merged so ships may be cargo conteiners on one hand and transfered objects on other hand.

NOTE 2: there may be (not neccessarily static) conteiners that are possible to manipulate by multiple races at any given location. These are salvage and packets, remote-mined and/or robber-baroned planets and pick-pocketed or robber-baroned fleets.

As result each players client may submit his idea of the new fleets at location and their cargo values.
These are probably not same for all players despite all being valid on their own. Server has somehow to resolve the conflicts between different players there. Rolling Eyes

I think stars! uses method that in turn file there may be tons of cargo transfer commands:
object id that transfers cargo
object id versus what it transfers
amount of fuel to transfer
amount of ironium to transfer
amount of germanium to transfer
amount of colonists to transfer
(object ids are not neccessarily fleets and amounts may be negative too)

These are intermixed with tons of manual split and/or merge fleet commands:
fleet id that transfers
fleet id to what it transfers
design bitmap (each bit marking design that participates in transfer)
amount of first participant design transfered
...
amount of last participant design transfered
(amounts may be negative too)

Cargo ships may participate in split/merges and their cargo is also split/merged during it.
With that split/merge command one may create new fleet with previously unexisting ID (1..512). One of the participants may become empty of ships and therefore unexisting (and so the fleet ID is free to use in different place). The ID-s are universal so by doing lot of work you may make same ID to exist (at least temporarily) in all places. Wink

Exclamation The order of such manual splits/merges and cargo transfers is very important, all it must be evaluated step-by-step for one player. Exclamation

I dont know how stars! resolves conflicts between players, some randomizing seems to be done but not in the order of single player commands. Mineral upload cheat is there and robber baron has bugs and Wumpus has said that transfers are not validated too well so it is far from perfect. Wink

But ... you must put lot of thought into it if you want to make it all as one single order per location. Nod


[Updated on: Tue, 30 January 2007 09:04]

Report message to a moderator

Re: Cargo Transfers from the client Tue, 30 January 2007 12:06 Go to previous message
Iconian is currently offline Iconian

 
Officer Cadet 2nd Year

Messages: 233
Registered: January 2006
Location: Nevada, USA
I'm not a programmer, so maybe I'm misunderstanding, but my dad was a programmer for 20 years. He wrote a database a few years back in which he made certain that every person in the system had a particular ID that would never change. Perhaps I've missed grasping something, but I think that you should attach permanent ID's to every fleet. Once you build a ship it gets an ID number, and that ID number will never change. Though ships may come and go, be destroyed and scrapped and built and merged, all will retain their original ID's. I think my dad said that having that single ID made it much easier to keep track of everything in the system.

Hopefully this comment is even pertinent to this discussion . . .



Yeah, bread too.

Don't Let the Stars! Fade Away

Report message to a moderator

Previous Topic: Looking for a tester (or two) for an open-source Stars! clone
Next Topic: New AR ability
Goto Forum:
  


Current Time: Fri May 03 11:50:54 EDT 2024