Ambrosia Garden Archive
    • Getting more from Contribute-Require flag bits


      identifying all 768 possible ship types

      ( this thread was prompted by a remark from rmx256 in another topic that he wished there were more than 64 Contribute-Require bits )

      I can here you thinking... 768 ships and only 64 flag bits, how's he going do that ?.
      The next thing you might think is... oh yeah, use the bits as a counter, then I only need 10 bits for 768 ships.
      Nope, that's not going to work either. Because any resource that has a Require bit test capability can only test for the existence of a bit, but cannot test for the absence of a bit. So if one were to try and use 10 Contribute-Require flag bits (CRFs hereafter) as a counter, all ships with an odd number count would then look the same to a resource trying to test for ship number one. And all ships that had an even number count would look like ship number two. And so on and so forth.

      Divide and conquer is the basic rule to use. The way to do this is to categorize the ships into groups, classes, types, variants, governments, technology, mass values, crew count or whatever kind of groupings your particular application needs. I'm going to use the Nova scenario as an example to work with, since we're all familiar with it. This example is only concerned with ships that can be piloted by the player. Nova has 288 ships spread out among 60 types, each type having from 1 to 16 variants. The 60 ship types can be further divided into the three game engine mass groups (below 100 tons, from 100 to 199 tons, and 200 tons or greater). But more divisions are needed for this purpose, so governments and ship function can be used to further divide ship types. There are 6 ship producing governments: Federation, Auroran, Polaris, Pirate, Rebel, and civilians. For the sake of this example I'm going to define the ship functions as Carriers, Cruisers, Destroyers, Frigates, Clippers, Corvettes, Heavy-Fighters, Light-Fighters, and Cargo. So to summarize there are...

      16 bits for variant
      3 bits for mass group
      6 bits for producer
      9 bits for function

      34 bits total

      Now if you take each ship in the Nova inventory and classify it according to those 4 categories you'll find that considerably less than 64 bits are needed to identify all 288 ships. In fact this example would theoretically be able to support up to 2592 ships (1636*9 = 2592). If you would like to see a working example of a CRF usage method similar to this, just have a look at my ShipyardUpgrades plug that is in the addons. And no, this is not a ploy to get more people to download my plug. Just a way to convince anyone with doubts that this method of CRF usage has been implemented and actually works. Oh, a word of warning. Using the CRFs to track which ship the player is piloting only works because ship ownership is mutually exclusive. The player can only pilot one ship at a time which prevents any possibility of two different CRF patterns being recorded simultaneously by the game-engine.

    • Arturo, on Jun 22 2005, 02:12 PM, said:

      ( this thread was prompted by a remark from rmx256 in another topic that he wished there were more than 64 Contribute-Require bits )

      I can here you thinking... 768 ships and only 64 flag bits, how's he going do that ?.
      The next thing you might think is... oh yeah, use the bits as a counter, then I only need 10 bits for 768 ships.
      Nope, that's not going to work either. Because any resource that has a Require bit test capability can only test for the existence of a bit, but cannot test for the absence of a bit. So if one were to try and use 10 Contribute-Require flag bits (CRFs hereafter) as a counter, all ships with an odd number count would then look the same to a resource trying to test for ship number one. And all ships that had an even number count would look like ship number two. And so on and so forth.

      Divide and conquer is the basic rule to use. The way to do this is to categorize the ships into groups, classes, types, variants, governments, technology, mass values, crew count or whatever kind of groupings your particular application needs. I'm going to use the Nova scenario as an example to work with, since we're all familiar with it. This example is only concerned with ships that can be piloted by the player. Nova has 288 ships spread out among 60 types, each type having from 1 to 16 variants. The 60 ship types can be further divided into the three game engine mass groups (below 100 tons, from 100 to 199 tons, and 200 tons or greater). But more divisions are needed for this purpose, so governments and ship function can be used to further divide ship types. There are 6 ship producing governments: Federation, Auroran, Polaris, Pirate, Rebel, and civilians. For the sake of this example I'm going to define the ship functions as Carriers, Cruisers, Destroyers, Frigates, Clippers, Corvettes, Heavy-Fighters, Light-Fighters, and Cargo. So to summarize there are...

      16 bits for variant
      3 bits for mass group
      6 bits for producer
      9 bits for function

      34 bits total

      Now if you take each ship in the Nova inventory and classify it according to those 4 categories you'll find that considerably less than 64 bits are needed to identify all 288 ships. In fact this example would theoretically be able to support up to 2592 ships (1636*9 = 2592). If you would like to see a working example of a CRF usage method similar to this, just have a look at my ShipyardUpgrades plug that is in the addons. And no, this is not a ploy to get more people to download my plug. Just a way to convince anyone with doubts that this method of CRF usage has been implemented and actually works. Oh, a word of warning. Using the CRFs to track which ship the player is piloting only works because ship ownership is mutually exclusive. The player can only pilot one ship at a time which prevents any possibility of two different CRF patterns being recorded simultaneously by the game-engine.
      View Post

      why not just use 2 control bits per virtual bit (one for virtual bit=1 and one for virtual bit=0) and do your counter idea? that way you'd only need 20 bits for 1024 ships. just say the 2-bit sequence 10 represents 1 and 01 represents 0, and rather than checking if a single bit is 1 or 0, check if the high or low bit of a pair is 1.

    • nighthawk, on Jun 22 2005, 03:28 PM, said:

      why not just use 2 control bits per virtual bit (one for virtual bit=1 and one for virtual bit=0) and do your counter idea? that way you'd only need 20 bits for 1024 ships. just say the 2-bit sequence 10 represents 1 and 01 represents 0, and rather than checking if a single bit is 1 or 0, check if the high or low bit of a pair is 1.
      View Post

      That's awesome!

    • Yeah, I had the same idea as this recently. rEV uses the 3 bits for mass as you suggest so I thought it could be useful to further classify ships using more bits.
      nighthawk, I don't think that would help though I'm too tired to think it through right now.
      (EDIT): Ah, I see how it works now. So then you've got 2^32 possibilities which is... er... more than I can count. You could have one for every single resource in the entire game and still have over 4 billion remaining.

      This post has been edited by Guy : 23 June 2005 - 08:14 PM

    • I thought of the counter once, then realized that flaw. However, 2 bits never occured to me. Great idea, nighthawk!

    • Yup, that's the most efficient use of the CRFs. Use one 10-bit number for the ship RID and the second 10-bit number for the twos-complement of the RID. Clever nighthawk. However that method does have a drawback. It would only allow a developer to identify one of 768. You couldn't select a subset of ships. Say for instance that you wanted to restrict fighter bay outfits to be only available to Carriers or only to ships with the largest mass value. Or if you wanted to only offer a mission to just Starbridge ships. Couldn't do that with the 20-bit method without burning up a lot of extra outfit or mission resources. But if you spend a few more CRF bits with the method I outlined, you can identify several different subsets of ships. It comes down to what you're trying to implement and deciding which resources you want to conserve.

    • Arturo, on Jun 24 2005, 05:47 AM, said:

      Yup, that's the most efficient use of the CRFs. Use one 10-bit number for the ship RID and the second 10-bit number for the twos-complement of the RID. Clever nighthawk. However that method does have a drawback. It would only allow a developer to identify one of 768. You couldn't select a subset of ships. Say for instance that you wanted to restrict fighter bay outfits to be only available to Carriers or only to ships with the largest mass value. Or if you wanted to only offer a mission to just Starbridge ships. Couldn't do that with the 20-bit method without burning up a lot of extra outfit or mission resources. But if you spend a few more CRF bits with the method I outlined, you can identify several different subsets of ships. It comes down to what you're trying to implement and deciding which resources you want to conserve.
      View Post

      Sure you can. You've still got 44 bits left over to do whatever else you like with.

    • Guy, on Jun 24 2005, 06:26 AM, said:

      Sure you can. You've still got 44 bits left over to do whatever else you like with.
      View Post

      that or do your numbering a bit more carefully and leave some virtual bits of your require field blank (both physical bits 0).
      e.g.:
      not carrier 1: ship id=0=00(virtual)=0101(physical)
      not carrier 2: ship id=1=01(virtual)=0110(physical)
      carrier 1: ship id=2=10(virtual)=1001(physical)
      carrier 2: ship id=3=11(virtual)=1010(physical)
      so to require a carrier, set require to 1?(virtual)=1000(physical)

    • I was just thinking about Arturo's method and realised you could have more flexible tests if you did it backwards - that is check the bits of all classes it doesn't belong to. Then require strings could test for ships of one type or another type or for any types except one.