added some tables, add upgrade

now not reading tables:
	morphs
	chains
	upgrades
	towersOnLevel
This commit is contained in:
2010-08-22 08:57:31 +03:00
parent da42fe8f58
commit 7099e17901
5 changed files with 261 additions and 86 deletions

View File

@@ -34,6 +34,46 @@ struct Tower
};
struct srcTrigger
{
enum triggerType
{
onDestination,
onTimer,
onAlienInRadius
};
int childId; // =-1 for non birth splash (e.q. only damage)
bool delParent;
float damage;
float radius;
triggerType type;
unsigned int timer;
int count;
float randomPosRadius;
};
struct srcSplash
{
QString name;
int imgType;
float speed; // in cells
bool autoControl;
QList <int> triggerIndexes;
};
struct srcTower
{
QString name;
int type;
int PlayerId; // tower's owner
float range; // in cells
float reload; // time for reload in ticks
QList <srcTrigger> triggers;
QList <srcSplash> splashes;
};
struct Splash
{
int Id;

View File

@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data>
<ADdata>
<ADdata>
<aliens>
<alien speed="0.012" imageType="1" prise="0" id="10" name="my alien" health="100"/>
<alien speed="0.0099" imageType="1" prise="1" id="12" name="MONSTR" health="200" armor="1.5" regeneration="3"/>
<alien speed="0.012" score="100" imageType="1" prise="0" id="10" name="my alien" health="100"/>
<alien speed="0.0099" score="350" imageType="1" prise="1" id="12" name="MONSTR" health="200" armor="1.5" regeneration="3"/>
</aliens>
<maps>
<map imageType="1" id="1" data="AAAERHicY2BgEGAA4v///0hQgmFmAGlGcjCxZuCTHzUDuxkMDOr85JrBwKC0A8kMJlwYagYOeYgZ+NXgNwMtPEbNINIMIsynOO8DAG0r1Q0=" name="Map 16x16" maxPlayers="2"/>
@@ -21,7 +22,23 @@
<wavePart wave="2" alien="10" count="9"/>
</waveParts>
<wavesOnLevels>
<waveOnLevel wave="1" level="1"/>
<waveOnLevel level="1" wave="1"/>
<waveOnLevel level="1" wave="2"/>
</wavesOnLevels>
<splashes>
<splash speed="0.2" imageType="1" id="1" name="rocket" lifetime="9999"/>
<splash speed="0.2" imageType="1" id="2" name="smart rocket" lifetime="9999" autoControl="true"/>
<splash speed="100" imageType="2" id="3" name="bullet" lifetime="100" autoControl="true"/>
<splash speed="1" imageType="3" id="4" name="bum" lifetime="10"/>
<splash speed="0" imageType="4" id="5" name="smoke" lifetime="10"/>
</splashes>
<towers>
<tower id="1" imageType="1" name="rocket launcher" cost="30" buildTime="50" reload="20" splash="1" radius="3" expByDamage="0.04" expByKill="0.1" expByShot="0.15"/>
<tower id="2" imageType="2" name="gun" cost="10" buildTime="25" reload="5" splash="3" radius="1.5" expByDamage="0.1" expByShot="0.1" expByKill="0.2"/>
</towers>
<triggers>
<trigger id="2" name="shot" type="onDestination" delParent="true" damage="5"/>
<trigger id="3" name="explosion" type="onDestination" count="1" delParent="true" damage="5" radius="1.5"/>
<trigger id="4" name="smoke" type="onTimer" timer="2" count="1"/>
</triggers>
</ADdata>

View File

@@ -24,10 +24,11 @@ void Loader::load()
readMaps();
readLevels();
//readMorphs();
//readSplashes();
//readTowers();
readSplashes();
readTowers();
readTriggers();
//readChains();
//readLevTowers();
//readTriggers();
readWaves();
readWaveParts();
readLevWaves();
@@ -171,8 +172,9 @@ void Loader::readAliens()
al.armor = nm.namedItem("armor").nodeValue().toFloat();
al.imgType = nm.namedItem("imageType").nodeValue().toInt();
al.regeneration = nm.namedItem("regeneration").nodeValue().toFloat();
al.score = nm.namedItem("score").nodeValue().toInt();
aliens.insert(al.id,al);
qDebug() << tr("Alien %1 id=%2 health=%3 speed=%4 prise=%5 imgType=%6 armor=%7 regeneration=%8").arg(al.name).arg(al.id).arg(al.health).arg(al.speed).arg(al.prise).arg(al.imgType).arg(al.armor).arg(al.regeneration);
qDebug() << tr("Alien %1 id=%2 health=%3 speed=%4 prise=%5 imgType=%6 armor=%7 regeneration=%8 score=%10").arg(al.name).arg(al.id).arg(al.health).arg(al.speed).arg(al.prise).arg(al.imgType).arg(al.armor).arg(al.regeneration).arg(al.score);
}
qDebug("================");
qDebug() << tr("Found %1 aliens").arg(aliens.size());
@@ -294,6 +296,51 @@ void Loader::readLevels()
}
void Loader::readTriggers()
{
QString str;
QDomNodeList trelems = doc->elementsByTagName("trigger");
for (int i=0; i<trelems.size(); i++)
{
tbTrigger trig;
QDomNamedNodeMap nm = trelems.at(i).attributes();
trig.id = nm.namedItem("id").nodeValue().toInt();
if (triggers.contains(trig.id)) qCritical("Same splash ID dedected, replacing...");
trig.name = nm.namedItem("name").nodeValue();
trig.damage = nm.namedItem("damage").nodeValue().toFloat();
trig.radius = nm.namedItem("radius").nodeValue().toFloat();
trig.randomPosRadius = nm.namedItem("randomPosRadius").nodeValue().toFloat();
trig.count = nm.namedItem("count").nodeValue().toInt();
trig.timer = nm.namedItem("timer").nodeValue().toInt();
trig.chance = nm.namedItem("chance").nodeValue().toInt();
if (!(trig.chance>1)) trig.chance = 100;
str = nm.namedItem("delParent").nodeValue();
trig.delParent = (str == "true");
str = nm.namedItem("type").nodeValue();
if (str == "onDestination")
trig.type = tbTrigger::onDestination;
if (str == "onTimer")
trig.type = tbTrigger::onTimer;
if (str == "onAlienInRadius")
trig.type = tbTrigger::onAlienInRadius;
str = nm.namedItem("childAim").nodeValue();
trig.childAim = tbTrigger::noAim;
if (str == "allSide")
trig.childAim = tbTrigger::allSide;
if (str == "parentAim")
trig.childAim = tbTrigger::parentAim;
if (str == "nearlestAlien")
trig.childAim = tbTrigger::nearlestAlien;
triggers.insert(trig.id,trig);
qDebug() << tr("Trigger %1 id=%2 damage=%3 radius=%4 delParent=%5 timer=%6").arg(trig.name).arg(trig.id).arg(trig.damage).arg(trig.radius).arg(trig.delParent).arg(trig.timer)
<< tr("count=%1 chance=%2 randomPosRadius=%3 type=%4 childAim=%5").arg(trig.count).arg(trig.chance).arg(trig.randomPosRadius).arg(trig.type).arg(trig.childAim);
}
qDebug("================");
qDebug() << tr("Found %1 triggers").arg(triggers.size());
qDebug("================");
}
void Loader::readSplashes()
{
QString str;
@@ -301,29 +348,17 @@ void Loader::readSplashes()
for (int i=0; i<selems.size(); i++)
{
tbSplash s;
// s.id = selems.at(i).attributes().namedItem("id").nodeValue().toInt();
// if (splashes.contains(s.id)) qCritical("Same splash ID dedected, replacing...");
// s.name = selems.at(i).attributes().namedItem("name").nodeValue();
// s.speed = selems.at(i).attributes().namedItem("speed").nodeValue().toFloat();
// s.radius = selems.at(i).attributes().namedItem("radius").nodeValue().toFloat();
// s.damage = selems.at(i).attributes().namedItem("damage").nodeValue().toFloat();
// s.timer = selems.at(i).attributes().namedItem("timer").nodeValue().toInt();
// s.lifetime = selems.at(i).attributes().namedItem("lifetime").nodeValue().toInt();
// s.imgType = selems.at(i).attributes().namedItem("imageType").nodeValue().toInt();
// str = selems.at(i).attributes().namedItem("autoControl").nodeValue();
// s.autoControl = (str == "true");
// str = selems.at(i).attributes().namedItem("triggerDeath").nodeValue();
// s.isDeadAfterTrigger = (str == "true");
// str = selems.at(i).attributes().namedItem("trigger").nodeValue();
// s.trigger = tbSplash::noTrigger;
// if (str == "onDestination")
// s.trigger = tbSplash::onDestination;
// if (str == "onTimer")
// s.trigger = tbSplash::onTimer;
// if (str == "onAlienInRadius")
// s.trigger = tbSplash::onAlienInRadius;
// splashes.insert(s.id,s);
// qDebug() << tr("Splash %1 id=%2 damage=%3 speed=%4 radius=%5 imgType=%6 ").arg(s.name).arg(s.id).arg(s.damage).arg(s.speed).arg(s.radius).arg(s.imgType) << tr("lifetime=%1 timer=%2 trigger=%3 autoControl=%4 triggerDeath=%5").arg(s.lifetime).arg(s.timer).arg(s.trigger).arg(s.autoControl).arg(s.isDeadAfterTrigger);
QDomNamedNodeMap nm = selems.at(i).attributes();
s.id = nm.namedItem("id").nodeValue().toInt();
if (splashes.contains(s.id)) qCritical("Same splash ID dedected, replacing...");
s.name = nm.namedItem("name").nodeValue();
s.speed = nm.namedItem("speed").nodeValue().toFloat();
s.lifetime = nm.namedItem("lifetime").nodeValue().toInt();
s.imgType = nm.namedItem("imageType").nodeValue().toInt();
str = nm.namedItem("autoControl").nodeValue();
s.autoControl = (str == "true");
splashes.insert(s.id,s);
qDebug() << tr("Splash %1 id=%2 speed=%3 imgType=%4 autoControl=%5 lifetime=%6").arg(s.name).arg(s.id).arg(s.speed).arg(s.imgType).arg(s.autoControl).arg(s.lifetime);
}
qDebug("================");
qDebug() << tr("Found %1 splashes").arg(splashes.size());
@@ -336,12 +371,32 @@ void Loader::readTowers()
QDomNodeList twelems = doc->elementsByTagName("tower");
for (int i=0; i<twelems.size(); i++)
{
bool OK = true;
tbTower tw;
tw.id = twelems.at(i).attributes().namedItem("id").nodeValue().toInt();
QDomNamedNodeMap nm = twelems.at(i).attributes();
tw.id = nm.namedItem("id").nodeValue().toInt();
if (towers.contains(tw.id)) qCritical("Same tower ID dedected, replacing...");
tw.name = twelems.at(i).attributes().namedItem("name").nodeValue();
tw.name = nm.namedItem("name").nodeValue();
tw.radius = nm.namedItem("radius").nodeValue().toFloat();
tw.expByDamage = nm.namedItem("expByDamage").nodeValue().toFloat();
tw.expByKill = nm.namedItem("expByKill").nodeValue().toFloat();
tw.expByShot = nm.namedItem("expByShot").nodeValue().toFloat();
tw.imgType = nm.namedItem("imageType").nodeValue().toInt();
tw.reload = nm.namedItem("reload").nodeValue().toInt();
tw.cost = nm.namedItem("cost").nodeValue().toInt();
tw.buildTime = nm.namedItem("buildTime").nodeValue().toInt();
tw.splashId = nm.namedItem("splash").nodeValue().toInt();
if (!splashes.contains(tw.splashId))
{
qCritical("Invalid splash Id");
OK = false;
}
if (OK)
{
towers.insert(tw.id,tw);
qDebug() << tr("Tower %1 id=%2").arg(tw.name).arg(tw.id);
qDebug() << tr("Tower %1 id=%2 radius=%3 cost=%4 reload=%5 buildTime=%6 splash=%7").arg(tw.name).arg(tw.id).arg(tw.radius).arg(tw.cost).arg(tw.reload).arg(tw.buildTime).arg(tw.splashId)
<< tr("imgType=%1 expByKill=%2 expByShot=%3 expByDamage=%4").arg(tw.imgType).arg(tw.expByKill).arg(tw.expByShot).arg(tw.expByDamage);
}
}
qDebug("================");
qDebug() << tr("Found %1 towers").arg(towers.size());
@@ -383,8 +438,6 @@ void Loader::validate()
QXmlSchema schema;
if (!schema.load(&sfile))
qFatal("Error parsing schema.xml");
if (!schema.isValid())
qFatal("Invalid XMLSchema in schema.xml");
QXmlSchemaValidator sval(schema);
QFile dfile("data.xml");
if (!dfile.open(QIODevice::ReadOnly))

View File

@@ -18,6 +18,8 @@ struct tbAlien
float health;
float armor;
float regeneration;
bool isFlying;
unsigned int score;
int imgType;
unsigned int prise;
};
@@ -27,7 +29,6 @@ struct tbSplash
int id;
QString name;
float speed;
float radius;
unsigned int lifetime;
bool autoControl;
int imgType;
@@ -41,8 +42,21 @@ struct tbTrigger
onTimer,
onAlienInRadius
};
enum aimType
{
noAim,
parentAim,
allSide,
nearlestAlien
};
int id;
QString name;
float damage;
float radius;
int chance;
bool delParent;
aimType childAim;
triggerType type;
unsigned int timer;
int count;
@@ -54,13 +68,33 @@ struct tbTower
int id;
QString name;
float radius;
unsigned int price;
unsigned int cost;
unsigned int reload;
unsigned int buildTime;
float expByShot;
float expByKill;
float expByDamage;
int splashId;
int imgType;
};
struct tbChain
{
int towerId;
int parentSplashId;
int childSplashId;
int triggerId;
};
struct tbUpgrade
{
int towerId;
int triggerId;
unsigned int cost;
float towRadius;
unsigned int towReload;
float trigDamage;
float trigDamageRadius;
};
struct tbMorph
@@ -105,7 +139,7 @@ struct tbTowerOnLevel
{
int levelId;
int towerId;
int enableWaveId;
//int enableWaveId;
};
struct tbLevel
@@ -113,6 +147,7 @@ struct tbLevel
int id;
QString name;
int mapId;
unsigned int score;
};
@@ -135,14 +170,15 @@ private:
QHash <int,tbAlien> aliens;
QHash <int,tbMap> maps;
QHash <int,tbLevel> levels;
QHash <int,tbMorph> morphs;
QHash <int,tbSplash> splashes;
QHash <int,tbTower> towers;
QHash <int,tbTowerOnLevel> levTowers;
QHash <int,tbTrigger> triggers;
QHash <int,tbWave> waves;
QMultiHash <int,tbWaveOnLevel> levWaves;
QMultiHash <int,tbWavePart> waveParts;
QMultiHash <int,tbChain> chains;
QMultiHash <int,tbMorph> morphs;
QMultiHash <int,tbTowerOnLevel> levTowers;
void readAliens();
void readMaps();
@@ -152,6 +188,7 @@ private:
void readTowers();
void readLevTowers();
void readTriggers();
void readChains();
void readWaves();
void readLevWaves();
void readWaveParts();

