IMPORTANT: Test all the map algorithms and systems on my local WAMP installation, before putting it on the server. Should be much faster and easier. (I don't need to start an online game again every time.)
Server (game creation) stuff
The server needs to:
Determine the islands and save them (indexed array). (Using my recursive algorithm)
Leave a property that checks if the island has been "discovered", and one that saves the title someone gives the island.
Give each island a single dock/harbor. (Pick random tile on the edge.) Save this dock based on position, so it's easy to check if a dock is within range or within sight.
Leave properties for the dock's current DEAL, its SIZE (based on island size), and its REPUTATION
Place all "player ships" at a random position in the water, at least X distance from all other ships.
Collect all submitted monsters. Spawn them all over the map, as long as they're in (deep) water.
Create AI ships. Pre-determine routes between harbors, based on their size. Spawn each ship next to a harbor.
Client (game displaying) stuff
Then it needs to send this information to the clients:
Send the ship and monster images to the cartographers. (When their map level allows, they will start receiving dock and monster position and all that.)
Monitors get everything at the start: ship drawings + flags, individual player avatars, docks, monsters, AI ships.
Then, at new turns, they just get the updated position of each unit.
Important optimization!
During the game, we will be searching through tiles A LOT. (Checking if they are within viewing range, checking if the bullet hit them, etc.)
It would be very expensive (server-side) to search through all those lists time and time again.
Example: Want to know if we hit a monster on tile A? Well, check all monsters. No hit; the cannonball flies to tile B. Well ... we need to check all the monsters again! Doing this for all tiles within range, for every cannonball, for each ship, etc. is very expensive.)
Instead! There is a (slightly larger) map variable on the server. This doesn't just save the current value of the tile (sea or island), but also any units (or special things) that are on this tile.
At the end of turn, when everything moves, we update their own object AND we update this map. This costs a little extra at that moment, but saves many operations in the long run.
Example (again): Want to know if we hit something on tile A? Fetch the tile, see if there are more than 0 units on the tile. Simple! We go to tile B, perform the same quick operation.
(As an extra optimization, all tiles where there are NO units/specialties, can just reduce back to their number. To check if we hit something, we just check if this tile's value is a number or not. If so, we don't hit anything. If not, the tile's value is an object, and we can "damage" everything within that object.)
Another important note: We don't actually need to save what's there. We just need to save the index/id of the "thing" that is on the tile. Once we know that, we can look up the information in the corresponding list. (You hit monster number 3? Let me check my monsters Array at position 3.)
IMPORTANT: Test all the map algorithms and systems on my local WAMP installation, before putting it on the server. Should be much faster and easier. (I don't need to start an online game again every time.)
Server (game creation) stuff
The server needs to:
Client (game displaying) stuff
Then it needs to send this information to the clients:
Important optimization!
During the game, we will be searching through tiles A LOT. (Checking if they are within viewing range, checking if the bullet hit them, etc.)
It would be very expensive (server-side) to search through all those lists time and time again.
Example: Want to know if we hit a monster on tile A? Well, check all monsters. No hit; the cannonball flies to tile B. Well ... we need to check all the monsters again! Doing this for all tiles within range, for every cannonball, for each ship, etc. is very expensive.)
Instead! There is a (slightly larger) map variable on the server. This doesn't just save the current value of the tile (sea or island), but also any units (or special things) that are on this tile.
At the end of turn, when everything moves, we update their own object AND we update this map. This costs a little extra at that moment, but saves many operations in the long run.
Example (again): Want to know if we hit something on tile A? Fetch the tile, see if there are more than 0 units on the tile. Simple! We go to tile B, perform the same quick operation.
(As an extra optimization, all tiles where there are NO units/specialties, can just reduce back to their number. To check if we hit something, we just check if this tile's value is a number or not. If so, we don't hit anything. If not, the tile's value is an object, and we can "damage" everything within that object.)
Another important note: We don't actually need to save what's there. We just need to save the index/id of the "thing" that is on the tile. Once we know that, we can look up the information in the corresponding list. (You hit monster number 3? Let me check my monsters Array at position 3.)