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

Function newentity

source/src/world.cpp:370–430  ·  view source on GitHub ↗

so copyent/pasteent can keep all attributes

Source from the content-addressed store, hash-verified

368
369VAR(_nextentityispasted,0,0,1);// so copyent/pasteent can keep all attributes
370void newentity(int index, int x, int y, int z, const char *what, float v1f, float v2f, float v3f, float v4f, float v5f, float v6f, float v7f) // add an entity or overwrite an existing one
371{
372 int type = findtype(what);
373 if(type == NOTUSED) return;
374 if (index >= 0 && ents[index].type == SOUND) deletesoundentity(ents[index]); // overwriting sound entity
375 if(_nextentityispasted)
376 {
377 _nextentityispasted = 0;
378 }
379 else
380 {
381 switch(type)
382 { // MAPMODEL, PLAYERSTART and CTF-FLAG use the current camera direction as value for attr1, so attr23456 need to be moved
383 case MAPMODEL:
384 v6f = v5f;
385 v5f = v4f;
386 v4f = v3f;
387 v3f = v2f;
388 case PLAYERSTART:
389 case CTF_FLAG:
390 v2f = v1f;
391 int y = camera1->yaw;
392 if(type != PLAYERSTART) y = y + 7 - (y + 7) % 15;
393 v1f = y;
394 break;
395 }
396 }
397
398 int v1 = v1f * entscale[type][0], v2 = v2f * entscale[type][1], v3 = v3f * entscale[type][2], v4 = v4f * entscale[type][3], v5 = v5f * entscale[type][4], v6 = v6f * entscale[type][5], v7 = v7f * entscale[type][6];
399 entity e(x, y, z, type, v1, v2, v3, v4, v5, v6, v7);
400
401 switch(type)
402 {
403 case LIGHT:
404 if(v1 > 64) e.attr1 = 64;
405 if(!v1) e.attr1 = 16;
406 if(!v2 && !v3 && !v4) e.attr2 = 255;
407 break;
408 }
409 clampentityattributes(e);
410 syncentchanges(true);
411 addmsg(SV_EDITENT, "ri9i3", index<0 ? ents.length() : index, type, e.x, e.y, e.z, e.attr1, e.attr2, e.attr3, e.attr4, e.attr5, e.attr6, e.attr7);
412 e.spawned = true;
413 int oldtype = type;
414 if(index<0) ents.add(e);
415 else
416 {
417 oldtype = ents[index].type;
418 ents[index] = e;
419 }
420 if(oldtype!=type) switch(oldtype)
421 {
422 case LIGHT: calclight(); break;
423 }
424 switch(type)
425 {
426 case LIGHT: calclight(); break;
427 case SOUND: audiomgr.preloadmapsound(e); break;

Callers 3

undelentFunction · 0.85
entsetFunction · 0.85
newentFunction · 0.85

Calls 9

findtypeFunction · 0.85
deletesoundentityFunction · 0.85
clampentityattributesFunction · 0.85
syncentchangesFunction · 0.85
addmsgFunction · 0.85
calclightFunction · 0.85
preloadmapsoundMethod · 0.80
lengthMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected