Okay, you've got a player playing your game, and his name is "MAD_DOG". Let's pretend what the player "MAD_DOG" wants to do, is to upgrade a "bar", to a "tavern". Note, the only diference between a "bar" and a "tavern" is that a "tavern" has 1000 health, instead of the 500 health that a bar has. The health of a building is used in battle, to identify when a building is just broken, and when it's completely demolished.
So, let's identify our tables:
players
building_types
- building_id
building_name
building_health
building_instances
- id
building_id
owner_id
health
In our game, there are many types of buildings, but for the sake of simplicity, we'll only speak of two: bars, and taverns. There are 2 entries into `
building_types`:
Code: Select all
building_id: 11
building_name: bar
building_health: 500
Code: Select all
building_id: 12
building_name: tavern
building_health: 1000
MAD_DOG is a registered player, so there's an entry in `
players`:
Code: Select all
player_id: 430
player_name: MAD_DOG
So he's logged on, going his thing, and he sees an impending battle. He decides he'll need an e-drink afterwards, so he'll want to fortify his bar.
He's upgrading his bar to a tavern.
When he built this bar last november, the table `
building_instances` got a new row:
Code: Select all
id: 1376
building_id: 11
owner_id: 430
health: 300
Okay, so he clicks on his bar, and he game returns the building id of '1376', the id of his bar. He then clicks 'upgrade'. The game has an array of buildings and their upgrades, and magically outputs the upgrade to a bar: the
tavern.
We won't worry about the cost to upgrade right now, so he clicks on 'upgrade', and his bar becomes a tavern. In that time, the following change was done to table `building_instances`:
Code: Select all
id: 1376
building_id: 12
owner_id: 430
health: 1000
What just happened? Well, his bar is still the same building, id 1376 (the 1376th structure created in the whole game), so it's the same building, it's just a different building_type: it's now a number 12.
Referring back to the table `building_types`, an 11 was a bar, and a 12 is now a tavern. Every time someone clicks to see building 1376, they'll now see it's owned by MAD_DOG [user 430], its health is 1000, and it's a building_type 12. A simple SQL query to table `building_types`, and you can convert the number 12 into the type "
tavern", so his bar became a tavern.
I can tell I've accidentally explained it in the most complicated way possible, so someone else can have a go at it too. But if you don't understand anything I just said, try first to understand the database layout, and the difference between a `
building_instance`, and a `
building_type`.