some bugfix in splashes

This commit is contained in:
2010-08-31 00:12:48 +04:00
parent 2a13131366
commit 92133b9b6d
8 changed files with 152 additions and 53 deletions

View File

@@ -20,7 +20,7 @@ AD_Core::AD_Core(QObject *parent) :
adtowers = new Towers(addata);
adsplashes = new Splashes(addata);
connect(addata->map,SIGNAL(recreateAlienPath(bool*)),adaliens,SLOT(retrace(bool*)));
connect(adtowers,SIGNAL(shot(srcSplashType,int,TowerType)),adsplashes,SLOT(addSplash(srcSplashType,int,TowerType)));
connect(adtowers,SIGNAL(shot(QPoint)),adsplashes,SLOT(addSplash(QPoint)));
// adaliens->addAlien(0);
// adaliens->AddAlien(0);
// adaliens->AddAlien(0);

View File

@@ -58,6 +58,7 @@
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
<value key="QtVersionId" type="int">0</value>
<value key="ToolChain" type="int">0</value>
<value key="addQDumper" type=""></value>
<value key="buildConfiguration" type="int">2</value>
</valuemap>
</data>
@@ -66,6 +67,7 @@
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Release</value>
<value key="QtVersionId" type="int">0</value>
<value key="addQDumper" type=""></value>
<value key="buildConfiguration" type="int">0</value>
</valuemap>
</data>
@@ -166,6 +168,46 @@
<variable>buildconfiguration-Debug-cleanstep0</variable>
<valuemap type="QVariantMap">
<value key="ProjectExplorer.BuildConfiguration.DisplayName" type="QString">Debug</value>
<valuelist key="abstractProcess.Environment" type="QVariantList">
<value type="QString">DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-wExeabp7q4,guid=18815993df3603fdc64a3f6d4c7b5822</value>
<value type="QString">DEFAULTS_PATH=/usr/share/gconf/gnome.default.path</value>
<value type="QString">DESKTOP_SESSION=gnome</value>
<value type="QString">DISPLAY=:0.0</value>
<value type="QString">GDMSESSION=gnome</value>
<value type="QString">GDM_KEYBOARD_LAYOUT=us</value>
<value type="QString">GDM_LANG=ru_RU.UTF-8</value>
<value type="QString">GNOME_DESKTOP_SESSION_ID=this-is-deprecated</value>
<value type="QString">GNOME_KEYRING_CONTROL=/tmp/keyring-4vN5uf</value>
<value type="QString">GTK_MODULES=canberra-gtk-module</value>
<value type="QString">HOME=/home/andrey</value>
<value type="QString">LANG=ru_RU.UTF-8</value>
<value type="QString">LD_LIBRARY_PATH=/usr/lib/qtcreator:</value>
<value type="QString">LOGNAME=andrey</value>
<value type="QString">MANDATORY_PATH=/usr/share/gconf/gnome.mandatory.path</value>
<value type="QString">ORBIT_SOCKETDIR=/tmp/orbit-andrey</value>
<value type="QString">PATH=/usr/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games</value>
<value type="QString">PWD=/home/andrey</value>
<value type="QString">QTDIR=/usr/share/qt4</value>
<value type="QString">SESSION_MANAGER=local/buull-eeePC:@/tmp/.ICE-unix/1205,unix/buull-eeePC:/tmp/.ICE-unix/1205</value>
<value type="QString">SHELL=/bin/bash</value>
<value type="QString">SPEECHD_PORT=6561</value>
<value type="QString">SSH_AGENT_PID=1239</value>
<value type="QString">SSH_AUTH_SOCK=/tmp/keyring-4vN5uf/ssh</value>
<value type="QString">USER=andrey</value>
<value type="QString">USERNAME=andrey</value>
<value type="QString">XAUTHORITY=/var/run/gdm/auth-for-andrey-x9URui/database</value>
<value type="QString">XDG_CONFIG_DIRS=/etc/xdg/xdg-gnome:/etc/xdg</value>
<value type="QString">XDG_DATA_DIRS=/usr/share/gnome:/usr/local/share/:/usr/share/</value>
<value type="QString">XDG_SESSION_COOKIE=f0649decca52f2beb55c9ea74ad1d028-1283151906.338331-318132279</value>
</valuelist>
<value key="abstractProcess.IgnoreReturnValue" type="bool">true</value>
<valuelist key="abstractProcess.arguments" type="QVariantList">
<value type="QString">clean</value>
<value type="QString">-w</value>
</valuelist>
<value key="abstractProcess.command" type="QString">/usr/bin/make</value>
<value key="abstractProcess.enabled" type="bool">true</value>
<value key="abstractProcess.workingDirectory" type="QString">/home/andrey/AD/aliendefender</value>
<value key="cleanConfig" type="bool">true</value>
<valuelist key="makeargs" type="QVariantList">
<value type="QString">clean</value>

