   New project need mental help.
  Hi. The mental help section is at the bottom.My other project began in the 'middle of programming'. It was a refresher and a tester project. I got it up and running and everything. Of course being in the middle there where several complications. Truth be told I am disappointed with the outcome; Now I have a better understanding, on animations, AI, loading, and how to handle collisions so I guess it's not a complete waste.Well I'm creating another project. In a recent post I said something about a 4 Quadrant Grid and each area of the grid being a Nobe. That brought several plans and pretty soon I had a pretty decent architecture planned out. My idea is to create... well the PC game Tropico but 2D(yellow blocks will be used) and scaled down by a thousand.What I plan to learn/accomplish:1. AI(movement & actions, AI response)---Movement & Actions, I need a better Queue System then what I have now---AI response, So far I just plan to have them work and sleep.2. Grid collision & path finding---I'm going to use a '3 layered' grid(Large 4x4, Medium 2x2, Small 1x1)---I have looked up A* and probably should need help on this(notice the should)---I plan on cutting there paths down to 'sections' if the distance is too great3. Create UI---Build Buttons, Details on selected object, Details of: happiness, housing, income4. Create Management---See belowMemory/Object ManagementI hate hard coding people(sprite) details so I want to 'randomize' a few details of the objects.I want all the people to be made from one object(each doing above) and added to a vector list. The list is use to handle object events, thinking, and rendering. I do plan to add children to the 'game' they will also need to be added to the list when they are created.Mental Help:1. Creatinga. Would I create and add the objects to the list as such:std::vector<void*> List;List.push_back(new Object);b. How would I delete certain ones(the dead ones) from the list and from memory? <-- Main Questionc. Would adding the Object like this call the constructor? <-- I think yes2. Saving And Loadinga. How would I save all the Object details to a single file using this list?b. How would I set the details to the object?[Edited by - rpg gamer 17 on October 6, 2009 5:37:07 PM]
  You need mental help?! ;) Just nitpicking, but your name actually expands out as "role playing game gamer 17". :PQuote:Original post by rpg gamer 17Mental Help:1. Creatinga. Would I create and add the objects to the list as such:std::vector<void*> List;List.push_back(new Object);Would you? Sure. There are numerous ways to handle object management and a list is a fine way of doing it. But I recommend using a base class (say, IObject) from which you derive all other objects on the list. (std::vector<IObject *> objectList) This way you can add standard functionality which, through polymorphism, will process differently for each derived class. Then, when looping through your list, you'd just have to call something like myObject->Render(), without using any casts.Quote:b. How would I delete certain ones(the dead ones) from the list and from memory? <-- Main QuestionAlso numerous ways of doing it. A safe way is for your base class to store a bool which flags the object for deletion. Then, while in your process loop, you check for the flag being true on each object and delete it and erase it from the list.Quote:c. Would adding the Object like this call the constructor? <-- I think yesConstructors are called whenever you create an object on the stack (normal variable definitions) or the heap (dynamic definitions i.e. new). So yes.Quote:2. Saving And Loadinga. How would I save all the Object details to a single file using this list?Look up fstream. You can write any data you want to a file, so simply organise the data you need in the manner you want and write it to file.Quote:b. How would I set the details to the object?Well, you could use different functions. You can set object variables using a parameterised constructor, or using an Init(...) function, or using individual accessor functions like SetPosition(float x, float y). That's quite straightforward. Did you have anything else in mind?   ;  rp gamer 17 didn't sound right. I say each letter of an abreviated word and not the word that it means.2.a.I plan to save the grid information(buildings, plants), and people to a single file. I was mainly complaining about the complexity of doing such a thing. After a little more planning I though of how I could convert my 'flag based' loading system into a loading system. I'll set flags at the beginning and end of the objects loading process. I use to 'flag' each detail of the object but since I won't be creating the files myself. I'll save and load the details in a set order.b.I was thinking about question 1.c when I asked it. Now that I know constructers will be called, I can create the object with loaded parameters and add it to the list.I'm not finished with this yetEDIT:Okay finally at my house.1.a.Polymorphism that's what I need. I'm going to have 3 main functions for each class. It's the basic Handle, Process, Render. I was just going to jam a void* full of objects; Throw a bunch of errors until I get the needed object type(try, throw, catch, repeat). I've never messed with polymorphism before. Thanks for the link!b.for(ListIt = List.begin(); ListIt != List.end(); ListIt++){if(dead) {delete *ListIt;List.erase(ListIt);}}Right?It doesn't throw any errors when I compile so I'm thinking yes.c.Yay! This makes my job alot easier.Thanks![Edited by - rpg gamer 17 on October 7, 2009 3:53:03 PM]