/*! \brief Combine items quantities * * Join like items into groups of nine or less. */ static void join_items(void) { unsigned short t_inv[NUM_ITEMS + 1]; int a; for (a = 0; a < NUM_ITEMS; a++) { t_inv[a] = 0; } for (a = 0; a < MAX_INV; a++) { /* foreach instance of item, put the quantity into a temp * inventory then remove that item from the real inventory */ t_inv[g_inv[a][0]] += g_inv[a][1]; g_inv[a][0] = 0; g_inv[a][1] = 0; } for (a = 1; a < NUM_ITEMS; a++) { // While there is something in the temp inventory while (t_inv[a] > 0) { if (t_inv[a] > MAX_ITEMS) { // Portion out 9 items per slot check_inventory(a, MAX_ITEMS); t_inv[a] -= MAX_ITEMS; } else { // Portion out remaining items into another slot check_inventory(a, t_inv[a]); t_inv[a] = 0; } } } }
void get_options(struct opt_info **options, struct player_info *player, int *option_count) { int i, j; int fit; *option_count = 0; for (i = 0; i < player->location->header.opt_count; i++) { fit = 1; for (j = 0; j < player->location->options[i].header.inv_count; j++) { if (!check_inventory(player, &player->location->options[i].inventory[j])) { fit = 0; break; } } if (!fit) continue; options[(*option_count)++] = &player->location->options[i]; } }
/*! \brief Activate the special skill * * This function activates the special skill for a hero, * including targetting etc. if required. * * \param attack_fighter_index Hero to process * \returns 1 if the skill was used, otherwise 0 */ int skill_use(size_t attack_fighter_index) { int tgt, found_item, a, b, c, p, cts, tx, ty, next_target = 0, nn[NUM_FIGHTERS]; size_t enemy_index; size_t fighter_index; std::unique_ptr<Raster> temp; tempa = Magic.status_adjust(attack_fighter_index); switch (pidx[attack_fighter_index]) { case SENSAR: tgt = select_enemy(attack_fighter_index, TGT_ENEMY_ONE); if (tgt == -1) { return 0; } enemy_index = (unsigned int)tgt; temp = std::unique_ptr<Raster>(new Raster(320, 240)); blit(Combat.backart, temp.get(), 0, 0, 0, 0, 320, 240); Draw.color_scale(temp.get(), Combat.backart, 16, 31); b = fighter[attack_fighter_index].mhp / 20; strcpy(attack_string, _("Rage")); display_attack_string = 1; tempa.stats[eStat::Attack] = fighter[attack_fighter_index].stats[eStat::Attack]; tempa.stats[eStat::Hit] = fighter[attack_fighter_index].stats[eStat::Hit]; if (fighter[enemy_index].crit == 1) { tempa.stats[eStat::Attack] += b; tempa.stats[eStat::Hit] += b; } Combat.fight(attack_fighter_index, enemy_index, 1); if (fighter[enemy_index].IsDead()) { for (fighter_index = PSIZE; fighter_index < PSIZE + Combat.GetNumEnemies(); fighter_index++) { if (fighter[fighter_index].IsAlive()) { nn[next_target] = fighter_index; next_target++; } } if (next_target > 0) { enemy_index = nn[kqrandom->random_range_exclusive(0, next_target)]; Combat.fight(attack_fighter_index, enemy_index, 1); } } fighter[attack_fighter_index].hp -= (b * 2); Combat.AdjustHealth(attack_fighter_index, b * 2); display_attack_string = 0; blit(temp.get(), Combat.backart, 0, 0, 0, 0, 320, 240); Effects.display_amount(attack_fighter_index, FONT_DECIDE, 0); if (fighter[attack_fighter_index].IsAlive() && fighter[attack_fighter_index].hp <= 0) { Combat.fkill(attack_fighter_index); Effects.death_animation(attack_fighter_index, 0); } break; case SARINA: fighter[attack_fighter_index].ctmem = 1000; strcpy(attack_string, _("Sweep")); display_attack_string = 1; tempa.stats[eStat::Attack] = tempa.stats[eStat::Attack] * 75 / 100; fighter[attack_fighter_index].aframe = 6; Combat.UnsetDatafileImageCoords(); Combat.battle_render(0, 0, 0); Draw.blit2screen(0, 0); kq_wait(150); Combat.multi_fight(attack_fighter_index); display_attack_string = 0; break; case CORIN: strcpy(attack_string, _("Elemental Infusion")); display_attack_string = 1; fighter[attack_fighter_index].aux = 2; if (combat_spell_menu(attack_fighter_index) == 1) { Effects.draw_castersprite( attack_fighter_index, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor); Combat.UnsetDatafileImageCoords(); play_effect(22, 128); Draw.convert_cframes( attack_fighter_index, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor - 3, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor + 3, 0); Combat.battle_render(0, 0, 0); fullblit(double_buffer, back); for (p = 0; p < 2; p++) { for (a = 0; a < 16; a++) { tx = fighter[attack_fighter_index].cx + (fighter[attack_fighter_index].cw / 2); ty = fighter[attack_fighter_index].cy + (fighter[attack_fighter_index].cl / 2); if (p == 0) { circlefill( double_buffer, tx, ty, a, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor); } else { circlefill( double_buffer, tx, ty, 15 - a, eff[magic[fighter[attack_fighter_index].csmem].eff].kolor); Combat.draw_fighter(attack_fighter_index, 0); } Draw.blit2screen(0, 0); kq_wait(50); fullblit(back, double_buffer); } } Draw.revert_cframes(attack_fighter_index, 0); Combat.battle_render(0, 0, 0); Draw.blit2screen(0, 0); infusion(attack_fighter_index, fighter[attack_fighter_index].csmem); c = Magic.mp_needed(attack_fighter_index, fighter[attack_fighter_index].csmem); if (c < 1) { c = 1; } fighter[attack_fighter_index].mp -= c; Combat.SetEtherEffectActive(attack_fighter_index, false); fighter[attack_fighter_index].aux = 1; } else { fighter[attack_fighter_index].aux = 0; display_attack_string = 0; return 0; } display_attack_string = 0; fighter[attack_fighter_index].SetInfuse(magic[fighter[attack_fighter_index].csmem].elem); break; case AJATHAR: if (fighter[attack_fighter_index].unl > 0) { strcpy(attack_string, _("Dispel Undead")); display_attack_string = 1; fullblit(double_buffer, back); for (a = 0; a < 14/*MagicNumber*/; a++) { Draw.convert_cframes(PSIZE, 1 + a, 15, 1); for (fighter_index = PSIZE; fighter_index < PSIZE + Combat.GetNumEnemies(); fighter_index++) { if (Effects.is_active(fighter_index)) { Combat.draw_fighter(fighter_index, 0); } } Draw.blit2screen(0, 0); kq_wait(50); fullblit(back, double_buffer); } Draw.revert_cframes(PSIZE, 1); display_attack_string = 0; b = fighter[attack_fighter_index].lvl * 15; for (fighter_index = PSIZE; fighter_index < PSIZE + Combat.GetNumEnemies(); fighter_index++) { if (fighter[fighter_index].IsAlive() && fighter[fighter_index].mhp > 0) { if (fighter[fighter_index].unl == 99 || fighter[fighter_index].unl == 0) { cts = 0; } else { a = (fighter[attack_fighter_index].lvl + 5) - fighter[fighter_index].unl; if (a > 0) { cts = a * 8; } else { cts = 0; } } if (kqrandom->random_range_exclusive(0, 100) < cts) { if (b >= fighter[fighter_index].hp) { b -= fighter[fighter_index].hp; Combat.SetShowDeathEffectAnimation(fighter_index, true); Combat.fkill(fighter_index); } } } } Effects.death_animation(PSIZE, 1); Combat.UnsetDatafileImageCoords(); Combat.battle_render(attack_fighter_index, attack_fighter_index, 0); } else { a = kqrandom->random_range_exclusive(0, 100); c = fighter[attack_fighter_index].lvl / 10 + 1; if (a < 25) { b = kqrandom->random_range_exclusive(0, 5 * c) + 1; } else { if (a < 90) { b = kqrandom->random_range_exclusive(0, 10 * c) + (20 * c); } else { b = kqrandom->random_range_exclusive(0, 25 * c) + (50 * c); } } strcpy(attack_string, _("Divine Cure")); display_attack_string = 1; Effects.draw_spellsprite(0, 1, 15, 1); display_attack_string = 0; for (fighter_index = 0; fighter_index < numchrs; fighter_index++) { if (!fighter[fighter_index].IsStone() && fighter[fighter_index].IsAlive()) { int amount = Magic.do_shell_check(fighter_index, b); Combat.AdjustHealth(fighter_index, amount); } } Effects.display_amount(0, FONT_YELLOW, 1); for (fighter_index = 0; fighter_index < numchrs; fighter_index++) { if (!fighter[fighter_index].IsStone() && fighter[fighter_index].IsAlive()) { Magic.adjust_hp(fighter_index, Combat.GetHealthAdjust(fighter_index)); } } } break; case CASANDRA: fighter[attack_fighter_index].atrack[0] = fighter[attack_fighter_index].stats[eStat::Aura]; fighter[attack_fighter_index].atrack[1] = fighter[attack_fighter_index].stats[eStat::Spirit]; fighter[attack_fighter_index].stats[eStat::Aura] = fighter[attack_fighter_index].stats[eStat::Aura] * 15 / 10; fighter[attack_fighter_index].stats[eStat::Spirit] = fighter[attack_fighter_index].stats[eStat::Spirit] * 15 / 10; fighter[attack_fighter_index].atrack[2] = fighter[attack_fighter_index].mrp; fighter[attack_fighter_index].mrp = fighter[attack_fighter_index].mrp * 15 / 10; if (combat_spell_menu(attack_fighter_index) == 1) { Combat.SetEtherEffectActive(attack_fighter_index, false); fighter[attack_fighter_index].aux = 1; fighter[attack_fighter_index].stats[eStat::Aura] = fighter[attack_fighter_index].atrack[0]; fighter[attack_fighter_index].stats[eStat::Spirit] = fighter[attack_fighter_index].atrack[1]; fighter[attack_fighter_index].mrp = fighter[attack_fighter_index].atrack[2]; } else { fighter[attack_fighter_index].stats[eStat::Aura] = fighter[attack_fighter_index].atrack[0]; fighter[attack_fighter_index].stats[eStat::Spirit] = fighter[attack_fighter_index].atrack[1]; fighter[attack_fighter_index].mrp = fighter[attack_fighter_index].atrack[2]; return 0; } break; case TEMMIN: fighter[attack_fighter_index].aux = 1; fighter[attack_fighter_index].defend = 1; break; case AYLA: tgt = select_enemy(attack_fighter_index, TGT_ENEMY_ONE); if (tgt == -1) { return 0; } enemy_index = (uint32_t)tgt; tx = fighter[attack_fighter_index].cx; ty = fighter[attack_fighter_index].cy; fighter[attack_fighter_index].cx = fighter[enemy_index].cx - 16; fighter[attack_fighter_index].cy = fighter[enemy_index].cy + fighter[enemy_index].cl - 40; fighter[attack_fighter_index].facing = 1; strcpy(attack_string, _("Steal")); display_attack_string = 1; Combat.battle_render(0, attack_fighter_index + 1, 0); Draw.blit2screen(0, 0); kq_wait(100); play_effect(SND_MENU, 128); kq_wait(500); display_attack_string = 0; Combat.battle_render(attack_fighter_index, attack_fighter_index, 0); found_item = 0; #ifdef DEBUGMODE if (debugging > 2) { if (fighter[enemy_index].steal_item_rare > 0) { /* This steals a rare item from monster, if there is one */ found_item = fighter[enemy_index].steal_item_rare; fighter[enemy_index].steal_item_rare = 0; } else if (fighter[enemy_index].steal_item_common > 0) { /* This steals a common item from a monster, if there is one */ found_item = fighter[enemy_index].steal_item_common; fighter[enemy_index].steal_item_common = 0; } if (found_item > 0) { if (check_inventory(found_item, 1) != 0) { sprintf(strbuf, _("%s taken!"), items[found_item].name); Draw.message(strbuf, items[found_item].icon, 0, 0, 0); } } else { if (fighter[enemy_index].steal_item_common == 0 && fighter[enemy_index].steal_item_rare == 0) { Draw.message(_("Nothing to steal!"), 255, 0, 0, 0); } else { Draw.message(_("Couldn't steal!"), 255, 0, 0, 0); } } } #else cts = party[pidx[attack_fighter_index]].lvl * 2 + 35; if (cts > 95) { cts = 95; } if (kqrandom->random_range_exclusive(0, 100) < cts) { if (fighter[enemy_index].steal_item_rare > 0 && (kqrandom->random_range_exclusive(0, 100) < 5)) { /* This steals a rare item from monster, if there is one */ found_item = fighter[enemy_index].steal_item_rare; fighter[enemy_index].steal_item_rare = 0; } else if (fighter[enemy_index].steal_item_common > 0 && (kqrandom->random_range_exclusive(0, 100) < 95)) { /* This steals a common item from a monster, if there is one */ found_item = fighter[enemy_index].steal_item_common; fighter[enemy_index].steal_item_common = 0; } if (found_item > 0) { if (check_inventory(found_item, 1) != 0) { sprintf(strbuf, _("%s taken!"), items[found_item].name); Draw.message(strbuf, items[found_item].icon, 0, 0, 0); } } else { if (fighter[enemy_index].steal_item_common == 0 && fighter[enemy_index].steal_item_rare == 0) { Draw.message(_("Nothing to steal!"), 255, 0, 0, 0); } else { Draw.message(_("Couldn't steal!"), 255, 0, 0, 0); } } } else { Draw.message(_("Couldn't steal!"), 255, 0, 0, 0); } #endif fighter[attack_fighter_index].cx = tx; fighter[attack_fighter_index].cy = ty; display_attack_string = 0; fighter[attack_fighter_index].facing = 0; Combat.battle_render(attack_fighter_index, attack_fighter_index, 0); Draw.blit2screen(0, 0); break; case NOSLOM: tgt = select_enemy(attack_fighter_index, TGT_ENEMY_ONE); if (tgt == -1) { return 0; } enemy_index = (uint32_t)tgt; reveal(enemy_index); break; default: break; } return 1; }
/*! \brief Player defeated the enemies * \author Josh Bolduc * \date Created ???????? * \date Updated * * Distribute the booty! */ static void heroes_win (void) { int tgp = 0; int index; int b; int c; int z; int nc = 0; int txp = 0; int found_item = 0; int nr = 0; int ent = 0; s_fighter t1; s_fighter t2; play_music ("rend5.s3m", 0); kq_wait (500); revert_equipstats (); for (index = 0; index < numchrs; index++) fighter[index].aframe = 4; battle_render (0, 0, 0); blit2screen (0, 0); kq_wait (250); for (index = 0; index < numchrs; index++) { if ((fighter[index].sts[S_STONE] == 0) && (fighter[index].sts[S_DEAD] == 0)) nc++; ta[index] = 0; } for (index = PSIZE; index < PSIZE + numens; index++) { txp += fighter[index].xp; tgp += fighter[index].gp; } /* JB: nc should never be zero if we won, but whatever */ if (nc > 0) txp /= nc; gp += tgp; if (tgp > 0) sprintf (strbuf, _("Gained %d xp and found %d gp."), txp, tgp); else sprintf (strbuf, _("Gained %d xp."), txp); menubox (double_buffer, 152 - (strlen (strbuf) * 4), 8, strlen (strbuf), 1, BLUE); print_font (double_buffer, 160 - (strlen (strbuf) * 4), 16, strbuf, FNORMAL); blit2screen (0, 0); blit (double_buffer, back, 0, 0, 0, 0, 352, 280); for (index = 0; index < numens; index++) { /* PH bug: (?) should found_item be reset to zero at the start of this loop? * If you defeat 2 enemies, you should (possibly) get 2 items, right? */ if ((rand () % 100) < fighter[index + PSIZE].dip) { if (fighter[index + PSIZE].defeat_item_common > 0) found_item = fighter[index + PSIZE].defeat_item_common; if (fighter[index + PSIZE].defeat_item_rare > 0) { if ((rand () % 100) < 5) found_item = fighter[index + PSIZE].defeat_item_rare; } if (found_item > 0) { if (check_inventory (found_item, 1) != 0) { sprintf (strbuf, _("%s found!"), items[found_item].name); menubox (double_buffer, 148 - (strlen (strbuf) * 4), nr * 24 + 48, strlen (strbuf) + 1, 1, BLUE); draw_icon (double_buffer, items[found_item].icon, 156 - (strlen (strbuf) * 4), nr * 24 + 56); print_font (double_buffer, 164 - (strlen (strbuf) * 4), nr * 24 + 56, strbuf, FNORMAL); nr++; } } } } if (nr > 0) { blit2screen (0, 0); wait_enter (); blit (back, double_buffer, 0, 0, 0, 0, 352, 280); } nr = 0; for (c = 0; c < numchrs; c++) { if ((party[pidx[c]].sts[S_STONE] == 0) && (party[pidx[c]].sts[S_DEAD] == 0)) { b = c * 160; player2fighter (pidx[c], &t1); if (give_xp (pidx[c], txp, 0) == 1) { menubox (double_buffer, b, 40, 18, 9, BLUE); player2fighter (pidx[c], &t2); print_font (double_buffer, b + 8, 48, _("Level up!"), FGOLD); print_font (double_buffer, b + 8, 56, _("Max HP"), FNORMAL); print_font (double_buffer, b + 8, 64, _("Max MP"), FNORMAL); print_font (double_buffer, b + 8, 72, _("Strength"), FNORMAL); print_font (double_buffer, b + 8, 80, _("Agility"), FNORMAL); print_font (double_buffer, b + 8, 88, _("Vitality"), FNORMAL); print_font (double_buffer, b + 8, 96, _("Intellect"), FNORMAL); print_font (double_buffer, b + 8, 104, _("Sagacity"), FNORMAL); sprintf (strbuf, "%3d>", t1.mhp); print_font (double_buffer, b + 96, 56, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.mhp); print_font (double_buffer, b + 128, 56, strbuf, FGREEN); sprintf (strbuf, "%3d>", t1.mmp); print_font (double_buffer, b + 96, 64, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.mmp); print_font (double_buffer, b + 128, 64, strbuf, FGREEN); for (z = 0; z < 5; z++) { sprintf (strbuf, "%3d>", t1.stats[z]); print_font (double_buffer, b + 96, z * 8 + 72, strbuf, FNORMAL); sprintf (strbuf, "%3d", t2.stats[z]); if (t2.stats[z] > t1.stats[z]) print_font (double_buffer, b + 128, z * 8 + 72, strbuf, FGREEN); else print_font (double_buffer, b + 128, z * 8 + 72, strbuf, FNORMAL); } nr++; } else menubox (double_buffer, b, 104, 18, 1, BLUE); sprintf (strbuf, _("Next level %7d"), party[pidx[c]].next - party[pidx[c]].xp); print_font (double_buffer, b + 8, 112, strbuf, FGOLD); } } blit2screen (0, 0); for (c = 0; c < numchrs; c++) if ((party[pidx[c]].sts[S_STONE] == 0) && (party[pidx[c]].sts[S_DEAD] == 0)) ent += learn_new_spells (pidx[c]); if (ent == 0) wait_enter (); }
int process_message (unsigned char* data, int length) { unsigned char* temp; Uint8 command = data[0]; data += 3; // Handlers skip command switch (command) { case RAW_TEXT: printf("%s\n", data+1); handle_raw_text_from_server(data+1); break; case YOU_ARE: me = *((short *)(data)); break; case ADD_NEW_ACTOR: add_actor(*((short *)(data)), data+23, *((short*)(data+2)), *((short*)(data+4))); break; case ADD_NEW_ENHANCED_ACTOR: add_actor(*((short *)(data)), data+28, *((short*)(data+2)), *((short*)(data+4))); break; case REMOVE_ACTOR: destroy_actor(*((short *)(data))); break; case KILL_ALL_ACTORS: destroy_all_actors(); break; case ADD_ACTOR_COMMAND: handle_actor_command(*((short *)(data)), data[2]); break; case HERE_YOUR_INVENTORY: get_inventory_from_server(data); break; case GET_NEW_INVENTORY_ITEM: get_new_inventory_item_from_server(data); break; case REMOVE_ITEM_FROM_INVENTORY: remove_inventory_item(data[0]); break; case GET_TRADE_ACCEPT: printf ("Someone pressed accept!\n"); printf ("%d", data[0]); if (data[0]) { trade.he_accepted++; update_trade(); } else { trade.we_accepted++; } break; case GET_TRADE_REJECT: if (data[0]) { trade.he_accepted = 0; } else { trade.we_accepted = 0; } break; case GET_TRADE_EXIT: end_trade(); check_inventory(); break; case GET_TRADE_OBJECT: if /* (data[7]) */ (data[8]) { /* data[6] is type attribute data[7] is pos atribbute */ get_trade_object(/* data[6] */ data[7], *((Uint16 *)(data)), *((Uint32 *)(data+2))); } break; case REMOVE_TRADE_OBJECT: if /* (data[3]) */ (data[5]) { /* remove_trade_object(data[2], *((Uint16 *)(data))); */ remove_trade_object (data[4], *((Uint32*)(data))); } break; case GET_YOUR_TRADEOBJECTS: get_inventory_from_server(data); break; case GET_TRADE_PARTNER_NAME: temp = data +1; /* Skip storage_available */ temp[length] = 0; /* ?! Isn't this outside of data range? */ activate_trade(temp); /* Should pass the address of begining of partner name */ break; case LOG_IN_OK: logged_in = 1; break; case LOG_IN_NOT_OK: fprintf(stderr, "ERROR: Invalid password\n"); die(); case YOU_DONT_EXIST: fprintf(stderr, "ERROR: Invalid username\n"); die(); default: // ignore it break; } return 1; }