/[james]/t2matchlog/logpositiondata.cs
ViewVC logotype

Annotation of /t2matchlog/logpositiondata.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 45 - (hide annotations) (download)
Sun Dec 21 00:09:21 2003 UTC (21 years ago) by james
File size: 7507 byte(s)
Don't log empty games; log caps and returns.

1 james 36 ////////////////////////////////////////////////////////////////////////////////
2     // logpositiondata.cs
3     ////////////////////////////////////////////////////////////////////////////////
4    
5     // all global variable and functions are prefixed logpos_
6    
7     new fileObject("logpos_file");
8    
9     package t2matchlog {
10    
11     ////////////////////////////////////////////////////////////////////////////////
12    
13     function DefaultGame::startMatch(%game)
14     {
15 james 45 if (ClientGroup.getCount() == 0) {
16     $logpos_wait = true;
17     } else {
18     $logpos_wait = false;
19     logpos_start();
20     }
21    
22     Parent::startMatch(%game);
23     }
24    
25    
26     function logpos_start()
27     {
28 james 36 $logpos_flag_count = 0;
29    
30     %file = "positiondata/" @ $missionSequence @ "_" @ $CurrentMissionType @
31     "_" @ $currentMission @ "_";
32     %i = 0;
33     while (isFile(%file @ %i))
34     %i++;
35     logpos_file.openForWrite(%file @ %i);
36    
37     logpos_file.writeLine($CurrentMission);
38     logpos_file.writeLine($CurrentMissionType);
39     logpos_file.writeLine($MissionDisplayName);
40     logpos_file.writeLine($MissionTypeDisplayName);
41     logpos_file.writeLine(MissionArea.area);
42     logpos_dump_landmarks(MissionGroup);
43     logpos_file.writeLine("");
44    
45     for (%ci = 0; %ci != ClientGroup.getCount(); %ci++) {
46     %client = ClientGroup.getObject(%ci);
47     if (%client.player) {
48     %name = stripChars(detag(getTaggedString(%client.name)),
49     "\cp\co\c6\c7\c8\c9");
50     logpos_file.writeLine("S " @ %client SPC
51     %client.player.team SPC %name);
52     }
53     }
54    
55     $logpos_vehicle_count = 0;
56     $logpos_gameover = false;
57     schedule(1000, 0, logpos_write_position_data);
58     }
59    
60     ////////////////////////////////////////////////////////////////////////////////
61    
62     function DefaultGame::gameOver(%game)
63     {
64 james 45 if ($logpos_wait) {
65     Parent::gameOver(%game);
66     return;
67     }
68    
69 james 36 for (%ci = 0; %ci != ClientGroup.getCount(); %ci++) {
70     %client = ClientGroup.getObject(%ci);
71     logpos_file.writeLine("L " @ %client SPC %client.score);
72     }
73     for (%team = 1; %team <= %game.numTeams; %team++)
74 james 37 logpos_file.writeLine("Z " @ %team SPC $TeamScore[%team] SPC
75     getTaggedString(%game.getTeamName(%team)));
76 james 36 logpos_file.close();
77     $logpos_gameover = true;
78    
79     Parent::gameOver(%game);
80     }
81    
82     ////////////////////////////////////////////////////////////////////////////////
83    
84     function logpos_write_position_data()
85     {
86     if ($logpos_gameover)
87     return;
88    
89     // flags
90     for (%i = 0; %i != $logpos_flag_count; %i++)
91     {
92     %flag = $logpos_flag[%i];
93     if (%flag.carrier $= "")
94     logpos_file.writeLine("F " @ %flag.team SPC %flag.position);
95     else
96     logpos_file.writeLine("F " @ %flag.team SPC %flag.carrier.client);
97     }
98    
99     // players
100     for (%ci = 0; %ci != ClientGroup.getCount(); %ci++)
101     {
102     %client = ClientGroup.getObject(%ci);
103     if (!%client.player)
104     continue;
105     %vehicle = %client.player.getObjectMount();
106     %seat = "";
107     if (%client.player.isPilot()) { %seat = "p"; }
108     if (%client.player.isWeaponOperator()) { %seat = "w"; }
109     %data = %client.player.position SPC %vehicle SPC %seat;
110     logpos_file.writeLine(%client SPC %data);
111     }
112    
113     // vehicles
114     for (%i = 0; %i != $logpos_vehicle_count; %i++) {
115     %vehicle = $logpos_vehicle[%i];
116     if (%vehicle)
117     logpos_file.writeLine(%vehicle SPC %vehicle.position);
118     }
119    
120     // terminate each set of position coordinates with a blank line
121     logpos_file.writeLine("");
122    
123     schedule(1000, 0, logpos_write_position_data);
124     }
125    
126     ////////////////////////////////////////////////////////////////////////////////
127    
128     function logpos_dump_landmarks(%group)
129     {
130     for (%i = 0; %i < %group.getCount(); %i++)
131     {
132     %obj = %group.getObject(%i);
133     %type = %obj.getClassName();
134    
135     if (%type $= "SimGroup")
136     {
137     logpos_dump_landmarks(%obj);
138     }
139     else if (%type $= "Item" && %obj.dataBlock $= "Flag")
140     {
141     $logpos_flag[$logpos_flag_count] = %obj;
142     $logpos_flag_count++;
143     }
144     else if (%obj.team !$= "")
145     {
146     %data = %type SPC %obj.dataBlock SPC %obj.getName();
147     %data = %data SPC %obj.position SPC %obj.name;
148     logpos_file.writeLine(%obj.team SPC %data);
149     }
150     }
151     }
152    
153     ////////////////////////////////////////////////////////////////////////////////
154    
155     function vehicleListAdd(%blockName, %obj)
156     {
157 james 45 if (!$logpos_wait)
158     logpos_file.writeLine("V " @ %obj SPC %obj.team SPC %blockName);
159 james 36 $logpos_vehicle[$logpos_vehicle_count] = %obj;
160     $logpos_vehicle_count++;
161     Parent::vehicleListAdd(%blockName, %obj);
162     }
163    
164     function vehicleListRemove(%data, %obj)
165     {
166 james 45 if (!$logpos_wait)
167     logpos_file.writeLine("W " @ %obj);
168 james 36 for (%i = 0; %i != $logpos_vehicle_count; %i++)
169     if ($logpos_vehicle[%i] == %obj)
170     $logpos_vehicle[%i] = 0;
171     Parent::vehicleListRemove(%data, %obj);
172     }
173    
174     function DefaultGame::playerSpawned(%game, %player)
175     {
176 james 45 if ($logpos_wait) {
177     $logpos_wait = false;
178     logpos_start();
179     } else {
180     %name = stripChars(detag(getTaggedString(%player.client.name)),
181     "\cp\co\c6\c7\c8\c9");
182     logpos_file.writeLine("S " @ %player.client SPC %player.team SPC %name);
183     }
184 james 36 Parent::playerSpawned(%game, %player);
185     }
186    
187     function DefaultGame::onClientKilled(%game, %clVictim, %clKiller, %damageType,
188     %implement, %damageLocation)
189     {
190 james 37 if (%damageType == $DamageType::Impact ||
191     (isObject(%implement) && (%implement.getClassName() $= "Turret" ||
192     %implement.getClassName() $= "VehicleTurret" ||
193     %implement.getClassName() $= "FlyingVehicle")))
194     if (%controller = %implement.getControllingClient())
195     %clKiller = %controller;
196 james 45 if (!$logpos_wait)
197     logpos_file.writeLine("K " @ %clVictim SPC %clKiller SPC %damageType);
198 james 36 Parent::onClientKilled(%game, %clVictim, %clKiller, %damageType,
199     %implement, %damageLocation);
200     }
201    
202     function DefaultGame::onClientDamaged(%game, %clVictim, %clAttacker,
203     %damageType, %sourceObject)
204     {
205 james 45 if (!$logpos_wait)
206     logpos_file.writeLine("D " @ %clVictim SPC %clAttacker SPC %damageType);
207 james 36 Parent::onClientDamaged(%game, %clVictim, %clAttacker, %damageType,
208     %sourceObject);
209     }
210    
211     function DefaultGame::onClientLeaveGame(%game, %client)
212     {
213 james 45 if (!$logpos_wait)
214     logpos_file.writeLine("L " @ %client SPC %client.score);
215 james 36 Parent::onClientLeaveGame(%game, %client);
216     }
217    
218     function Player::setArmor(%this, %size)
219     {
220 james 45 if (!$logpos_wait)
221     logpos_file.writeLine("A " @ %this.client SPC %size);
222 james 36 Parent::setArmor(%this, %size);
223     }
224    
225     function ShapeBase::setInventory(%this, %data, %value, %force)
226     {
227 james 45 if (!$logpos_wait)
228     logpos_file.writeLine("I " @ %this.client SPC %data.getName() SPC %value);
229 james 36 Parent::setInventory(%this, %data, %value, %force);
230     }
231    
232     function AIDeployObject(%client, %object)
233     {
234 james 45 if (!$logpos_wait)
235     logpos_file.writeLine("O " @ %object SPC %client SPC
236     %object.getDataBlock().getName() SPC %object.position);
237 james 36 Parent::AIDeployObject(%client, %object);
238     }
239    
240     function ShapeBaseData::onDestroyed(%data, %obj, %prevstate)
241     {
242 james 45 if (!$logpos_wait)
243     logpos_file.writeLine("P " @ %obj SPC %obj.lastDamagedBy);
244 james 36 Parent::onDestroyed(%data, %obj, %prevstate);
245     }
246    
247 james 45 function CTFGame::flagCap(%game, %player)
248     {
249     if (!$logpos_wait)
250     logpos_file.writeLine("C " @ %player.holdingFlag.team SPC %player.client);
251     Parent::flagCap(%game, %player);
252     }
253    
254     function CTFGame::flagReturn(%game, %flag, %player)
255     {
256     if (!$logpos_wait)
257     logpos_file.writeLine("R " @ %flag.team SPC %player.client);
258     Parent::flagReturn(%game, %flag, %player);
259     }
260    
261 james 36 };
262    
263     activatePackage(t2matchlog);
264    
265     ////////////////////////////////////////////////////////////////////////////////
266    

  ViewVC Help
Powered by ViewVC 1.1.26