void Player::reset()
{
- delete this;
- name = new char[64];
- password = new char[256];
- name[0] = '\0';
- password[0] = '\0';
+ memset(name, 0, 255);
+ memset(password, 0, 255);
exp = 1;
gold = 0;
weapon = 1;
level = 1;
alive = 1;
- started = 1; // Possibly deprecated
forest_fights = 100;
player_fights = 3;
fight = NULL;
master = NULL;
battle = NULL;
+ flags = 0;
}
Player::Player(aClient *user)
{
+ name = new char[256];
+ password = new char[256];
+
if (user)
{
- if (user->stats)
- setData(user->stats);
- else
- reset(); // Set Defaults
-
- strcpy(name, user->getNick());
+ setData(user->stats);
+ strcpy(name, user->getNick());
}
else
- {
- reset(); // Set default properties
- int num = rand() % 32767;
- sprintf(name, "Player%d", num);
- }
+ setData(NULL);
+
cout << "New Player: " << name << endl << flush;
}
+
Player::Player(char *n)
{
+ name = new char[256];
+ password = new char[256];
+
reset(); // Set defaults
strcpy(name, n);
Player::~Player()
{
+ cout << "Deleting player";
+
if (name)
- delete name;
+ {
+ cout << ": " << name;
+ delete [] name;
+ }
if (password)
- delete password;
+ {
+ cout << " Password: " << password;
+ delete [] password;
+ }
+ cout << endl << "Player Deleted";
}
void Player::setData(Player *right)
if (right)
{
strcpy(name, right->name);
- strcpy(password, right->password);
-
+ strcpy(password, right->password);
exp = right->exp;
gold = right->gold;
bank = right->bank;
weapon = right->weapon;
level = right->level;
alive = right->alive;
- started = right->started; // Possibly obsoleted
forest_fights = right->forest_fights;
player_fights = right->player_fights;
- cout << "Setting Player data for " << right->name << endl;
+ flags = right->flags;
+ }
+ else
+ {
+ reset();
+
+ int num = rand() % 32767;
+ sprintf(name, "Player%d", num);
}
+
+ cout << "Setting Player data for " << name << endl;
}
-const Player &Player::operator=( const Player &right )
+monster_::~monster_()
{
- if (&right != this)
- {
- strcpy(name, right.name);
- strcpy(password, right.password);
- exp = right.exp;
- gold = right.gold;
- bank = right.bank;
- hp = right.hp;
- maxhp = right.maxhp;
- strength = right.strength;
- defense = right.defense;
- armor = right.armor;
- weapon = right.weapon;
- level = right.level;
- alive = right.alive;
- started = right.started; // Possibly obsoleted
- forest_fights = right.forest_fights;
- player_fights = right.player_fights;
- }
- return *this; // Enables Cascading ( x = y = z;)
+ delete name;
+ delete weapon;
+ delete death;
+}
+
+monster_::monster_()
+{
+ name = new char[32];
+ weapon = new char[32];
+ death = new char[256];
+
+ memset(name, 0, 32);
+ memset(weapon, 0, 32);
+ memset(death, 0, 256);
+}
+
+monster_::monster_(monster_ *m)
+{
+ name = new char[strlen(m->name) + 1];
+ weapon = new char[strlen(m->weapon) + 1];
+ death = new char[strlen(m->death) + 1];
+
+ strcpy(name, m->name);
+ strcpy(weapon, m->weapon);
+ strcpy(death, m->death);
+
+ strength = m->strength;
+ maxhp = m->maxhp;
+ hp = m->hp;
+ gold = m->gold;
+ exp = m->exp;
+}
+
+long int Player::setFlags(long int newflags)
+{
+ flags = newflags;
+ return getFlags();
}
+
+long int Player::addFlag(long int flag)
+{
+ flags |= flag;
+ return getFlags();
+}
+
+long int Player::remFlag(long int flag)
+{
+ flags &= ~flag;
+ return getFlags();
+}
+