cosmetix
[k8-i-v-a-n.git] / src / game / team.cpp
blobf1eb578b9b6966519eb5c1e4e695f1824e20f935
1 /*
3 * Iter Vehemens ad Necem (IVAN)
4 * Copyright (C) Timo Kiviluoto
5 * Released under the GNU General
6 * Public License
8 * See LICENSING which should be included
9 * along with this file for more details
13 /* Compiled through charset.cpp */
16 team::team() : Leader(0), ID(0), KillEvilness(0) {
17 //fprintf(stderr, "team:team()!!!\n");
21 team::team(feuLong aID) : Leader(0), ID(aID), KillEvilness(0) {
22 //fprintf(stderr, "team:team(%u)\n", ID);
26 void team::Save (outputfile &SaveFile) const {
27 SaveFile << ID << Relation << KillEvilness << Name;
31 void team::Load (inputfile &SaveFile) {
32 SaveFile >> ID >> Relation >> KillEvilness >> Name;
36 std::list<character *>::iterator team::Add (character *Char) {
37 return Member.insert(Member.end(), Char);
41 void team::SetRelation (team *AnotherTeam, int Relation) {
42 this->Relation[AnotherTeam->ID] = AnotherTeam->Relation[ID] = Relation;
46 int team::GetRelation (const team *AnotherTeam) const {
47 if (AnotherTeam != this) {
48 std::map<feuLong, int>::const_iterator Iterator = Relation.find(AnotherTeam->ID);
49 if (Iterator != Relation.end()) return Iterator->second;
50 ABORT("Team %u dismissed! (%u) %p %p", AnotherTeam->ID, ID, AnotherTeam, this);
52 return FRIEND;
56 void team::Hostility (team *Enemy) {
57 /* We're testing if the game works better this way... */
58 if (ID != PLAYER_TEAM) return;
59 if (this != Enemy && GetRelation(Enemy) != HOSTILE) {
60 if (ID == PLAYER_TEAM && game::IsSumoWrestling()) game::EndSumoWrestling(DISQUALIFIED);
61 /* This is a gum solution. The behaviour should come from the script. */
62 /*if (ID == COLONIST_TEAM && Enemy->ID == NEW_ATTNAM_TEAM) return;*/
63 game::Hostility(this, Enemy);
64 if (ID == PLAYER_TEAM) {
65 if (Enemy->ID == ATTNAM_TEAM) {
66 /* This is a gum solution. The message should come from the script. */
67 if (PLAYER->CanHear()) ADD_MESSAGE("You hear an alarm ringing.");
68 if (game::GetStoryState() != 2) {
69 v2 AngelPos = game::GetPetrus() ? game::GetPetrus()->GetPos() : v2(28, 20);
70 int Seen = 0;
71 angel *Angel;
73 for (int c = 0; c < 3; ++c) {
74 if (!c) Angel = archangel::Spawn(VALPURUS); else Angel = angel::Spawn(VALPURUS);
76 v2 Where = game::GetCurrentLevel()->GetNearestFreeSquare(Angel, AngelPos);
78 if (Where == ERROR_V2) Where = game::GetCurrentLevel()->GetRandomSquare(Angel);
79 Angel->SetTeam(Enemy);
80 Angel->PutTo(Where);
81 if (Angel->CanBeSeenByPlayer()) ++Seen;
83 if (Seen == 1) ADD_MESSAGE("%s materializes.", Angel->CHAR_NAME(INDEFINITE));
84 else if (Seen == 2) ADD_MESSAGE("Two %s materialize.", Angel->CHAR_NAME(PLURAL));
85 else if (Seen == 3) ADD_MESSAGE("Three %s materialize.", Angel->CHAR_NAME(PLURAL));
86 ADD_MESSAGE("\"We will defend the Holy Order!\"");
89 ADD_MESSAGE("You have a feeling this wasn't a good idea...");
91 SetRelation(Enemy, HOSTILE);
96 truth team::HasEnemy () const {
97 for (int c = 0; c < game::GetTeams(); ++c) {
98 if (!game::GetTeam(c)->GetMember().empty() && GetRelation(game::GetTeam(c)) == HOSTILE) return true;
100 return false;
104 int team::GetEnabledMembers () const {
105 int Amount = 0;
107 for (std::list<character*>::const_iterator i = Member.begin(); i != Member.end(); ++i) if ((*i)->IsEnabled()) ++Amount;
108 return Amount;
112 void team::MoveMembersTo (charactervector &CVector) {
113 for (std::list<character *>::iterator i = Member.begin(); i != Member.end(); ++i) {
114 if ((*i)->IsEnabled()) {
115 if ((*i)->GetAction() && (*i)->GetAction()->IsVoluntary()) (*i)->GetAction()->Terminate(false);
116 if (!(*i)->GetAction()) { CVector.push_back(*i); (*i)->Remove(); }
122 void team::Remove (std::list<character *>::iterator Iterator) {
123 if (*Iterator == Leader) Leader = 0;
124 Member.erase(Iterator);
128 outputfile &operator << (outputfile &SaveFile, const team *Team) {
129 Team->Save(SaveFile);
130 return SaveFile;
134 inputfile &operator >> (inputfile &SaveFile, team *&Team) {
135 Team = new team;
136 Team->Load(SaveFile);
137 return SaveFile;