connect(m_TickView, SIGNAL(ticksChanged(int,int)), m_FleetView, SLOT(slotViewTickRange(int,int)));
m_FleetViews->addWidget(m_FleetView, 1);
}
+ m_FleetViews->raiseWidget(2);
m_FleetViews->raiseWidget(1);
}
}
for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
{
- m_Fleet[i->first][0] += (*j)->fleet(i->first, tick);
+ int num = (*j)->fleet(i->first, tick);
+ m_Fleet[i->first][0] += num;
+ if (num > 0)
+ cerr << (*j)->name() << " adding " << num << " units of type " << i->first << endl;
}
}
}
cerr << "Distributing type: " << unittype << " with a total loss of " << totallost << " units" << endl;
+
+ cerr << "Total number of units before: " << fleet(unittype, 0) << " and after : " << fleet(unittype, 1) << endl;
for (vector<Fleet*>::iterator j = fleets.begin(); j != fleets.end(); ++j)
{
- int lost = totallost * ( (*j)->fleet(unittype, tick - 1) / m_Fleet[unittype][0] );
- cerr << (*j)->name() << " gaining " << lost << " " << unittype << endl;
+ int fl1 = (*j)->fleet(unittype, tick - 1);
+ float part = float(fl1) / fleet(unittype, 0) ;
+ int lost = totallost * part;
+ cerr << (*j)->name() << " gaining " << lost << " " << unittype << " since it's " << part * 100 << "% of the whole fleet, and it had : " << fl1 << " units last tick.." << endl;
(*j)->setFleet(unittype, (*j)->fleet(unittype, tick - 1) + lost, tick);
}
}
void Fleet::takeShoot(std::string unittype, int number, std::map<std::string, int>& hitunits)
{
- int guns = s_Units[unittype].guns() * number;
+ float guns = s_Units[unittype].guns() * number;
+
+ cerr << number << " " << unittype << ": with " << guns << " guns\n";
+
if (guns == 0)
return;
cerr << unittype << ": with " << guns << " guns\n";
- int gunsleft = guns;
+ float gunsleft = guns;
for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
{
string ta = s_Units[unittype].target(count);
for (map<string, int*>::iterator j = targets.begin(); j != targets.end(); ++j)
{
- int maxguns = (*j->second)/total * guns;
- cerr << "Now shooting at target: " << j->first << endl;
+ float maxguns = float((*j->second))/total * guns;
+ //cerr << "Now shooting at target: " << j->first << endl;
if (m_Armor[j->first] <= 0 || m_Armor[j->first] > s_Units[j->first].armor())
m_Armor[j->first] = s_Units[j->first].armor();
double k = maxguns;
- cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
- cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
+ //cerr << "Targets agility: " << s_Units[j->first].agility() << endl;
+ //cerr << "Weaponspeed: " << s_Units[unittype].weaponSpeed() << endl;
while (k > 0)
{
cerr << unittype << ": with " << guns << " guns\n";
- int gunsleft = guns;
+ float gunsleft = guns;
for (int count = 0; count < 3; ++count)//vector<string>::iterator i = s_Units[unittype].target().begin(); i != s_Units[unittype].target().end(); ++i)
{
string ta = s_Units[unittype].target(count);
//
void Fleet::killFleet(std::string unittype, int number, int tick = 0)
{
- if (m_Fleet[unittype].size() <= tick)
+ int earlier = 0;
+ int ticks = m_Fleet[unittype].size();
+
+ if (ticks != 0)
+ earlier = m_Fleet[unittype][ticks - 1];
+
+ for (int i = ticks; i <= tick; ++i)
{
- m_Fleet[unittype].push_back(m_Fleet[unittype][m_Fleet[unittype].size()] - number);
- return;
+ m_Fleet[unittype].push_back(earlier);
}
m_Fleet[unittype][tick] -= number;
}
{
m_Fleet = new Fleet(*fleet);
}
- m_Fleet->printFleet();
+ //m_Fleet->printFleet();
fillTable();
}
int after = m_Fleet->fleet(i->latin1(), m_iMaxTick);
m_UnitsLostSurvivedView[(*i)]->setText(QString("%1").arg(after - before));
}
+
+ Planet* pl;
+ if ((pl = dynamic_cast<Planet*>(m_Fleet)))
+ {
+ int lost;
+ int before;
+ int after;
+
+ before = pl->roids(tr("metal").latin1(),m_iMinTick);
+ after = pl->roids(tr("metal").latin1(),m_iMaxTick);
+ lost = after - before;
+ m_RoidsEditView->slotSetLost(tr("metal"),lost);
+
+ before = pl->roids(tr("crystal").latin1(),m_iMinTick);
+ after = pl->roids(tr("crystal").latin1(),m_iMaxTick);
+ lost = after - before;
+ m_RoidsEditView->slotSetLost(tr("crystal"),lost);
+
+ before = pl->roids(tr("eonium").latin1(),m_iMinTick);
+ after = pl->roids(tr("eonium").latin1(),m_iMaxTick);
+ lost = after - before;
+ m_RoidsEditView->slotSetLost(tr("eonium"),lost);
+
+ before = pl->roids(tr("uninit").latin1(),m_iMinTick);
+ after = pl->roids(tr("uninit").latin1(),m_iMaxTick);
+ lost = after - before;
+ m_RoidsEditView->slotSetLost(tr("uninit"),lost);
+ }
}
if( ticks == 0)
return 0;
+ --ticks;
if (ticks < tick)
return roids->at(ticks);
return roids->at(tick);
//////////////////////////////////////////////////////////////////////////
//
-void Planet::setRoids(std::string type, int number)
+void Planet::setRoids(std::string type, int number, int tick = 0)
{
- if (m_Roids[type].size() == 0)
- m_Roids[type].push_back(number);
- m_Roids[type][0] = number;
+ int ticks = m_Roids[type].size();
+ int roids = 0;
+ if (m_Roids[type].size() > 0)
+ roids = m_Roids[type][m_Roids[type].size() - 1];
+
+ for (int i = ticks; i <= tick; ++i )
+ m_Roids[type].push_back(roids);
+ m_Roids[type][tick] = number;
}
+//////////////////////////////////////////////////////////////////////////
+//
+void Planet::takeRoids(std::string type, int number, int tick = 0)
+{
+ int ticks = m_Roids[type].size();
+ int roids = 0;
+ if (m_Roids[type].size() > 0)
+ roids = m_Roids[type][m_Roids[type].size() - 1];
+
+ for (int i = ticks; i <= tick; ++i )
+ m_Roids[type].push_back(roids);
+ m_Roids[type][tick] -= number;
+}
+
+
+
//////////////////////////////////////////////////////////////////////////
//
void Planet::runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile)
skipped = 0;
Planet allFriends;
- allFriends.addToThis(friends, tick);
+ allFriends.addToThis(friends, tick - 1);
+
+ /*for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+ allFriends.setRoids(i->first, roids(i->first, tick));
+
+ allFriends.setPlanetScore(m_iScore);*/
Fleet allHostiles;
- allHostiles.addToThis(hostiles, tick);
+ allHostiles.addToThis(hostiles, tick - 1);
map<string, map<string, int> > stealfriendly;
map<string, map<string, int> > stealhostile;
- calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile );
+ calcOneTick(&allFriends, &allHostiles, stealfriendly, stealhostile, tick );
//allFriends.printFleet();
allFriends.distributeLossesGains(friends, tick);
allHostiles.distributeLossesGains(hostiles, tick);
+
+ /* for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+ setRoids(i->first, roids(i->first, 1), tick);*/
+ }
+
+ for (RoidList::iterator i = m_Roids.begin(); i != m_Roids.end(); ++i)
+ {
+ for (vector<int>::iterator j = i->second.begin(); j != i->second.end(); ++j)
+ cout << i->first << " roids : " << (*j) << endl;
}
}
//////////////////////////////////////////////////////////////////////////
//
-void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >& stealhostile )
+void Planet::calcOneTick(Planet* friendly, Fleet* hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >& stealhostile, int tick = 0)
{
map<int, string> unitsinit; // order units after their ininitiative
for (UnitList::iterator i = s_Units.begin(); i != s_Units.end(); ++i)
if (s_Units[unittype].type() == "Pod")
{
- float capping = friendly->m_iScore / hostile->score() / 10;
- for (RoidList::iterator roids = m_Roids.begin(); roids != m_Roids.end(); ++roids)
+ if (m_iScore <= 0) break;
+ float capping = float(m_iScore) / hostile->score() / 10;
+
+ cerr << "Capping is: " << capping << endl;
+
+ if (capping > 0.15)
+ capping = 0.15;
+ if (capping <= 0)
+ break;
+
+ for (RoidList::iterator roid = m_Roids.begin(); roid != m_Roids.end(); ++roid)
{
- int caproids = capping * roids->second[0];
+ int caproids = capping * roids(roid->first, tick - 1);
int freepods = hostiletemp->freeFleet(unittype, 1);
+
+ cerr << "Possible to steal " << caproids << " " << roid->first << " roids\n";
+ cerr << freepods << " free pods available\n";
- if (freepods == 0)
+ if (freepods <= 0)
break;
if (freepods < caproids)
- caproids = caproids - freepods;
+ caproids = freepods;
+
+ cerr << caproids << " roids stolen\n";
- roids->second.push_back(roids->second[0] - caproids);
+ takeRoids(roid->first, caproids, tick);
+
hostiletemp->killFleet(unittype, caproids, 1);
+ int totroids = caproids + hostiletemp->resource(roid->first, 0);
+ hostiletemp->setResource(roid->first, totroids, 1);
+
+ cerr << totroids << " stolen " << roid->first << " roids\n";
}
}
void setPlanetScore(unsigned i);
int roids(std::string type, int tick = 0) const;
- void setRoids(std::string type, int number);
+ void setRoids(std::string type, int number, int tick = 0);
+ void takeRoids(std::string type, int number, int tick = 0);
void runBattle(std::vector<Fleet*> friendly, std::vector<Fleet*> hostile);
protected:
- void calcOneTick(Planet* friendly, Fleet* Hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >& stealhostile );
+ void calcOneTick(Planet* friendly, Fleet* Hostile, std::map<std::string, std::map<std::string, int> >& stealfriendly, std::map<std::string, std::map<std::string, int> >& stealhostile, int tick = 0);
unsigned m_iScore;
RoidList m_Roids;
<property name="geometry">
<rect>
<x>0</x>
- <y>0</y>
- <width>198</width>
- <height>89</height>
+ <y>11</y>
+ <width>222</width>
+ <height>105</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy>
<hsizetype>5</hsizetype>
- <vsizetype>5</vsizetype>
+ <vsizetype>4</vsizetype>
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
+ <property name="minimumSize">
+ <size>
+ <width>0</width>
+ <height>105</height>
+ </size>
+ </property>
<property name="caption">
<string>QGroupBoxForm</string>
</property>
<cstring>unnamed</cstring>
</property>
<property name="margin">
- <number>5</number>
+ <number>11</number>
</property>
<property name="spacing">
- <number>2</number>
+ <number>6</number>
</property>
<widget class="QLabel" row="0" column="1">
<property name="name">
<property name="name">
<cstring>eoniumLabel</cstring>
</property>
+ <property name="frameShape">
+ <enum>MShape</enum>
+ </property>
<property name="text">
<string>Eonium</string>
</property>
<slots>
<slot>init()</slot>
<slot>setValue( const QString & type, unsigned value )</slot>
- <slot access="protected">slotValueChanged( const QString & s )</slot>
+ <slot>slotValueChanged( const QString & s )</slot>
+ <slot>slotSetLost( QString type, int i )</slot>
</slots>
<pixmapinproject/>
<layoutdefaults spacing="0" margin="2"/>
type = tr("score");
test = type;
emit changed(type, s.toInt());
+}
+
+
+void RoidsEditView::slotSetLost( QString type, int i )
+{
+ if (type == tr("metal"))
+ MetalLostEdit->setText(QString("%1").arg(i));
+ else if (type == tr("crystal"))
+ CrystalLostEdit->setText(QString("%1").arg(i));
+ else if (type == tr("eonium"))
+ EoniumLostEdit->setText(QString("%1").arg(i));
+ else if (type == tr("uninit"))
+ UninitLostEdit->setText(QString("%1").arg(i));
+ /*else if (type == tr("score"))
+ ScoreEdit->setText(QString("%1").arg(i));
+ */
}
\ No newline at end of file