Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
 Couple bugs
Yesterday, 5:42 pm
By Remcon
Bug in disarm( )
Nov 12, 2017, 6:54 pm
By GatewaySysop
Bug in will_fall( )
Oct 23, 2017, 1:35 am
By GatewaySysop
Bug in do_zap( ), do_brandish( )
Oct 18, 2017, 1:52 pm
By GatewaySysop
Bug in get_exp_worth( )
Oct 10, 2017, 1:26 am
By GatewaySysop
LOP 1.45
Author: Remcon
Submitted by: Remcon
LOP Heroes Edition
Author: Vladaar
Submitted by: Vladaar
Heroes sound extras
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.3
Author: Vladaar
Submitted by: Vladaar
Memwatch
Author: Johan Lindh
Submitted by: Vladaar
Users Online
CommonCrawl, Google, Yahoo!

Members: 0
Guests: 10
Stats
Files
Topics
Posts
Members
Newest Member
477
3,705
19,232
608
LAntorcha
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » Codebases » SWR FUSS » New module system help needed
Forum Rules | Mark all | Recent Posts

New module system help needed
< Newer Topic :: Older Topic >

Pages:<< prev 1 next >>
Post is unread #1 Jun 26, 2009, 10:47 pm
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

Some background information first. We recently put in a system for players to build their own ships, similar to the LotJ way in that you create a ship frame from a blueprint and then finish it by adding ship parts, such as hull pieces. We're going a slightly different route though, in that the only parts needed are for the hull, and all other stats are left at 0, then are set based on installed modules. This will allow the players more freedom to mix and match stuff to suit their needs as far as what they want a ship for.

Now the way I've been designing everything is that we have a "module" item, and, depending on how the various object value #'s are set on it, determines what type of module it is, and how much it affects the ships stats. Having gotten to the point where I can pretty much begin putting the various functions in place to handle all of this I've come upon a bit of a stumbling block on my road to modularized ship goodness. How, after a module is installed, and the actual module object is removed from the players inventory, do I keep track of what modules the ship has, and how much they're affecting the stats they modify?

I COULD simply make it so that the objects are simply set as invisible and are reset in a room in the ship, like the engine room. I don't particularly like that method though. So then I thought, why not a new data structure, module_data, that stores the various object values needed, as well as a pointer to the ship it's installed in. The ship would of course have a pointer to the modules that are installed in it as well.

So I went poking around in the code and it seems to me that I'd need to use the CREATE, LINK, UNLINK and DISPOSE(?) macros in order to keep the various module stats saved so that things like modules being damaged in combat, and therefore changing how much they affect the ship they're installed in, are possible.

So, do I actually need to use those macros in order to get this working or is there another way I can save the stats somehow so damage or removal of the modules can affect the ship? And if I do, how exactly would I go about it? Can't quite get my brain wrapped around how that stuff is working from looking at the code...
       
Post is unread #2 Jun 27, 2009, 10:47 am
Go to the top of the page
Go to the bottom of the page

David Haley
Sorcerer
GroupMembers
Posts903
JoinedJan 29, 2007

Yes, you need to use those macros to maintain a linked list of things; they don't actually do anything other than maintain the linked list. More importantly, you'll need to save the modules along with the ship whenever you save the ship.
       
Post is unread #3 Jul 2, 2009, 5:23 pm   Last edited Jul 2, 2009, 5:38 pm by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

Well, I think I've found a way to handle stuff so that the installed modules are specific to each individual ship, not global, thanks to the cargo system we already had installed that appeared to handle things on a ship by ship basis already. This method still uses the CREATE macro to allocate the required memory for the module, but uses two functions, which are pretty much slightly edited clones of the LINK and UNLINK macros , to handle installation and uninstallation of the modules. Yay for copy/paste!

As far as saving the module info for the ships I already have an idea of how that's going to work. Haven't written anything as of yet but, using Gendi's modular ships snippet as something of a reference source, which seems to be what all the other SWR's with module systems use actually, I do have a direction I'll be going for this.

Now I'd like some opinions on this system, regarding tractor beams. Specifically, should they be considered another type of laser, or a special module altogether? This has been bothering me for a while.

