/* * Copyright (C) 2002-2007 The Warp Rogue Team * Part of the Warp Rogue Project * * This software is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License. * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY. * * See the license.txt file for more details. */ /* * Module Name: Party * Description: - */ #define Uses_Character #define Uses_Perks #define Uses_Area #define Uses_Actions #define Uses_Util #define Uses_Object #define Uses_Ai #include "mheader.h" #include "party.h" static void party_reorder(void); /* * list of all characters in the player's party */ static LIST * PlayerParty = NULL; /* * party module init */ void party_init(void) { PlayerParty = list_new(); } /* * party module clean up */ void party_clean_up(void) { if (PlayerParty == NULL) { return; } list_free(PlayerParty); } /* * returns a list of all characters in the player's party */ LIST * party_player(void) { return PlayerParty; } /* * makes a character join the player's party */ void party_join(CHARACTER *character) { battle_tactics_join(character); leader_join(character); character->party = PARTY_PLAYER; ai_set_state(character, AI_STATE_FOLLOW); ai_set_default_state(character, AI_STATE_FOLLOW); list_add(PlayerParty, character); party_reorder(); } /* * makes a character leave the player's party */ void party_leave(CHARACTER *character) { character->party = PARTY_NIL; ai_set_state(character, character->ai.original_state); ai_set_default_state(character, character->ai.original_state); list_remove(PlayerParty, character); battle_tactics_leave(character); leader_leave(character); party_reorder(); } /* * returns the number of characters in the player's party */ PARTY_SIZE party_n_members(void) { if (PlayerParty == NULL) { return 0; } return PlayerParty->n_nodes; } /* * returns true if the passed character is a member of the player's party */ bool party_is_member(const CHARACTER *character) { if (character->party == PARTY_PLAYER) return true; return false; } /* * sets the AI tactic of the player's party */ void party_set_tactic(AI_TACTIC tactic) { LIST_NODE *node; CHARACTER *character; for (node = PlayerParty->head; node != NULL; node = node->next) { character = (CHARACTER *)node->data; if (is_player_controlled_character(character)) { continue; } ai_set_tactic(character, tactic); } } /* * returns the power rating of the player's party */ POWER_RATING party_power_rating(void) { LIST_NODE *node; CHARACTER *character; POWER_RATING party_power; party_power = 0; for (node = PlayerParty->head; node != NULL; node = node->next) { POWER_RATING character_power; character = (CHARACTER *)node->data; character_power = character_power_rating(character); if (character_power > party_power) { party_power = character_power; } } return party_power; } /* * returns true if the player's party contains at least * one character who has the 'Battle tactics' perk */ bool party_has_battle_tactics(void) { LIST_NODE *node; CHARACTER *character; bool has_tactics; has_tactics = false; for (node = PlayerParty->head; node != NULL; node = node->next) { character = (CHARACTER *)node->data; if (character->perk[PK_BATTLE_TACTICS]) { has_tactics = true; break; } } return has_tactics; } /* * returns true if the player's party contains at least * one character who has the 'Leader' perk */ bool party_has_leader(void) { LIST_NODE *node; CHARACTER *character; bool has_leader; has_leader = false; for (node = PlayerParty->head; node != NULL; node = node->next) { character = (CHARACTER *)node->data; if (character->perk[PK_LEADER]) { has_leader = true; break; } } return has_leader; } /* * switches to another party character */ void switch_character(CHARACTER_TYPE character_type) { LIST_NODE *node; for (node = PlayerParty->head; node != NULL; node = node->next) { CHARACTER *character; character = (CHARACTER *)node->data; if (character->type == character_type) { set_player_controlled_character(character); break; } } } /* * returns the amount of money it costs to recruit the passed character */ MONEY recruiting_cost(const CHARACTER *character) { LIST_NODE *node; MONEY cost; cost = 0; for (node = character->inventory->head; node != NULL; node = node->next) { const OBJECT *object; const OBJECT_DATA *object_data; object = (const OBJECT *)node->data; object_data = object_static_data(object); if (object_data->type == OTYPE_MONEY) { cost += object->charge; } else { cost += object_data->value; } } return cost; } /* * reorders player's party */ static void party_reorder(void) { LIST_NODE *node; CHARACTER *character; bool first_npc; for (node = PlayerParty->head, first_npc = true; node != NULL; node = node->next) { character = (CHARACTER *)node->data; if (character->type == CT_PC) { continue; } if (first_npc) { character->type = CT_PARTY_NPC_1; first_npc = false; } else { character->type = CT_PARTY_NPC_2; } } }