MCPcopy Create free account
hub / github.com/assaultcube/AC / calcentitystats

Function calcentitystats

source/src/tools.cpp:265–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

263
264int lastflagdistancewarning = 0;
265void calcentitystats(entitystats_s &es, const persistent_entity *pents, int pentsize)
266{
267#ifndef STANDALONE
268 vector<persistent_entity> _pents;
269 if(!pents)
270 { // use regular ents list
271 loopv(ents) _pents.add() = ents[i];
272 pentsize = _pents.length();
273 if(pentsize) pents = &_pents[0];
274 }
275#endif
276 memset(&es, 0, sizeof(es));
277 loopi(MAXENTTYPES) es.first[i] = pentsize;
278 vector<int> picks;
279 loopi(pentsize)
280 {
281 const persistent_entity &e = pents[i];
282 if(e.type < MAXENTTYPES)
283 {
284 es.entcnt[e.type]++;
285 if(es.first[e.type] == pentsize) es.first[e.type] = i;
286 es.last[e.type] = i;
287 if(e.type == PLAYERSTART) switch(e.attr2)
288 {
289 case 0: es.spawns[0]++; break;
290 case 1: es.spawns[1]++; break;
291 case 100: es.spawns[2]++; break;
292 default: es.unknownspawns++; break;
293 }
294 if(e.type == CTF_FLAG) switch(e.attr2)
295 {
296 case 0:
297 case 1:
298 es.flags[e.attr2]++;
299 es.flagents[e.attr2] = i;
300 break;
301 default:
302 es.unknownflags++;
303 break;
304 }
305 if(isitem(e.type)) picks.add(i);
306 }
307 }
308 es.hasffaspawns = es.spawns[2] >= MINSPAWNS;
309 es.hasteamspawns = es.spawns[0] >= MINSPAWNS && es.spawns[1] >= MINSPAWNS;
310 if(es.flags[0] == 1 && es.flags[1] == 1)
311 {
312 vec fd(pents[es.flagents[0]].x - pents[es.flagents[1]].x, pents[es.flagents[0]].y - pents[es.flagents[1]].y, 0);
313 es.flagentdistance = fd.magnitude();
314 #ifndef STANDALONE
315 // the clientgame:server calls this too, so we need to check we didn't just warn already.
316 if(es.flagentdistance < MINFLAGDISTANCE && (lastflagdistancewarning==0 || (lastmillis - lastflagdistancewarning) > 1000))
317 {
318 hudoutf("\f2flags \f3too close\f5! \f4[%d<%d]", es.flagentdistance, MINFLAGDISTANCE);
319 lastflagdistancewarning = lastmillis;
320 }
321 #endif // STANDALONE
322 es.hasflags = es.flagentdistance >= MINFLAGDISTANCE;

Callers 4

loadMethod · 0.85
entstats_Function · 0.85
modeinfoFunction · 0.85
load_worldFunction · 0.85

Calls 7

hudoutfFunction · 0.85
gmode_possibleFunction · 0.85
magnitudeMethod · 0.80
loopvFunction · 0.70
loopiFunction · 0.70
addMethod · 0.45
lengthMethod · 0.45

Tested by

no test coverage detected