The NPC load/save code works now. After I wrote it, I had a few problems:
1. NPC names were not unique (in order for the game to work, each NPC should have an unique name, from a list of names). So when I added a new NPC, it had, sometimes, an alreadye existing name. The problem was in the code which handled adding new NPCs. it didn't mark the name as used.
2. When the server was shut down, at the next restart the NPCs had no name. This was very frustrating, as some debugging shown that the names were properly saved and loaded, only that for some reason, between the loading the NPCs and the player log in, those names (but not other data) were cleared. I am using Insight (GDB) as a debugger, and, for some reason, it had issues with placing a watch ion the first character of a string. I mean, it did place the watch, but it wasn't hardware, as it took forever to reach the code that cleared those names.
Eventually I gave up, and did a manual step by step execution, which pinpointed the bug: The NPCs were loaded too early. The init code that was supposed to clear all the players/AI/NPCs was fired AFTER the NPCs were loaded.
3. After a restart, the NPCs were moved from their original position. The problem was that I didn't clear the tile under them before saving the map, so when loading the map again, at the start, it shown that those tiles are used by some player/ai/npc.
Now, more about NPCs and their purpose:
The idea is that every city will be self governed by it's players, through their representatives, which will be periodically elected by the players.
The mayor will have some attributions such as approving the buildings (so players won't just put a nuclear power plant right next to a residential area) and various other tasks. However, the bulk of the work will have to be done by the players. the NPCs will serve as 'gateways' between the players and the server.
For example, a merchant NPC will be controlled by the trade advisor, and, if available (a shop is built) it will be able to sell, buy and manufacture things for other players.
A merchant NPC can be configured by the trade advisor to sell/buy/manufacture items only for the citizens of it's city, or for everyone, for the allied cities only, or for everyone but the players from enemy cities.
The trade advisor will also be able to set a list of prices based on the affiliation of a player with the city the NPC belongs to. For example, a merchant NPC can sell items cheaper to it's citizens, and much more expensive to the enemies.