#include <iostream>
#include <stdio.h>
#include <cstring>
#include <string.h>
#include <fstream>
using namespace std;
int m=0,n=0,k=0,r=0,t=0;
const string name[5] = {"dragon", "ninja", "iceman", "lion", "wolf"};
const int makinglist[2][5] = {2,3,4,1,0,3,0,1,2,4};
int warriorlife[5]={0};
int warriorattack[5]={0};
int templife[2] ={0};
const string warriorcolor[2] = {"red", "blue"};
int totallife[2]={0};
bool lastcolor[2]={0};
bool headnum[2]={0};
int totalnum[2]={0};
bool gameover = 0;
int hour = 0;
class sword
{
private:
int attacks;
public:
sword(int a):attacks(a){}
void getdull(){attacks = int (attacks * 0.8);}
bool destroy(){return (attacks == 0);}
int getattacks()
{
return attacks;
}
};
class arrow
{
public:
int times;
int attacks;
arrow(int a,int b)
{
times = a;
attacks = b;
}
void used()
{
times--;
}
bool destroyed(){return (times ==0);}
};
class warrior
{
public:
int color;
int warriorno;
int kind;
int hp;
int attack;
arrow *arrows;
sword *swords;
bool bomb;
public:
friend class city;
warrior(int a,int b,int c)
{
color = a;
warriorno = b;
kind = c;
hp = warriorlife[kind];
attack = warriorattack[kind];
totallife[color] -= warriorlife[kind];
printf("0%02d:00 %s %s %d born\n",hour,warriorcolor[color].c_str(),name[kind].c_str(),warriorno);
arrows = NULL;
swords = NULL;
bomb = false;
switch(c)
{
case 0:case 2:
if (b % 3 ==0)
if ((int)(attack*0.2)!=0)
swords = new sword((int)(attack * 0.2));
if (b % 3 ==1)
bomb = true;
if (b % 3 == 2)
arrows = new arrow(3,r);
break;
case 1:
if (b % 3 ==0)
{
if ((int)(attack*0.2)!=0)
swords = new sword((int)(attack * 0.2));
bomb = true;
}
if (b % 3 ==1)
{
bomb = true;
arrows = new arrow(3,r);
}
if (b % 3 == 2)
{
arrows = new arrow(3,r);
if ((int)(attack*0.2)!=0)
swords = new sword((int)(attack * 0.2));
}
break;
default:
break;
}
}
~warrior()
{
if (swords!=NULL) delete swords;
if (arrows!=NULL) delete arrows;
}
virtual bool escape() {return false;}
virtual double getmorale() {}
virtual void changemorale(int) {}
virtual void changeloyalty() {}
void get_hp(int a) {hp += a;}
} ;
//warrior *p[2][1000];
class dragon:public warrior
{
private:
double morale;
public:
dragon(int a,int b,int c):warrior(a,b,c)
{
morale = double (totallife[a])/warriorlife[0];
printf("Its morale is %.2lf\n",morale);
}
// void yell(int no_)
// {
// }
double getmorale( )
{
return morale;
}
void changemorale(int s)
{
if (s == 1)
morale += 0.2;
else
morale -= 0.2;
}
};
class lion:public warrior
{
private:
int loyalty;
public:
lion(int a,int b,int c):warrior(a,b,c)
{
loyalty = totallife[a];
printf("Its loyalty is %d\n",loyalty);
}
bool escape()
{
if (loyalty <= 0)
return 1;
else
return 0;
}
void changeloyalty()
{
loyalty -= k;
}
};
class city
{
private:
int no;
int color;
int life;
int lastwin;
int nowwin;
public:
warrior *ct[2];
~city()
{
for (int i=0;i<=1;i++)
if (ct[i]!=NULL)
delete ct[i];
}
int getlastwin()
{
return nowwin;
}
void shootarrow(city *next,int color_)
{
if (ct[color_] == NULL)
return;
if (ct[color_] -> arrows!=NULL && next->ct[1-color_]!=NULL)
{
next->ct[1-color_]->hp -= ct[color_]->arrows->attacks;
ct[color_]->arrows -> used();
if (ct[color_]->arrows->destroyed())
{
delete ct[color_]->arrows;
ct[color_]->arrows=NULL;
}
printf("0%02d:35 %s %s %d shot",hour,warriorcolor[color_].c_str(),name[ct[color_]->kind].c_str(),ct[color_]->warriorno);
if (next->ct[1-color_]->hp<=0)
{
//next.ct[1-color_]->hp=0;
printf(" and killed %s %s %d",warriorcolor[1-color_].c_str(),name[next->ct[1-color_]->kind].c_str(),next->ct[1-color_]->warriorno);
}
printf("\n");
}
}
void bombuse()
{
int mark = 1;
int addattack = 0;
if (ct[0]==NULL||ct[1]==NULL||ct[0]->hp<=0||ct[1]->hp<=0)
return;
if (color == 0 ||(color == -1&&no%2==1))
mark = 0;
if (ct[mark]->swords!=NULL)
addattack = ct[mark]->swords->getattacks();
if (ct[1 - mark]->hp <= ct[mark]->attack + addattack)
{
if (ct[1 - mark] ->bomb)
{
printf("0%02d:38 %s %s %d used a bomb and killed %s %s %d\n",hour,warriorcolor[1-mark].c_str(),
name[ct[1-mark]->kind].c_str(),ct[1-mark]->warriorno,warriorcolor[mark].c_str(),name[ct[mark]->kind].c_str(),ct[mark]->warriorno);
delete ct[0],ct[1];
ct[0] = ct[1] = NULL;
}
return;
}
addattack=0;
if (ct[1-mark]->swords!=NULL)
addattack=ct[1-mark]->swords->getattacks();
if (ct[1-mark]->kind==1)
return;
if (ct[mark]->hp <= (ct[1 - mark]->attack) / 2 + addattack)
{
if (ct[mark] ->bomb)
{
printf("0%02d:38 %s %s %d used a bomb and killed %s %s %d\n",hour,warriorcolor[mark].c_str(),
name[ct[mark]->kind].c_str(),ct[mark]->warriorno,warriorcolor[1-mark].c_str(),name[ct[1-mark]->kind].c_str(),ct[1-mark]->warriorno);
delete ct[0],ct[1];
ct[0] = ct[1] = NULL;
}
return;
}
}
void battle()
{
int mark = 1;
nowwin = -1;
int leftlife = 0;
int addattack = 0;
if (color == 0 ||(color == -1&&no%2==1))
mark = 0;
if (ct[0]==NULL)
{
if (ct[1]!=NULL && ct[1]->hp<=0)
{
delete ct[1];
ct[1]=NULL;
}
return;
}
if (ct[1]==NULL)
{
if (ct[0]!=NULL && ct[0]->hp<=0)
{
delete ct[0];
ct[0]=NULL;
}
return;
}
if (ct[mark]->hp <= 0 && ct[1-mark]->hp <= 0)
{
delete ct[0];
delete ct[1];
ct[0] = ct[1] = NULL;
return;
}
if (ct[mark]->hp<=0)
{
killeffect(1-mark,0,0);
return;
}
if (ct[1-mark]->hp<=0)
{
killeffect(mark,0,1);
return;
}
printf("0%02d:40 %s %s %d ",hour,warriorcolor[mark].c_str(),name[ct[mark]->kind].c_str(),ct[mark]->warriorno);
printf("attacked %s %s %d in