Also, the hull amount is used to determine how many modules a ship can hold. The thing I'm wondering though, is how much of the hull should be used? I mean, should I, as an example, subtract say, 10% of the hull value, to determine free space? It seems as though I should be taking into account the fact that the frame of the ship, as well as the cockpit, will take up space, which would of course mean there's less room for stuff to be put in.

Any thoughts or suggestions are welcomed.
       
Post is unread #4 Jul 11, 2009, 12:03 am
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

Alright, here's an actual coding question for all you smart people.

Originally when creating a new module I was just using LINK to throw the new one onto the end of the linked list for the ships installed mods. I had also created a function that would be used to sort all the installed modules in the order I wanted them. It's just one big mess of for loop after for loop and I wasn't very happy with it. So after talking with my dad the other night and telling him about it, he suggested using something to insert the new module exactly where I wanted it during creation instead of just throwing it onto the end and having to run that stupid sorting function. So I took a look at the INSERT macro in mud.h and I'd like someone who has more experience than me to take a look at my updated creation function and tell me if it looks good, or what I can do to get it to work better.

MODULE_DATA *new_module( SHIP_DATA *ship, int type )
{
  MODULE_DATA *module = NULL;
  MODULE_DATA *insert = NULL;

  if ( ship == NULL )
  {
    bug( "new_module: null ship passed to function!" );
    return NULL;
  }

  CREATE( module, MODULE_DATA, 1 );

  module->mod_val[0] = type;
  module->mod_val[1] = 0; // condition - 100 = perfect condition
  module->mod_val[2] = 0; // size
  module->mod_val[3] = 1; // state - 1 = in working order but turned off
  module->mod_val[4] = 0; // atype - 0 is default of base system
  module->mod_val[5] = 0; // varies
  module->mod_val[6] = 0; // varies
  module->mod_vnum   = 0; // varies, naturally

  // alright, now comes the fun part. linking the new module into the ships module list
  
  // hmm, is this the first module?
  if ( !ship->first_module )
    LINK( module, ship->first_module, ship->last_module, next, prev ); // yep
  else
  { // guess not..
    insert = ship->first_module;

    do // let's run through this at least once
    {
      if ( insert == ship->first_module && insert->mod_val[MOD_TYPE] > type ) // ok, if we're pointing at the first ship mod,
      {                                                                       // and it's type is greater than what we're installing...
        INSERT( module, insert, ship->first_module, next, prev ); // stick the new mod into the list before the old one
        break;                                                    // and the new one becomes ship->first_module
      }
      
      if ( insert->mod_val[MOD_TYPE] < type ) // is the current mods type less than the one we're installing?
      {
        if ( insert->next == NULL )           // if there's only the one already installed
        {
          LINK( module, ship->first_module, ship->last_module, next, prev ); // just throw the new one onto the end
          break;
        }
        
        if ( insert->next->mod_val[MOD_TYPE] != type ) // ok, there's more than one, but is the next one a different type?
        {
          INSERT( module, insert->next, ship->first_module, next, prev ); // throw it into the list before the next one
          break;
        }
        // if we've gotten this far, then the current mod is the same as the one we're installing,
        // and so is the next. So we'll just let the mod we're pointing at get set the the next in
        // the list of installed mods and let everything run through again, until we hit the end.
      }
      insert = insert->next;
    }while( insert->next != NULL );
  }
  
  // now then, just to make sure that everything was done correctly up above, lets make sure that the list of installed mods is good
  CHECK_LINKS( ship->first_module, ship->last_module, next, prev, MODULE_DATA );
  return module;
}


And this is in the module_install function, which calls new_module.
if ( ( module = new_module( ship, obj->value[MOD_TYPE] ) == NULL ) )
{
  bug( "module_install: could not create new module" );
  return;
}


Well, there you have it. What have I screwed up? :)
       
Post is unread #5 Jul 11, 2009, 12:30 am
Go to the top of the page
Go to the bottom of the page

Banner
Magician
GroupMembers
Posts169
JoinedNov 29, 2005

I'm not sure what you're doing there, but I thought I'd give you a few bits of my module system to show you how it works.

