Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
2 | |
3 | Ship = {} |
4 | |
5 | local Ship_mt = Class(Ship); |
6 | |
7 | function Ship:onCreate(id) |
8 | g_currentMission:addUpdateable(Ship:new(id)); |
9 | --print("created ship, id: ", id); |
10 | end; |
11 | |
12 | function Ship:new(id) |
13 | local instance = {}; |
14 | setmetatable(instance, Ship_mt); |
15 | |
16 | instance.nurbsId = getChildAt(id, 0); |
17 | instance.shipIds = {}; |
18 | table.insert(instance.shipIds, getChildAt(id, 1)); |
19 | instance.times = {}; |
20 | table.insert(instance.times, 0); |
21 | |
22 | local length = getSplineLength(instance.nurbsId); |
23 | instance.timeScale = (Utils.getNoNil(getUserAttribute(id, "speed"), 10)/3.6); |
24 | local numShips = Utils.getNoNil(getUserAttribute(id, "numShips"), 1); |
25 | |
26 | for i=2,numShips do |
27 | local shipId = clone(instance.shipIds[1], false, true); |
28 | link(id, shipId); |
29 | table.insert(instance.shipIds, shipId); |
30 | table.insert(instance.times, (1/numShips)*(i-1)); |
31 | end; |
32 | |
33 | |
34 | if length ~= 0 then |
35 | instance.timeScale = instance.timeScale/length; |
36 | end; |
37 | |
38 | instance.initCount = 0; |
39 | |
40 | return instance; |
41 | end; |
42 | |
43 | function Ship:delete() |
44 | |
45 | end; |
46 | |
47 | function Ship:update(dt) |
48 | |
49 | -- Avoid depth buffer of the water shader (initial one frame delay) |
50 | if self.initCount > 0 then |
51 | |
52 | for i=1, table.getn(self.shipIds) do |
53 | self.times[i] = self.times[i] - 0.001*dt*self.timeScale; |
54 | local x,y,z = getSplinePosition(self.nurbsId, self.times[i]); |
55 | local rx,ry,rz = getSplineOrientation(self.nurbsId, self.times[i], 0, -1, 0); |
56 | setTranslation(self.shipIds[i], x, y, z); |
57 | setRotation(self.shipIds[i], rx, ry, rz); |
58 | |
59 | end; |
60 | else |
61 | self.initCount = self.initCount + 1; |
62 | end; |
63 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de