View File

@@ -62,6 +62,7 @@ struct srcTriggerType
nearlestAlien
};
int childId; // =-1 for none birth splash (e.q. only damage)
aimType childAim;
bool delParent;
float damage;
float radius;
@@ -72,13 +73,26 @@ struct srcTriggerType
};
struct TriggerType
struct TriggerOnDest
{
int src;
};
struct TriggerOnTimer
{
int src;
unsigned int timer;
};
struct TriggerOnAlien
{
int src;
QList <int> triggerAliens;
};
struct srcSplashType
{
QString name;
@@ -96,12 +110,16 @@ struct SplashType
int imgType;
int src;
QPoint TowerId; // parent tower (-1;-1) for null parent
int srcTower;
int PlayerId;
int AlienId; // aim alien (different from tower.AlienId)
QPointF destination;
int life; // in ticks
float angle; // -180 .. 180
QPointF pos;
QList <TriggerType> triggers;
QList <TriggerOnAlien> trigsOnAlien;
QList <TriggerOnDest> trigsOnDest;
QList <TriggerOnTimer> trigsOnTimer;
};

View File

@@ -372,6 +372,8 @@ void Loader::fillTowerChains(QList <tbChain> * chlist, QList <int> * trigIds, sr
strigt.randomPosRadius = tbtrig.randomPosRadius;
strigt.timer = tbtrig.timer;
strigt.type = tbtrig.type;
strigt.childAim = tbtrig.childAim;
strigt.childId = -1;
stt->triggers.append(strigt);
trigIds->append(trigid);
}

View File