in write_ship:
      fprintf( fp, "Modules      %d\n", ship->modules );
      fprintf( fp, "Maxmodules   %d\n", ship->maxmodules );
      fprintf( fp, "End\n\n" );
      if( ship->first_module )
      {
         for( module = ship->first_module; module; module = module->next )
         {
            fprintf( fp, "#MODULE\n" );                
            fprintf( fp, "Name       %s~\n", module->name );
            fprintf( fp, "Type       %d\n", module->type );
            fprintf( fp, "Modifier   %d\n", module->modifier );
            fprintf( fp, "End\n\n" );
         }
      }
      fprintf( fp, "#END\n" );

   }
   fclose( fp );
   fpReserve = fopen( NULL_FILE, "r" );
   return;
}


load_ship_from_file:
         word = fread_word( fp );
         if( !str_cmp( word, "SHIP" ) )
         {
            fread_ship( ship, fp );
            continue;
         }
         else if( !str_cmp( word, "MODULE" ) )
         {
            fread_module( ship, fp );
            continue;
         }
         else if( !str_cmp( word, "END" ) )
            break;
         else


fread_module:
void fread_module( SHIP_DATA * ship, FILE * fp )
{
   MODULE_DATA *module;
   char buf[MAX_STRING_LENGTH];
   char *word;
   bool fMatch;
   CREATE( module, MODULE_DATA, 1 );
   for( ;; )
   {
      word = feof( fp ) ? "END" : fread_word( fp );
      fMatch = FALSE;

      switch ( UPPER( word[0] ) )
      {
         case '*':
            fread_to_eol( fp );
            fMatch = TRUE;
            break;
         case 'E':
            if( !str_cmp( word, "End" ) )
            {
               if( !module->name )
                  module->name = STRALLOC( "" );

               LINK( module, ship->first_module, ship->last_module, next, prev );
               return;         
            }        
            break;
         case 'M': 
            KEY( "Modifier", module->modifier, fread_number( fp ) );
            break;          
         case 'N':
            KEY( "Name", module->name, fread_string( fp ) );
            break;
         case 'T':                 
            KEY( "Type", module->type, fread_number( fp ) );
            break;
      }
      if( !fMatch )               
      {
         sprintf( buf, "No Match: fread_module: %s", word );
         bug( buf, 0 );                
      }   
   }
}



Function names most likely will not match but you should be able to find them. Not entirely sure what you needed help with but that should get you the gist of it.
       
Post is unread #6 Jul 11, 2009, 12:59 am   Last edited Jul 11, 2009, 1:09 am by Andril
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

I haven't actually gotten around to dealing with the save and load stuff for a ships installed modules yet. I want to get the installing, removing and listing of ones that are installed done and working properly first. But what that code I put in is supposed to do, hopefully, is make it so a ships modules are kept in order as they're installed, so that each type of module is kept together with others of the same type. And so that extension modules are always installed AFTER a base system. But that particular issue is handled elsewhere, because an extension module isn't allowed to be installed without the base system in the first place.

Edit:
And my module system is completely custom. The only snippet I've found for one is Gendi's old one. We actually had that already installed but I didn't really like the fact that it was using affects so I decided to write my own. *shrug*
       
Post is unread #7 Jul 11, 2009, 9:29 am
Go to the top of the page
Go to the bottom of the page

Banner
Magician
GroupMembers
Posts169
JoinedNov 29, 2005


Andril said:



Edit:
And my module system is completely custom. The only snippet I've found for one is Gendi's old one. We actually had that already installed but I didn't really like the fact that it was using affects so I decided to write my own. *shrug*


Obviously, so is mine. It's not using affects either.
       
Post is unread #8 Jul 12, 2009, 2:28 pm
Go to the top of the page
Go to the bottom of the page

Andril
Magician
GroupMembers
Posts147
JoinedJun 9, 2009

If the impression you got from the part of my last post that you quoted was that I was trying to say something bad about your module system I'd like to apologize and say I'm sorry, but that certainly wasn't my intention. Your system, judging from what your saving and loading functions shows, is less complex than mine, at least in certain respects. That's not a bad thing by any means.

And actually, I was more referring to your comment about function names most likely not matching yours in that edit part. But again, I'm sorry if I offended you.
       
Pages:<< prev 1 next >>