added Towers loading in level

This commit is contained in:
unknown
2010-08-26 14:39:52 +04:00
parent 47cf1e38ea
commit b3854e867d
7 changed files with 247 additions and 119 deletions

View File

@@ -188,13 +188,13 @@ void Loader::save(QString filename)
elem.setAttribute("randomPosRadius",trig.randomPosRadius);
switch (trig.childAim)
{
case tbTrigger::allSide :
case srcTriggerType::allSide :
elem.setAttribute("childAim","allSide");
break;
case tbTrigger::nearlestAlien :
case srcTriggerType::nearlestAlien :
elem.setAttribute("childAim","nearlestAlien");
break;
case tbTrigger::parentAim :
case srcTriggerType::parentAim :
elem.setAttribute("childAim","parentAim");
break;
default:
@@ -203,15 +203,15 @@ void Loader::save(QString filename)
}
switch (trig.type)
{
case tbTrigger::onTimer :
elem.setAttribute("type","onTimer");
break;
case tbTrigger::onDestination :
elem.setAttribute("type","onDestination");
break;
case tbTrigger::onAlienInRadius :
elem.setAttribute("type","onAlienInRadius");
break;
case srcTriggerType::onTimer :
elem.setAttribute("type","onTimer");
break;
case srcTriggerType::onDestination :
elem.setAttribute("type","onDestination");
break;
case srcTriggerType::onAlienInRadius :
elem.setAttribute("type","onAlienInRadius");
break;
}
}
child = data.createElement("chains");
@@ -243,84 +243,151 @@ void Loader::save(QString filename)
}
//Game_Data * Loader::loadlevel(int id)
//{
// if (!levels.contains(id))
// {
// qCritical() << tr("Error Level %1 not found!").arg(id);
// return 0;
// }
// qDebug() << tr("Loading level %1 ...").arg(levels.value(id).name);
// tbMap tbm = maps.value(levels.value(id).mapId);
// Map * map = new Map(tbm.data,tbm.size,tbm.name,tbm.maxPlayers,tbm.imgType);
// Game_Data * gd = new Game_Data(map);
// QList <tbWaveOnLevel> wollist = levWaves.values(id);
// if (wollist.isEmpty())
// {
// qCritical() << tr("Error no waves on level!");
// return 0;
// }
// tbWave tbw;
// tbWavePart tbwpt;
// QList <tbWavePart> wplist;
// QList <int> alienIds;
// for (int i=0; i<wollist.size(); i++)
// {
// WaveType wt;
// tbw = waves.value(wollist.at(i).waveId);
// wt.prise = tbw.prise;
// wt.timeout = tbw.timeout;
// wplist = waveParts.values(tbw.id);
// if (wplist.isEmpty())
// {
// qCritical() << tr("Error wave %1 is empty!").arg(tbw.id);
// return 0;
// }
// for (int j=0; j<wplist.size(); j++)
// {
// tbwpt = wplist.at(j);
// if (alienIds.contains(tbwpt.alienId))
// {
// wt.types.prepend(alienIds.indexOf(tbwpt.alienId));
// } else {
// alienIds.append(tbwpt.alienId);
// wt.types.prepend(alienIds.size()-1);
// }
// wt.counts.prepend(tbwpt.count);
// }
// gd->waves.prepend(wt);
// wplist.clear();
// }
// for (int i=0; i<gd->waves.size(); i++)
// qDebug() << tr("load wave #%1 prise=%2 timeout=%3").arg(i+1).arg(gd->waves.at(i).prise).arg(gd->waves.at(i).timeout) << gd->waves.at(i).types << gd->waves.at(i).counts;
// wollist.clear();
// for (int i=0; i<alienIds.size(); i++)
// {
// srcAlienType salt;
// tbAlien tbal = aliens.value(alienIds.at(i));
// salt.armor = tbal.armor;
// salt.health = tbal.health;
// salt.imgType = tbal.imgType;
// salt.isFlying = tbal.isFlying;
// salt.name = tbal.name;
// salt.prise = tbal.prise;
// salt.regeneration = tbal.regeneration;
// salt.score = tbal.score;
// salt.speed = tbal.speed;
// gd->srcAliens.append(salt);
// qDebug() << tr("Alien %1 #%2 ").arg(salt.name).arg(i);
// }
// QList <tbTowerOnLevel> tollist = levTowers.values(id);
// tbTower tbt;
// for (int i=0; i<tollist.size(); i++)
// {
// srcTowerType stt;
// tbt = towers.value(tollist.at(i).towerId);
// }
// return gd;
//}
Game_Data * Loader::loadlevel(int id)
{
if (!levels.contains(id))
{
qCritical() << tr("Error Level %1 not found!").arg(id);
return 0;
}
qDebug() << tr("Loading level %1 ...").arg(levels.value(id).name);
tbMap tbm = maps.value(levels.value(id).mapId);
Map * map = new Map(tbm.data,tbm.size,tbm.name,tbm.maxPlayers,tbm.imgType);
Game_Data * gd = new Game_Data(map);
QList <tbWaveOnLevel> wollist = levWaves.values(id);
if (wollist.isEmpty())
{
qCritical() << tr("Error no waves on level!");
return 0;
}
tbWave tbw;
tbWavePart tbwpt;
QList <tbWavePart> wplist;
QList <int> alienIds;
for (int i=0; i<wollist.size(); i++)
{
WaveType wt;
tbw = waves.value(wollist.at(i).waveId);
wt.prise = tbw.prise;
wt.timeout = tbw.timeout;
wplist = waveParts.values(tbw.id);
if (wplist.isEmpty())
{
qCritical() << tr("Error wave %1 is empty!").arg(tbw.id);
return 0;
}
for (int j=0; j<wplist.size(); j++)
{
tbwpt = wplist.at(j);
if (alienIds.contains(tbwpt.alienId))
{
wt.types.prepend(alienIds.indexOf(tbwpt.alienId));
} else {
alienIds.append(tbwpt.alienId);
wt.types.prepend(alienIds.size()-1);
}
wt.counts.prepend(tbwpt.count);
}
gd->waves.prepend(wt);
wplist.clear();
}
for (int i=0; i<gd->waves.size(); i++)
qDebug() << tr("load wave #%1 prise=%2 timeout=%3").arg(i+1).arg(gd->waves.at(i).prise).arg(gd->waves.at(i).timeout) << gd->waves.at(i).types << gd->waves.at(i).counts;
wollist.clear();
for (int i=0; i<alienIds.size(); i++)
{
srcAlienType salt;
tbAlien tbal = aliens.value(alienIds.at(i));
salt.armor = tbal.armor;
salt.health = tbal.health;
salt.imgType = tbal.imgType;
salt.isFlying = tbal.isFlying;
salt.name = tbal.name;
salt.prise = tbal.prise;
salt.regeneration = tbal.regeneration;
salt.score = tbal.score;
salt.speed = tbal.speed;
gd->srcAliens.append(salt);
qDebug() << tr("Alien %1 #%2 ").arg(salt.name).arg(i);
}
QList <tbTowerOnLevel> tollist = levTowers.values(id);
tbTower tbt;
for (int i=0; i<tollist.size(); i++)
{
srcTowerType stt;
tbt = towers.value(tollist.at(i).towerId);
stt.buildTime = tbt.buildTime;
stt.cost = tbt.cost;
stt.expByDamage = tbt.expByDamage;
stt.expByKill = tbt.expByKill;
stt.expByShot = tbt.expByShot;
stt.imgType = tbt.imgType;
stt.name = tbt.name;
stt.radius = tbt.radius;
stt.reload = tbt.reload;
QList <tbChain> chlist = chains.values(tbt.id);
QList <int> trigIds;
tbSplash tbs = splashes.value(tbt.splashId);
srcSplashType sst;
sst.autoControl = tbs.autoControl;
sst.imgType = tbs.imgType;
sst.lifetime = tbs.lifetime;
sst.name = tbs.name;
sst.speed = tbs.speed;
stt.splashes.append(sst);
int recursiveCheck = 1;
fillTowerChains(&chlist,&trigIds,&stt,tbt.splashId,0,&recursiveCheck);
qDebug() << tr("Tower %1 trig=%2 splash=%3").arg(stt.name).arg(stt.triggers.size()).arg(stt.splashes.size()) << tr("chain lenght %1").arg(recursiveCheck);
}
return gd;
}
void Loader::fillTowerChains(QList <tbChain> * chlist, QList <int> * trigIds, srcTowerType * stt, int parId, int parIndex, int * recursiveCheck)
{
if (*recursiveCheck > 100)
{
qCritical("circle dependencies detected!");
return;
}
for (int i=0; i<chlist->size(); i++)
{
if (chlist->at(i).parentSplashId == parId)
{
int trigid = chlist->at(i).triggerId;
if (!(trigIds->contains(trigid)))
{
srcTriggerType strigt;
tbTrigger tbtrig = triggers.value(trigid);
strigt.count = tbtrig.count;
strigt.damage = tbtrig.damage;
strigt.delParent = tbtrig.delParent;
strigt.radius = tbtrig.radius;
strigt.randomPosRadius = tbtrig.randomPosRadius;
strigt.timer = tbtrig.timer;
strigt.type = tbtrig.type;
stt->triggers.append(strigt);
trigIds->append(trigid);
}
stt->splashes[parIndex].triggerIndexes.append(trigIds->indexOf(trigid));
if (chlist->at(i).childSplashId > 0 && stt->triggers.at(trigIds->indexOf(trigid)).count > 0)
{
tbSplash tbs = splashes.value(chlist->at(i).childSplashId);
srcSplashType sst;
sst.autoControl = tbs.autoControl;
sst.imgType = tbs.imgType;
sst.lifetime = tbs.lifetime;
sst.name = tbs.name;
sst.speed = tbs.speed;
stt->splashes.append(sst);
stt->triggers[stt->splashes.at(parIndex).triggerIndexes.size()-1].childId = stt->splashes.size() - 1;
*recursiveCheck += 1;
fillTowerChains(chlist,trigIds,stt,chlist->at(i).childSplashId, stt->splashes.size()-1,recursiveCheck);
}
}
}
}
QString Loader::CreateMapExample()
{
QVector < QVector < int > > Cells;
@@ -611,19 +678,19 @@ void Loader::readTriggers()
trig.delParent = (str == "true");
str = nm.namedItem("type").nodeValue();
if (str == "onDestination")
trig.type = tbTrigger::onDestination;
trig.type = srcTriggerType::onDestination;
if (str == "onTimer")
trig.type = tbTrigger::onTimer;
trig.type = srcTriggerType::onTimer;
if (str == "onAlienInRadius")
trig.type = tbTrigger::onAlienInRadius;
trig.type = srcTriggerType::onAlienInRadius;
str = nm.namedItem("childAim").nodeValue();
trig.childAim = tbTrigger::noAim;
trig.childAim = srcTriggerType::noAim;
if (str == "allSide")
trig.childAim = tbTrigger::allSide;
trig.childAim = srcTriggerType::allSide;
if (str == "parentAim")
trig.childAim = tbTrigger::parentAim;
trig.childAim = srcTriggerType::parentAim;
if (str == "nearlestAlien")
trig.childAim = tbTrigger::nearlestAlien;
trig.childAim = srcTriggerType::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);
@@ -726,7 +793,7 @@ void Loader::readMaps()
void Loader::validate(QString filename)
{
QFile sfile("schema.xml");
QFile sfile("schema.xml");
if (!sfile.open(QIODevice::ReadOnly))
qFatal("No file schema.xml found!");
QXmlSchema schema;