Login
User Name:

Password:



Register
Forgot your password?
Vote for Us!
tintin++ ogg sound player script for linux
Author: Robert Smith
Submitted by: Vladaar
6Dragons ogg Soundpack
Author: Vladaar
Submitted by: Vladaar
6Dragons 4.4
Author: Vladaar
Submitted by: Vladaar
LoP 1.46
Author: Remcon
Submitted by: Remcon
LOP 1.45
Author: Remcon
Submitted by: Remcon
Users Online
CommonCrawl, Yandex, Vladaar

Members: 1
Guests: 4
Stats
Files
Topics
Posts
Members
Newest Member
481
3,735
19,369
618
Micheal64X
Today's Birthdays
There are no member birthdays today.
Related Links
» SmaugMuds.org » General » Coding » Logic questions
Forum Rules | Mark all | Recent Posts

Logic questions
< Newer Topic :: Older Topic > Need second opinion

Pages:<< prev 1 next >>
* #1 Sep 1, 2011, 3:55 am   Last edited Sep 1, 2011, 4:26 am by Aurin
Go to the top of the page
Go to the bottom of the page

Aurin
Magician
GroupMembers
Posts189
JoinedSep 5, 2010

/* This is used to update the city positions if one becomes empty */
void fix_city_order(CITY_DATA * city)
{
  char                    buf[MSL];
  bool                    cont = FALSE; // Added to allow closing out of function if needed - Aurin

  if(!city)
    return;

	// Is there a duke?
  if(!VLD_STR(city->duke))
  {
  // No. Let's free the string data for duke. Why? Seems redundant if it doesn't exist in the first place.
    if(city->duke)
      STRFREE(city->duke);
	  // Is there a baron?
    if(VLD_STR(city->baron))
    {
	// Yes, let's make him duke.
      city->duke = STRALLOC(city->baron);
      city->baron = NULL;
      snprintf(buf, MIL, "&W[&RAnnouncement&W]&C %s has been awarded the position of Duke for %s!", city->duke, city->name);
      echo_to_all(AT_RED, buf, ECHOTAR_ALL);
	  cont = TRUE;
    }
	// No baron. Is there a Captain?
    else if(VLD_STR(city->captain))
    {
	  // Yes, let's make HIM duke.
      city->duke = STRALLOC(city->captain);
      city->captain = NULL;
      snprintf(buf, MIL, "&W[&RAnnouncement&W]&C %s has been awarded the position of Duke for %s!", city->duke, city->name);
      echo_to_all(AT_RED, buf, ECHOTAR_ALL);
	  cont = TRUE;
    }
	// No Captain. Is there a Sheriff?
    else if(VLD_STR(city->sheriff))
    {
	  // Yes, let's make HIM Duke.
      city->duke = STRALLOC(city->sheriff);
      city->sheriff = NULL;
      snprintf(buf, MIL, "&W[&RAnnouncement&W]&C %s has been awarded the position of Duke for %s!", city->duke, city->name);
      echo_to_all(AT_RED, buf, ECHOTAR_ALL);
	  cont = TRUE;
    }
	// No Sheriff.  Is there a Knight?
    else if(VLD_STR(city->knight))
    {
	  // Yes, let's make HIM Duke.
      city->duke = STRALLOC(city->knight);
      STRFREE(city->knight);
      snprintf(buf, MIL, "&W[&RAnnouncement&W]&C %s has been awarded the position of Duke for %s!", city->duke, city->name);
      echo_to_all(AT_RED, buf, ECHOTAR_ALL);
      cont = TRUE;
    }
	// No Knight.  If we made it this far with a no to everything, why continue with the function, as nothing was changed? Added below ifcheck.
	if(!cont)
	  return;
  }

Okay, so, no comments existed in the above bit of code, I commented that with what I understood it to mean. Am I correct in making the assumptions I've made in the comments? I had no part in the creation of this code, or had any hand in the implementation of it. I'm now going through and trying to streamline things a bit, as well as fix errors/bugs within the code that pop up, as well as expand things. 98% of it, of course, is not commented so that I have no clue what was intended (sucks to be me *LOL*). The function goes on and has a replica of the above portion for each of the other positions, less the previous position checked.

Also, returning out of the function a good idea or not? I honestly don't see a reason to let it continue if it returns a "false" all the way through the else if's, but not really sure it's worth updating the rest if it doesn't matter.

Anywhoo, starting to ramble, so I'll await comments. :)

Cheers,
Aurin
       
Pages:<< prev 1 next >>