File: ExpGenSpawner.cpp

package info (click to toggle)
spring 105.0.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 108,860 kB
  • sloc: cpp: 467,785; ansic: 302,607; python: 12,925; java: 12,201; awk: 5,889; sh: 2,371; xml: 655; perl: 405; php: 276; objc: 194; makefile: 75; sed: 2
file content (62 lines) | stat: -rw-r--r-- 1,646 bytes parent folder | download | duplicates (3)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include "ExpGenSpawner.h"

#include "ExpGenSpawnableMemberInfo.h"
#include "ExplosionGenerator.h"

CR_BIND_DERIVED(CExpGenSpawner, CProjectile, )
CR_REG_METADATA(CExpGenSpawner,
(
	CR_MEMBER_BEGINFLAG(CM_Config),
		CR_MEMBER(delay),
		CR_MEMBER(damage),
		CR_IGNORED(explosionGenerator),
	CR_MEMBER_ENDFLAG(CM_Config),
	CR_SERIALIZER(Serialize)
))


CExpGenSpawner::CExpGenSpawner() : CProjectile()
{
	checkCol = false;
	deleteMe = false;
}

void CExpGenSpawner::Serialize(creg::ISerializer* s) {
	int generatorID;

	if (s->IsWriting())
		generatorID = explosionGenerator->GetGeneratorID();

	s->SerializeInt(&generatorID, sizeof(generatorID));

	if (s->IsWriting())
		return;

	// NOTE:
	//   projectiles are serialized, but ExplosionGeneratorHandler itself is not
	//   as such generator-id can be invalid when this spawner gets deserialized
	//   (if additional generators were loaded at runtime before game was saved)
	explosionGenerator = explGenHandler.GetGenerator(generatorID);
}

void CExpGenSpawner::Update()
{
	if ((deleteMe |= ((delay--) <= 0)))
		explosionGenerator->Explosion(pos, dir,  damage, 0.0f, 0.0f,  owner(), nullptr);
}


bool CExpGenSpawner::GetMemberInfo(SExpGenSpawnableMemberInfo& memberInfo)
{
	if (CProjectile::GetMemberInfo(memberInfo))
		return true;

	CHECK_MEMBER_INFO_INT  (CExpGenSpawner, delay )
	CHECK_MEMBER_INFO_FLOAT(CExpGenSpawner, damage)
	// TODO: much nicer to load cegID directly via LoadGeneratorID callback
	CHECK_MEMBER_INFO_PTR  (CExpGenSpawner, explosionGenerator, explGenHandler.LoadGenerator)

	return false;
}