Pilot for every ship

Post Reply
clausimu
Posts: 111
Joined: Tue Jan 06, 2015 8:31 pm

Pilot for every ship

Post by clausimu »

Following a short discussion I had with impaktor on IRC - I would like to extend crime tracking to NPC ships. This would enable the police reacting to pirates that target ships within station perimeters. All in all I would like to nudge the game a little further towards independent reactions between ships and away from being player-centered.

That said... One of the problems I am facing is that ships don't have Characters associated with them. It would be best if crime is attached to a (persistent) Character though. Because my coding abilities in C++ are next to nil I am trying to solve this entirely from the lua side and stitch ship objects and Character objects together. I realize that this is a pretty hackish way of doing it. If someone wants to realize this cleanly in C++ I would be more than happy to give the reigns to her/him. I am posting this here because it does change things a bit (more so in the future when things depend on this structure). So if you don't like this direction - please let me know.

The way I would approach it right now would require one new lua file: Pilots.lua.

(In Pseudocode) it would contain the following:

1.

Code: Select all

a central table where ships are associated with characters (pilots[ship] = character)
2.

Code: Select all

createPilot(ship)
char = Character.New()
pilots[ship] = char
return char
3.

Code: Select all

linkPilotShip(ship, char)
pilots[ship] = char
4.

Code: Select all

Code to save the pilots table during serialization, clear it before a player leaves the system, etc. (general "housekeeping" stuff :))
In addition, I would add the following method to Ship.lua:

Code: Select all

Ship:Pilot()
if ship in Pilots.pilot then
pilot = Pilots.pilot[ship]
else
pilot = Pilots.createPilot(self)
end
return pilot
end
Thus, if a ship does not have a pilot and one is required - it gets created and associated automatically. If a script wants a ship to have a certain pilot, it will have to use the "linkPilotShip" function to do so.

If this works out I would then work on extending crime tracking to Characters.
Post Reply