19 #include "AssetsManager.h"
24 QGridLayout* layout =
new QGridLayout(
this);
27 layout->addWidget(
new QLabel(tr(
"First fighter:"),
this), line, 0);
29 layout->addWidget(
myFirst, line++, 1);
31 layout->addWidget(
new QLabel(tr(
"Second fighter:"),
this), line, 0);
33 layout->addWidget(
mySecond, line++, 1);
35 layout->addWidget(
new QLabel(tr(
"Number of fights:"),
this), line, 0);
41 layout->addWidget(
new QLabel(tr(
"Maximum number of rounds:"),
this), line, 0);
53 layout->addWidget(
myResult, line++, 0, 1, 2);
55 QDialogButtonBox* box =
new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Close, Qt::Horizontal,
this);
56 layout->addWidget(box, line++, 0, 1, 2);
57 connect(box, SIGNAL(rejected()),
this, SLOT(reject()));
58 connect(box, SIGNAL(accepted()),
this, SLOT(
fight()));
60 setWindowTitle(tr(
"Combat simulator"));
70 object* obfirst = object_create_arch(
const_cast<archetype *
>(first));
71 object* obsecond = object_create_arch(
const_cast<archetype *
>(second));
72 tag_t tagfirst = obfirst->count;
73 tag_t tagsecond = obsecond->count;
76 mapstruct* test_map = get_empty_map(50, 50);
79 obfirst = object_insert_in_map_at(obfirst, test_map, NULL, 0, 12, 12);
80 obsecond = object_insert_in_map_at(obsecond, test_map, NULL, 0, 37, 37);
82 while (limit-- > 0 && obfirst->stats.hp >= 0 && obsecond->stats.hp >= 0)
84 if (obfirst->speed_left > 0) {
85 --obfirst->speed_left;
86 monster_do_living(obfirst);
90 attack_ob(obsecond, obfirst);
91 if (object_was_destroyed(obsecond, tagsecond))
93 if (obsecond->stats.hp <
mySecondMinHp && obsecond->stats.hp > 0)
97 if (obsecond->speed_left > 0) {
98 --obsecond->speed_left;
99 monster_do_living(obsecond);
103 attack_ob(obfirst, obsecond);
104 if (object_was_destroyed(obfirst, tagfirst))
106 if (obfirst->stats.hp <
myFirstMinHp && obfirst->stats.hp > 0)
110 if (obfirst->speed_left <= 0)
111 obfirst->speed_left += FABS(obfirst->speed);
112 if (obsecond->speed_left <= 0)
113 obsecond->speed_left += FABS(obsecond->speed);
118 if (obfirst->stats.hp < 0)
124 if (!object_was_destroyed(obfirst, tagfirst))
126 object_remove(obfirst);
127 object_free(obfirst, 0);
129 if (!object_was_destroyed(obsecond, tagsecond))
131 object_remove(obsecond);
132 object_free(obsecond, 0);
139 QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
155 object* obfirst = object_create_arch(
const_cast<archetype *
>(first));
156 object* obsecond = object_create_arch(
const_cast<archetype *
>(second));
166 object_free(obfirst, 0);
167 object_free(obsecond, 0);
172 fight(first, second);
175 myResult->setText(tr(
"Draw: %1 fights\n%2 victories: %3 (max hp: %4, min hp: %5)\n%6 victories: %7 (max hp: %8, min hp: %9)")
183 QApplication::restoreOverrideCursor();