View File

@@ -1,9 +1,9 @@
<?xml version="1.0"?>
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="ADdata">
<xsd:complexType>
<xsd:all>
<xsd:sequence>
<xsd:element name="aliens">
<xsd:complexType>
<xsd:sequence>
@@ -25,6 +25,13 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="levels">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="level" type="levelType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="waveParts">
<xsd:complexType>
<xsd:sequence>
@@ -39,20 +46,35 @@
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="levels">
<xsd:element name="splashes">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="level" type="levelType" maxOccurs="unbounded"/>
<xsd:element name="splash" type="splashType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:all>
<xsd:element name="towers">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="tower" type="towerType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="triggers">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="trigger" type="triggerType" maxOccurs="unbounded"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="alienType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="score" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="speed" type="xsd:float" use="required"/>
<xsd:attribute name="health" type="xsd:float" use="required"/>
<xsd:attribute name="prise" type="xsd:nonNegativeInteger" use="required"/>
@@ -65,41 +87,49 @@
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="speed" type="xsd:float" use="required"/>
<xsd:attribute name="damage" type="xsd:float" use="required"/>
<xsd:attribute name="radius" type="xsd:float" use="required"/>
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
<xsd:attribute name="triggerDeath" type="xsd:boolean" use="optional"/>
<xsd:attribute name="lifetime" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="autoControl" type="xsd:boolean" use="optional"/>
<xsd:attribute name="timer" type="xsd:positiveInteger" use="optional"/>
<xsd:attribute name="lifetime" type="xsd:positiveInteger" use="optional"/>
</xsd:complexType>
<xsd:complexType name="triggerType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="parentSplash" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="childSplash" type="xsd:nonNegativeInteger" use="optional"/>
<xsd:attribute name="count" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="count" type="xsd:positiveInteger" use="optional"/>
<xsd:attribute name="timer" type="xsd:positiveInteger" use="optional"/>
<xsd:attribute name="chance" type="xsd:positiveInteger" use="optional"/>
<xsd:attribute name="randomPosRadius" type="xsd:float" use="optional"/>
<xsd:attribute name="type" use="optional">
<xsd:attribute name="damage" type="xsd:float" use="optional"/>
<xsd:attribute name="radius" type="xsd:float" use="optional"/>
<xsd:attribute name="delParent" type="xsd:boolean" use="optional"/>
<xsd:attribute name="type" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="noTrigger"/>
<xsd:enumeration value="onDestination"/>
<xsd:enumeration value="onTimer"/>
<xsd:enumeration value="onAlienInRadius"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="childAim" use="optional">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="noAim"/>
<xsd:enumeration value="parentAim"/>
<xsd:enumeration value="allSide"/>
<xsd:enumeration value="nearlestAlien"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:complexType name="towerType">
<xsd:attribute name="name" type="xsd:string" use="required"/>
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="imageType" type="xsd:integer" use="required"/>
<xsd:attribute name="buildTime" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="price" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="splashType" type="xsd:integer" use="required"/>
<xsd:attribute name="cost" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="splash" type="xsd:integer" use="required"/>
<xsd:attribute name="reload" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="radius" type="xsd:float" use="required"/>
<xsd:attribute name="expByShot" type="xsd:float" use="optional"/>
@@ -116,10 +146,9 @@
</xsd:complexType>
<xsd:complexType name="morphType">
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="from" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="to" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="price" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="cost" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="expRequired" type="xsd:float" use="required"/>
</xsd:complexType>
@@ -133,7 +162,7 @@
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="timeout" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="prise" type="xsd:nonNegativeInteger" use="required"/>
<!--xsd:attribute name="type" type="xsd:nonNegativeInteger" use="required"/!-->
<!--xsd:attribute name="type" type="xsd:nonNegativeInteger" use="required"-->
</xsd:complexType>
<xsd:complexType name="waveOnLevelType">
@@ -142,10 +171,9 @@
</xsd:complexType>
<xsd:complexType name="towerOnLevelType">
<xsd:attribute name="id" type="xsd:positiveInteger" use="required"/>
<xsd:attribute name="level" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="tower" type="xsd:nonNegativeInteger" use="required"/>
<xsd:attribute name="enableWave" type="xsd:nonNegativeInteger" use="optional"/>
<!--xsd:attribute name="enableWave" type="xsd:nonNegativeInteger" use="optional"-->
</xsd:complexType>
<xsd:complexType name="levelType">