Thread: organizing data

  1. #1
    Unregistered
    Guest

    organizing data

    No code to post... just looking for some ideas. Here's the situation. I have a linked list full of "settlements". Each settlement is of a certain type (village, town, or city). You can build certain structures in the various settlements, and some structures are unique to certain settlement types. For example, you can build a market in a village, town, or city. You can build a port in a town or city (but not a village), and you can build a wall in a city (but not a village or town).

    During the CreateBuilding function, I want a simple test to determine if a building/structure is allowed to be built, based upon the type of settlement. I can think of some ugly ways to do this, but is there a pretty way?

    Code:
    Here's how I keep the data:
    class Structure {     
     private:
    // parallel arrays to keep track of the settlement's structures
       bool structure_status[MAX_NUM_BUILDINGS];  // 0 = does not exist, 1 = exists
       int structural_integrity[MAX_NUM_BUILDINGS];
       ...
    };

  2. #2
    Used Registerer jdinger's Avatar
    Join Date
    Feb 2002
    Posts
    1,065
    What if you enumerated the possible settlement/building types?

    Then just check against them, ie:

    Code:
    //pseudo..
    
    enum Bldg
    {
        Wall, 
        Port,
        Market,
    } NewBldgType;
    
    if(Settlement1==0)  //for instance 0 = village
    {
       switch(NewBldgType)
        {
         case 0:    //wall
         case 1:   //port
             //not ok
            break;
          case 2:
            //ok, build it
            break;
                       
         }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  2. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  3. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  4. Binary Tree, couple questions
    By scoobasean in forum C Programming
    Replies: 3
    Last Post: 03-12-2005, 09:09 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM