| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
#include "objs.h" |
| 50 |
|
| 51 |
#include <assert.h> |
| 52 |
|
| 53 |
#include "bullet_class.h" |
| 54 |
#include "damage.h" |
| 55 |
#include "gamedata.h" |
| 56 |
#include "log.h" |
| 57 |
#include "net_util.h" |
| 58 |
#include "pickup.h" |
| 59 |
|
| 60 |
CArray gObjs; |
| 61 |
CArray gMobObjs; |
| 62 |
static unsigned int sObjUIDs = 0; |
| 63 |
static unsigned int sMobObjUIDs = 0; |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
static void MapObjectDraw( |
| 68 |
GraphicsDevice *g, const int id, const struct vec2i pos) |
| 69 |
{ |
| 70 |
const TObject *obj = CArrayGet(&gObjs, id); |
| 71 |
CASSERT(obj->isInUse, "Cannot draw non-existent map object"); |
| 72 |
CPicDrawContext c = CPicDrawContextNew(); |
| 73 |
c.Offset = obj->Class->Offset; |
| 74 |
CPicDraw(g, &obj->thing.CPic, pos, &c); |
| 75 |
} |
| 76 |
|
| 77 |
#define NUM_SPALL_PARTICLES 3 |
| 78 |
#define SPALL_IMPULSE_FACTOR 1.0f |
| 79 |
void DamageObject(const NThingDamage d) |
| 80 |
{ |
| 81 |
TObject *o = ObjGetByUID(d.UID); |
| 82 |
|
| 83 |
if (o->Health <= 0) |
| 84 |
{ |
| 85 |
return; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
Emitter em; |
| 90 |
EmitterInit(&em, NULL, svec2_zero(), -0.5f, 0.5f, 1, 4, 0, 0, 0); |
| 91 |
AddParticle ap; |
| 92 |
memset(&ap, 0, sizeof ap); |
| 93 |
ap.Pos = o->thing.Pos; |
| 94 |
ap.Angle = NAN; |
| 95 |
ap.Z = 10; |
| 96 |
ap.Vel = |
| 97 |
svec2_scale(svec2_normalize(NetToVec2(d.Vel)), SPALL_IMPULSE_FACTOR); |
| 98 |
|
| 99 |
for (int i = 0; i < MIN(o->Health, d.Power); i++) |
| 100 |
{ |
| 101 |
char buf[256]; |
| 102 |
sprintf(buf, "spall%d", rand() % NUM_SPALL_PARTICLES + 1); |
| 103 |
ap.Class = StrParticleClass(&gParticleClasses, buf); |
| 104 |
|
| 105 |
ap.Mask = PicGetRandomColor(CPicGetPic(&o->Class->Pic, 0)); |
| 106 |
EmitterStart(&em, &ap); |
| 107 |
} |
| 108 |
|
| 109 |
o->Health -= d.Power; |
| 110 |
|
| 111 |
|
| 112 |
if (o->Health <= 0) |
| 113 |
{ |
| 114 |
if (!gCampaign.IsClient) |
| 115 |
{ |
| 116 |
GameEvent e = GameEventNew(GAME_EVENT_MAP_OBJECT_REMOVE); |
| 117 |
e.u.MapObjectRemove.UID = o->uid; |
| 118 |
e.u.MapObjectRemove.ActorUID = d.SourceActorUID; |
| 119 |
e.u.MapObjectRemove.Flags = d.Flags; |
| 120 |
GameEventsEnqueue(&gGameEvents, e); |
| 121 |
} |
| 122 |
|
| 123 |
|
| 124 |
EmitterInit(&em, NULL, svec2_zero(), -1.0f, 1.0f, 1, 16, 0, 0, 0); |
| 125 |
ap.Vel = svec2_scale(ap.Vel, 0.5f); |
| 126 |
for (int i = 0; i < 20; i++) |
| 127 |
{ |
| 128 |
char buf[256]; |
| 129 |
sprintf(buf, "spall%d", rand() % NUM_SPALL_PARTICLES + 1); |
| 130 |
ap.Class = StrParticleClass(&gParticleClasses, buf); |
| 131 |
|
| 132 |
ap.Mask = PicGetRandomColor(CPicGetPic(&o->Class->Pic, 0)); |
| 133 |
EmitterStart(&em, &ap); |
| 134 |
} |
| 135 |
} |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
const TActor *source = ActorGetByUID(d.SourceActorUID); |
| 140 |
const int playerUID = source != NULL ? source->PlayerUID : -1; |
| 141 |
if (!gCampaign.IsClient && playerUID >= 0 && |
| 142 |
strlen(d.SourceWeaponClassName) > 0) |
| 143 |
{ |
| 144 |
PlayerData *p = PlayerDataGetByUID(playerUID); |
| 145 |
const WeaponClass *wc = StrWeaponClass(d.SourceWeaponClassName); |
| 146 |
WeaponUsagesUpdate(p->WeaponUsages, wc, 0, 1); |
| 147 |
} |
| 148 |
} |
| 149 |
|
| 150 |
static void AddPickupAtObject(const TObject *o, const PickupType type) |
| 151 |
{ |
| 152 |
GameEvent e = GameEventNew(GAME_EVENT_ADD_PICKUP); |
| 153 |
switch (type) |
| 154 |
{ |
| 155 |
case PICKUP_HEALTH: |
| 156 |
if (!ConfigGetBool(&gConfig, "Game.HealthPickups")) |
| 157 |
{ |
| 158 |
return; |
| 159 |
} |
| 160 |
strcpy(e.u.AddPickup.PickupClass, "health"); |
| 161 |
break; |
| 162 |
case PICKUP_AMMO: |
| 163 |
if (!gCampaign.Setting.Ammo) |
| 164 |
{ |
| 165 |
return; |
| 166 |
} |
| 167 |
|
| 168 |
{ |
| 169 |
const int ammoId = rand() % AmmoGetNumClasses(&gAmmo); |
| 170 |
const Ammo *a = AmmoGetById(&gAmmo, ammoId); |
| 171 |
sprintf(e.u.AddPickup.PickupClass, "ammo_%s", a->Name); |
| 172 |
} |
| 173 |
break; |
| 174 |
case PICKUP_GUN: |
| 175 |
|
| 176 |
{ |
| 177 |
const int gunId = (int)(rand() % gMission.Weapons.size); |
| 178 |
const WeaponClass **wc = CArrayGet(&gMission.Weapons, gunId); |
| 179 |
sprintf(e.u.AddPickup.PickupClass, "gun_%s", (*wc)->name); |
| 180 |
} |
| 181 |
break; |
| 182 |
default: |
| 183 |
CASSERT(false, "unexpected pickup type"); |
| 184 |
break; |
| 185 |
} |
| 186 |
e.u.AddPickup.Pos = Vec2ToNet(o->thing.Pos); |
| 187 |
e.u.AddPickup.IsRandomSpawned = true; |
| 188 |
GameEventsEnqueue(&gGameEvents, e); |
| 189 |
} |
| 190 |
|
| 191 |
static void PlaceWreck(const char *wreckClass, const Thing *ti); |
| 192 |
void ObjRemove(const NMapObjectRemove mor) |
| 193 |
{ |
| 194 |
TObject *o = ObjGetByUID(mor.UID); |
| 195 |
o->Health = 0; |
| 196 |
|
| 197 |
if (!gCampaign.IsClient) |
| 198 |
{ |
| 199 |
|
| 200 |
UpdateMissionObjective( |
| 201 |
&gMission, o->thing.flags, OBJECTIVE_DESTROY, 1); |
| 202 |
const TActor *a = ActorGetByUID(mor.ActorUID); |
| 203 |
const int playerUID = a != NULL ? a->PlayerUID : -1; |
| 204 |
|
| 205 |
if ((o->thing.flags & THING_OBJECTIVE) && playerUID >= 0) |
| 206 |
{ |
| 207 |
GameEvent e = GameEventNew(GAME_EVENT_SCORE); |
| 208 |
e.u.Score.PlayerUID = playerUID; |
| 209 |
e.u.Score.Score = OBJECT_SCORE; |
| 210 |
GameEventsEnqueue(&gGameEvents, e); |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
CA_FOREACH(const WeaponClass *, wc, o->Class->DestroyGuns) |
| 215 |
CASSERT((*wc)->Type != GUNTYPE_MULTI, "unexpected gun type"); |
| 216 |
WeaponClassFire( |
| 217 |
*wc, o->thing.Pos, 0, 0, mor.Flags, mor.ActorUID, true, false); |
| 218 |
CA_FOREACH_END() |
| 219 |
|
| 220 |
|
| 221 |
if (!IsPVP(gCampaign.Entry.Mode)) |
| 222 |
{ |
| 223 |
CA_FOREACH( |
| 224 |
const MapObjectDestroySpawn, mods, o->Class->DestroySpawn) |
| 225 |
const double chance = (double)rand() / RAND_MAX; |
| 226 |
if (chance < mods->SpawnChance) |
| 227 |
{ |
| 228 |
AddPickupAtObject(o, mods->Type); |
| 229 |
} |
| 230 |
CA_FOREACH_END() |
| 231 |
} |
| 232 |
|
| 233 |
if (strlen(o->Class->Wreck.Bullet) > 0) |
| 234 |
{ |
| 235 |
|
| 236 |
GameEvent e = GameEventNew(GAME_EVENT_ADD_BULLET); |
| 237 |
e.u.AddBullet.UID = MobObjsObjsGetNextUID(); |
| 238 |
strcpy(e.u.AddBullet.BulletClass, o->Class->Wreck.Bullet); |
| 239 |
e.u.AddBullet.MuzzlePos = Vec2ToNet(o->thing.Pos); |
| 240 |
GameEventsEnqueue(&gGameEvents, e); |
| 241 |
} |
| 242 |
} |
| 243 |
|
| 244 |
SoundPlayAt(&gSoundDevice, o->Class->Wreck.Sound, o->thing.Pos); |
| 245 |
|
| 246 |
|
| 247 |
PlaceWreck(o->Class->Wreck.MO, &o->thing); |
| 248 |
|
| 249 |
ObjDestroy(o); |
| 250 |
|
| 251 |
if (o->thing.flags & THING_IMPASSABLE) |
| 252 |
{ |
| 253 |
|
| 254 |
PathCacheClear(&gPathCache); |
| 255 |
} |
| 256 |
} |
| 257 |
static void PlaceWreck(const char *wreckClass, const Thing *ti) |
| 258 |
{ |
| 259 |
if (wreckClass == NULL) |
| 260 |
{ |
| 261 |
return; |
| 262 |
} |
| 263 |
GameEvent e = GameEventNew(GAME_EVENT_MAP_OBJECT_ADD); |
| 264 |
e.u.MapObjectAdd.UID = ObjsGetNextUID(); |
| 265 |
const MapObject *mo = StrMapObject(wreckClass); |
| 266 |
CASSERT(mo != NULL, "cannot find wreck"); |
| 267 |
if (mo == NULL) |
| 268 |
{ |
| 269 |
LOG(LM_MAIN, LL_ERROR, "wreck (%s) not found", wreckClass); |
| 270 |
return; |
| 271 |
} |
| 272 |
strcpy(e.u.MapObjectAdd.MapObjectClass, mo->Name); |
| 273 |
e.u.MapObjectAdd.Pos = Vec2ToNet(ti->Pos); |
| 274 |
e.u.MapObjectAdd.ThingFlags = MapObjectGetFlags(mo); |
| 275 |
e.u.MapObjectAdd.Health = mo->Health; |
| 276 |
GameEventsEnqueue(&gGameEvents, e); |
| 277 |
} |
| 278 |
|
| 279 |
bool CanHit( |
| 280 |
const BulletClass *b, const int flags, const int uid, const Thing *target) |
| 281 |
{ |
| 282 |
switch (target->kind) |
| 283 |
{ |
| 284 |
case KIND_CHARACTER: |
| 285 |
return b->Hit.Flesh.Hit && |
| 286 |
CanHitCharacter(flags, uid, CArrayGet(&gActors, target->id)); |
| 287 |
case KIND_OBJECT: |
| 288 |
return b->Hit.Object.Hit; |
| 289 |
default: |
| 290 |
CASSERT(false, "cannot damage tile item kind"); |
| 291 |
break; |
| 292 |
} |
| 293 |
return false; |
| 294 |
} |
| 295 |
bool HasHitSound( |
| 296 |
const ThingKind targetKind, const int targetUID, |
| 297 |
const special_damage_e special, const bool allowFriendlyHitSound) |
| 298 |
{ |
| 299 |
switch (targetKind) |
| 300 |
{ |
| 301 |
case KIND_CHARACTER: { |
| 302 |
const TActor *a = ActorGetByUID(targetUID); |
| 303 |
return allowFriendlyHitSound || ActorTakesDamage(a, special); |
| 304 |
} |
| 305 |
case KIND_OBJECT: |
| 306 |
return true; |
| 307 |
default: |
| 308 |
CASSERT(false, "cannot damage tile item kind"); |
| 309 |
break; |
| 310 |
} |
| 311 |
return false; |
| 312 |
} |
| 313 |
|
| 314 |
static void DoDamageThing( |
| 315 |
const ThingKind targetKind, const int targetUID, const TActor *source, |
| 316 |
const int flags, const BulletClass *bullet, const WeaponClass *weapon, |
| 317 |
const bool canDamage, const struct vec2 hitVector); |
| 318 |
static void DoDamageCharacter( |
| 319 |
const TActor *actor, const TActor *source, const struct vec2 hitVector, |
| 320 |
const BulletClass *bullet, const WeaponClass *weapon, const int flags); |
| 321 |
void Damage( |
| 322 |
const struct vec2 hitVector, const BulletClass *bullet, |
| 323 |
const WeaponClass *weapon, const int flags, const TActor *source, |
| 324 |
const ThingKind targetKind, const int targetUID) |
| 325 |
{ |
| 326 |
switch (targetKind) |
| 327 |
{ |
| 328 |
case KIND_CHARACTER: { |
| 329 |
const TActor *actor = ActorGetByUID(targetUID); |
| 330 |
DoDamageCharacter(actor, source, hitVector, bullet, weapon, flags); |
| 331 |
} |
| 332 |
break; |
| 333 |
case KIND_OBJECT: |
| 334 |
DoDamageThing( |
| 335 |
targetKind, targetUID, source, flags, bullet, weapon, true, |
| 336 |
hitVector); |
| 337 |
break; |
| 338 |
default: |
| 339 |
CASSERT(false, "cannot damage tile item kind"); |
| 340 |
break; |
| 341 |
} |
| 342 |
} |
| 343 |
static void DoDamageThing( |
| 344 |
const ThingKind targetKind, const int targetUID, const TActor *source, |
| 345 |
const int flags, const BulletClass *bullet, const WeaponClass *weapon, |
| 346 |
const bool canDamage, const struct vec2 hitVector) |
| 347 |
{ |
| 348 |
GameEvent e = GameEventNew(GAME_EVENT_THING_DAMAGE); |
| 349 |
e.u.ThingDamage.UID = targetUID; |
| 350 |
e.u.ThingDamage.Kind = targetKind; |
| 351 |
e.u.ThingDamage.SourceActorUID = source ? source->uid : -1; |
| 352 |
e.u.ThingDamage.Flags = flags; |
| 353 |
BulletToDamageEvent(bullet, &e); |
| 354 |
if (!canDamage) |
| 355 |
{ |
| 356 |
e.u.ThingDamage.Power = 0; |
| 357 |
} |
| 358 |
e.u.ThingDamage.Vel = Vec2ToNet(hitVector); |
| 359 |
if (weapon) |
| 360 |
{ |
| 361 |
strcpy(e.u.ThingDamage.SourceWeaponClassName, weapon->name); |
| 362 |
} |
| 363 |
GameEventsEnqueue(&gGameEvents, e); |
| 364 |
} |
| 365 |
static void DoDamageCharacter( |
| 366 |
const TActor *actor, const TActor *source, const struct vec2 hitVector, |
| 367 |
const BulletClass *bullet, const WeaponClass *weapon, const int flags) |
| 368 |
{ |
| 369 |
|
| 370 |
CASSERT(actor->isInUse, "Cannot damage nonexistent player"); |
| 371 |
CASSERT( |
| 372 |
CanHitCharacter(flags, source ? source->uid : -1, actor), |
| 373 |
"damaging undamageable actor"); |
| 374 |
|
| 375 |
|
| 376 |
const float impulseFactor = bullet->Mass * SHOT_IMPULSE_FACTOR * |
| 377 |
CHARACTER_DEFAULT_MASS / |
| 378 |
ActorGetCharacter(actor)->Class->Mass; |
| 379 |
const struct vec2 vel = svec2_scale(hitVector, impulseFactor); |
| 380 |
if (!svec2_is_zero(vel)) |
| 381 |
{ |
| 382 |
GameEvent ei = GameEventNew(GAME_EVENT_ACTOR_IMPULSE); |
| 383 |
ei.u.ActorImpulse.UID = actor->uid; |
| 384 |
ei.u.ActorImpulse.Vel = Vec2ToNet(vel); |
| 385 |
ei.u.ActorImpulse.Pos = Vec2ToNet(actor->Pos); |
| 386 |
GameEventsEnqueue(&gGameEvents, ei); |
| 387 |
} |
| 388 |
|
| 389 |
const bool canDamage = |
| 390 |
CanDamageCharacter(flags, source, actor, bullet->Special.Effect); |
| 391 |
|
| 392 |
DoDamageThing( |
| 393 |
KIND_CHARACTER, actor->uid, source, flags, bullet, weapon, canDamage, |
| 394 |
hitVector); |
| 395 |
|
| 396 |
if (canDamage) |
| 397 |
{ |
| 398 |
|
| 399 |
const bool isFriendly = |
| 400 |
(actor->flags & FLAGS_GOOD_GUY) || actor->pilotUID == -1 || |
| 401 |
(!IsPVP(gCampaign.Entry.Mode) && actor->PlayerUID >= 0); |
| 402 |
if (source && source->PlayerUID >= 0 && bullet->Power != 0 && |
| 403 |
!isFriendly) |
| 404 |
{ |
| 405 |
|
| 406 |
|
| 407 |
GameEvent e = GameEventNew(GAME_EVENT_SCORE); |
| 408 |
e.u.Score.PlayerUID = source->PlayerUID; |
| 409 |
if (actor->flags & FLAGS_PENALTY) |
| 410 |
{ |
| 411 |
e.u.Score.Score = PENALTY_MULTIPLIER * bullet->Power; |
| 412 |
} |
| 413 |
else |
| 414 |
{ |
| 415 |
e.u.Score.Score = bullet->Power; |
| 416 |
} |
| 417 |
GameEventsEnqueue(&gGameEvents, e); |
| 418 |
} |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
void UpdateMobileObjects(int ticks) |
| 423 |
{ |
| 424 |
CA_FOREACH(TMobileObject, obj, gMobObjs) |
| 425 |
if (!obj->isInUse) |
| 426 |
{ |
| 427 |
continue; |
| 428 |
} |
| 429 |
if (!BulletUpdate(obj, ticks) && !gCampaign.IsClient) |
| 430 |
{ |
| 431 |
GameEvent e = GameEventNew(GAME_EVENT_REMOVE_BULLET); |
| 432 |
e.u.RemoveBullet.UID = obj->UID; |
| 433 |
GameEventsEnqueue(&gGameEvents, e); |
| 434 |
continue; |
| 435 |
} |
| 436 |
CA_FOREACH_END() |
| 437 |
} |
| 438 |
|
| 439 |
void ObjsInit(void) |
| 440 |
{ |
| 441 |
CArrayInit(&gObjs, sizeof(TObject)); |
| 442 |
CArrayReserve(&gObjs, 1024); |
| 443 |
sObjUIDs = 0; |
| 444 |
} |
| 445 |
void ObjsTerminate(void) |
| 446 |
{ |
| 447 |
CA_FOREACH(TObject, o, gObjs) |
| 448 |
if (o->isInUse) |
| 449 |
{ |
| 450 |
ObjDestroy(o); |
| 451 |
} |
| 452 |
CA_FOREACH_END() |
| 453 |
CArrayTerminate(&gObjs); |
| 454 |
} |
| 455 |
int ObjsGetNextUID(void) |
| 456 |
{ |
| 457 |
return sObjUIDs++; |
| 458 |
} |
| 459 |
|
| 460 |
void ObjAdd(const NMapObjectAdd amo) |
| 461 |
{ |
| 462 |
|
| 463 |
if (ObjGetByUID(amo.UID) != NULL) |
| 464 |
{ |
| 465 |
LOG(LM_MAIN, LL_DEBUG, "object uid(%d) already exists; not adding", |
| 466 |
(int)amo.UID); |
| 467 |
return; |
| 468 |
} |
| 469 |
|
| 470 |
TObject *o = NULL; |
| 471 |
int i; |
| 472 |
for (i = 0; i < (int)gObjs.size; i++) |
| 473 |
{ |
| 474 |
TObject *obj = CArrayGet(&gObjs, i); |
| 475 |
if (!obj->isInUse) |
| 476 |
{ |
| 477 |
o = obj; |
| 478 |
break; |
| 479 |
} |
| 480 |
} |
| 481 |
if (o == NULL) |
| 482 |
{ |
| 483 |
TObject obj; |
| 484 |
memset(&obj, 0, sizeof obj); |
| 485 |
CArrayPushBack(&gObjs, &obj); |
| 486 |
i = (int)gObjs.size - 1; |
| 487 |
o = CArrayGet(&gObjs, i); |
| 488 |
} |
| 489 |
memset(o, 0, sizeof *o); |
| 490 |
o->uid = amo.UID; |
| 491 |
o->Class = StrMapObject(amo.MapObjectClass); |
| 492 |
switch (o->Class->Type) |
| 493 |
{ |
| 494 |
case MAP_OBJECT_TYPE_NORMAL: |
| 495 |
|
| 496 |
break; |
| 497 |
case MAP_OBJECT_TYPE_PICKUP_SPAWNER: |
| 498 |
|
| 499 |
break; |
| 500 |
case MAP_OBJECT_TYPE_ACTOR_SPAWNER: |
| 501 |
o->counter = o->Class->u.Character.Counter; |
| 502 |
break; |
| 503 |
default: |
| 504 |
CASSERT(false, "unknown map object type"); |
| 505 |
break; |
| 506 |
} |
| 507 |
ThingInit(&o->thing, i, KIND_OBJECT, o->Class->Size, amo.ThingFlags); |
| 508 |
o->Health = amo.Health; |
| 509 |
o->thing.CPic = o->Class->Pic; |
| 510 |
o->thing.CPic.Mask = Net2Color(amo.Mask); |
| 511 |
if (ColorEquals(o->thing.CPic.Mask, colorTransparent)) |
| 512 |
{ |
| 513 |
o->thing.CPic.Mask = o->Class->Pic.Mask; |
| 514 |
} |
| 515 |
o->thing.CPicFunc = MapObjectDraw; |
| 516 |
MapTryMoveThing(&gMap, &o->thing, NetToVec2(amo.Pos)); |
| 517 |
EmitterInit( |
| 518 |
&o->damageSmoke, |
| 519 |
StrParticleClass( |
| 520 |
&gParticleClasses, o->Class->DamageSmoke.ParticleClass), |
| 521 |
svec2_zero(), -0.05f, 0.05f, 3, 3, 0, 0, o->Class->DamageSmoke.Ticks); |
| 522 |
o->isInUse = true; |
| 523 |
LOG(LM_MAIN, LL_DEBUG, |
| 524 |
"added object uid(%d) class(%s) health(%d) pos(%d, %d)", (int)amo.UID, |
| 525 |
amo.MapObjectClass, amo.Health, (int)amo.Pos.x, (int)amo.Pos.y); |
| 526 |
|
| 527 |
if (o->thing.flags & THING_IMPASSABLE) |
| 528 |
{ |
| 529 |
|
| 530 |
PathCacheClear(&gPathCache); |
| 531 |
} |
| 532 |
} |
| 533 |
|
| 534 |
void ObjDestroy(TObject *o) |
| 535 |
{ |
| 536 |
CASSERT(o->isInUse, "Destroying in-use object"); |
| 537 |
MapRemoveThing(&gMap, &o->thing); |
| 538 |
o->isInUse = false; |
| 539 |
} |
| 540 |
|
| 541 |
bool ObjIsDangerous(const TObject *o) |
| 542 |
{ |
| 543 |
|
| 544 |
return o->Class->DestroyGuns.size > 0; |
| 545 |
} |
| 546 |
|
| 547 |
void UpdateObjects(const int ticks) |
| 548 |
{ |
| 549 |
CA_FOREACH(TObject, obj, gObjs) |
| 550 |
if (!obj->isInUse) |
| 551 |
{ |
| 552 |
continue; |
| 553 |
} |
| 554 |
ThingUpdate(&obj->thing, ticks); |
| 555 |
switch (obj->Class->Type) |
| 556 |
{ |
| 557 |
case MAP_OBJECT_TYPE_NORMAL: |
| 558 |
|
| 559 |
if (obj->Class->DamageSmoke.HealthThreshold >= 0 && |
| 560 |
obj->Health <= |
| 561 |
obj->Class->Health * obj->Class->DamageSmoke.HealthThreshold) |
| 562 |
{ |
| 563 |
AddParticle ap; |
| 564 |
memset(&ap, 0, sizeof ap); |
| 565 |
ap.Pos = svec2_add( |
| 566 |
obj->thing.Pos, |
| 567 |
svec2( |
| 568 |
RAND_FLOAT(-obj->thing.size.x / 4, obj->thing.size.x / 4), |
| 569 |
RAND_FLOAT( |
| 570 |
-obj->thing.size.y / 4, obj->thing.size.y / 4))); |
| 571 |
ap.Z = obj->Class->DamageSmoke.Z; |
| 572 |
ap.Mask = colorWhite; |
| 573 |
EmitterUpdate(&obj->damageSmoke, &ap, ticks); |
| 574 |
} |
| 575 |
break; |
| 576 |
case MAP_OBJECT_TYPE_PICKUP_SPAWNER: |
| 577 |
if (gCampaign.IsClient) |
| 578 |
break; |
| 579 |
|
| 580 |
if (obj->counter == -1) |
| 581 |
{ |
| 582 |
break; |
| 583 |
} |
| 584 |
obj->counter -= ticks; |
| 585 |
if (obj->counter <= 0) |
| 586 |
{ |
| 587 |
|
| 588 |
|
| 589 |
obj->counter = -1; |
| 590 |
GameEvent e = GameEventNew(GAME_EVENT_ADD_PICKUP); |
| 591 |
strcpy(e.u.AddPickup.PickupClass, obj->Class->u.PickupClass->Name); |
| 592 |
e.u.AddPickup.SpawnerUID = obj->uid; |
| 593 |
e.u.AddPickup.Pos = Vec2ToNet(obj->thing.Pos); |
| 594 |
GameEventsEnqueue(&gGameEvents, e); |
| 595 |
} |
| 596 |
break; |
| 597 |
case MAP_OBJECT_TYPE_ACTOR_SPAWNER: |
| 598 |
if (gCampaign.IsClient) |
| 599 |
break; |
| 600 |
|
| 601 |
if (obj->counter == -1) |
| 602 |
{ |
| 603 |
break; |
| 604 |
} |
| 605 |
obj->counter -= ticks; |
| 606 |
if (obj->counter <= 0) |
| 607 |
{ |
| 608 |
|
| 609 |
obj->counter = -1; |
| 610 |
GameEvent e = GameEventNewActorAdd( |
| 611 |
obj->thing.Pos, |
| 612 |
CArrayGet( |
| 613 |
&gCampaign.Setting.characters.OtherChars, |
| 614 |
obj->Class->u.Character.CharId), |
| 615 |
NULL); |
| 616 |
e.u.ActorAdd.CharId = obj->Class->u.Character.CharId; |
| 617 |
GameEventsEnqueue(&gGameEvents, e); |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
e = GameEventNew(GAME_EVENT_MAP_OBJECT_REMOVE); |
| 622 |
e.u.MapObjectRemove.UID = obj->uid; |
| 623 |
GameEventsEnqueue(&gGameEvents, e); |
| 624 |
} |
| 625 |
break; |
| 626 |
default: |
| 627 |
|
| 628 |
break; |
| 629 |
} |
| 630 |
CA_FOREACH_END() |
| 631 |
} |
| 632 |
|
| 633 |
TObject *ObjGetByUID(const int uid) |
| 634 |
{ |
| 635 |
CA_FOREACH(TObject, o, gObjs) |
| 636 |
if (o->uid == uid) |
| 637 |
{ |
| 638 |
return o; |
| 639 |
} |
| 640 |
CA_FOREACH_END() |
| 641 |
return NULL; |
| 642 |
} |
| 643 |
|
| 644 |
void BulletToDamageEvent(const BulletClass *b, GameEvent *e) |
| 645 |
{ |
| 646 |
e->u.ThingDamage.Special = b->Special.Effect; |
| 647 |
e->u.ThingDamage.SpecialTicks = b->Special.Ticks; |
| 648 |
e->u.ThingDamage.Power = b->Power; |
| 649 |
e->u.ThingDamage.Mass = b->Mass; |
| 650 |
} |
| 651 |
|
| 652 |
void MobObjsInit(void) |
| 653 |
{ |
| 654 |
CArrayInit(&gMobObjs, sizeof(TMobileObject)); |
| 655 |
CArrayReserve(&gMobObjs, 1024); |
| 656 |
sMobObjUIDs = 0; |
| 657 |
} |
| 658 |
void MobObjsTerminate(void) |
| 659 |
{ |
| 660 |
CA_FOREACH(TMobileObject, m, gMobObjs) |
| 661 |
if (m->isInUse) |
| 662 |
{ |
| 663 |
BulletDestroy(m); |
| 664 |
} |
| 665 |
CA_FOREACH_END() |
| 666 |
CArrayTerminate(&gMobObjs); |
| 667 |
} |
| 668 |
int MobObjsObjsGetNextUID(void) |
| 669 |
{ |
| 670 |
return sMobObjUIDs++; |
| 671 |
} |
| 672 |
TMobileObject *MobObjGetByUID(const int uid) |
| 673 |
{ |
| 674 |
CA_FOREACH(TMobileObject, o, gMobObjs) |
| 675 |
if (o->UID == uid) |
| 676 |
{ |
| 677 |
return o; |
| 678 |
} |
| 679 |
CA_FOREACH_END() |
| 680 |
return NULL; |
| 681 |
} |