@@ -11,8 +11,11 @@ Splashes::Splashes(Game_Data *gd, QObject *parent) :
bool Splashes::addSplash(int srcId, QPointF pos)
{
qFatal("don't use this function addSplash(int srcId, QPointF pos)");
if (srcId < 0 || srcId >= gameData->srcSplashes.size())
qDebug("don't use this function addSplash(int srcId, QPointF pos)");
return false;
// FIXME: говнокод
// TODO: find and correct errors here
/* if (srcId < 0 || srcId >= gameData->srcSplashes.size())
{
qCritical("ERROR out of splashes range");
return false;
@@ -42,36 +45,61 @@ bool Splashes::addSplash(int srcId, QPointF pos)
}
gameData->curSplashes.insert(spl.id,spl);
nextId++;
return true;
return true;*/
}
void Splashes::addSplash(srcSplashType src, int index, TowerType tw)
void Splashes::addSplash(QPoint curTowerId)
{
SplashType spl;
spl.id = nextId;
spl.TowerId = tw.pos;
if (!gameData->curAliens.contains(tw.aim))
qFatal("Error finding splash aim! Tower has nvalid aim!");
spl.destination = gameData->curAliens.value(tw.aim).pos;
if (src.autoControl)
spl.AlienId = tw.aim;
else
spl.AlienId = -1;
spl.angle = tw.angle; // FIXME: tower not rotate
spl.pos = tw.pos; // FIXME: pos not in center or left-angle of tower
spl.imgType = src.imgType;
spl.life = 0;
spl.src = index;
TriggerType trig;
for(int i=0; i<src.triggerIndexes.size(); i++)
if (gameData->curTowers.contains(curTowerId))
{
trig.timer = gameData->players.at(tw.PlayerId)->srcTowers.at(tw.src).triggers.at(src.triggerIndexes.at(i)).timer;
trig.src = src.triggerIndexes.at(i);
spl.triggers.push_back(trig);
TowerType tw = gameData->curTowers.value(curTowerId);
srcSplashType src = gameData->players.at(tw.PlayerId)->srcTowers.at(tw.src).splashes.at(0);
SplashType spl;
spl.id = nextId;
spl.TowerId = curTowerId;
spl.srcTower = tw.src;
spl.PlayerId = tw.PlayerId;
if (!gameData->curAliens.contains(tw.aim))
qFatal("Error finding splash aim! Tower has nvalid aim!");
spl.destination = gameData->curAliens.value(tw.aim).pos;
if (src.autoControl)
spl.AlienId = tw.aim;
else
spl.AlienId = -1;
spl.angle = tw.angle;
spl.pos = tw.pos; // FIXME: splash do not create in center or left-angle of tower, it must be in tower's side
spl.imgType = src.imgType;
spl.life = 0;
spl.src = 0;
//TriggerType trig;
for(int i=0; i<src.triggerIndexes.size(); i++)
{
srcTriggerType trig;
TriggerOnDest tod;
TriggerOnAlien toa;
TriggerOnTimer tot;
trig = gameData->players.at(tw.PlayerId)->srcTowers.at(tw.src).triggers.at(src.triggerIndexes.at(i));
switch (trig.type)
{
case srcTriggerType::onDestination :
tod.src = src.triggerIndexes.at(i);
spl.trigsOnDest.append(tod);
break;
case srcTriggerType::onAlienInRadius :
toa.src = src.triggerIndexes.at(i);
spl.trigsOnAlien.append(toa);
break;
case srcTriggerType::onTimer :
tot.src = src.triggerIndexes.at(i);
tot.timer = trig.timer;
spl.trigsOnTimer.append(tot);
break;
}
}
gameData->curSplashes.insert(spl.id,spl);
nextId++;
}
gameData->curSplashes.insert(spl.id,spl);
nextId++;
}
@@ -94,30 +122,39 @@ void Splashes::update()
//isTowerSplash = true;
//if (!isTowerSplash)
// src = gameData->srcSplashes.at(spl.src);
if (src.autoControl)
if (src.autoControl)
{
bool badAl = false;
if (gameData->curAliens.contains(spl.AlienId))
spl.destination = gameData->curAliens.value(spl.AlienId).pos;
else
badAl = true;
if (distance2(spl.pos, spl.destination) < src.speed*src.speed)
{
if (distance2(spl.pos, spl.destination) < src.speed*src.speed)
if (badAl)
deadIndexes.push_back(spl.id);
if (gameData->curAliens.contains(spl.AlienId))
spl.destination = gameData->curAliens.value(spl.AlienId).pos;
arctg = std::atan2(spl.pos.x() - spl.destination.x(),spl.pos.y() - spl.destination.y());
//if (tmpdy < 0) arctg=arctg+M_PI;
angl = 180.0f*(-arctg)/M_PI;
spl.angle = angl;
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(arctg));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(arctg));
} else {
if (!gameData->map->rect().contains(spl.pos.toPoint()))
deadIndexes.push_back(spl.id);
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(-spl.angle*M_PI/180.f));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(-spl.angle*M_PI/180.f));
spl.pos = spl.destination;
for (int k=0; k<spl.trigsOnDest.size(); k++)
{
// TODO: activate trigger
}
}
arctg = std::atan2(spl.pos.x() - spl.destination.x(),spl.pos.y() - spl.destination.y());
//if (tmpdy < 0) arctg=arctg+M_PI;
angl = 180.0f*(-arctg)/M_PI;
spl.angle = angl;
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(arctg));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(arctg));
} else {
if (!gameData->map->rect().contains(spl.pos.toPoint()))
deadIndexes.push_back(spl.id);
spl.pos.setX(spl.pos.x()
-src.speed*std::sin(-spl.angle*M_PI/180.f));
spl.pos.setY(spl.pos.y()
-src.speed*std::cos(-spl.angle*M_PI/180.f));
}
// TODO: smooth splash rotate
// TODO: activate trigger and more...
gameData->curSplashes.insert(spl.id,spl);

View File

@@ -14,7 +14,7 @@ public:
signals:
public slots:
void addSplash(srcSplashType src, int index, TowerType tw);
void addSplash(QPoint towerId);
private:
Game_Data *gameData;

View File

@@ -96,7 +96,7 @@ void Towers::update()
if ((*i).aim > 0)
{
(*i).reload = 0;
emit shot(stw.splashes.at(0), 0, (*i));
emit shot((*i).pos);
//qDebug("shot!");
}
}

View File

@@ -12,7 +12,7 @@ public:
void delTower(QPoint pos);
void update();
signals:
void shot(srcSplashType src, int index, TowerType tw);
void shot(QPoint towerId);
public slots:
private: