예제 #1
0
void edit_party_event_filter (short item_hit)
{
	short which_pc;

		switch (item_hit) {
			case 1:
				dialog_not_toast = false;
				break;

			case 41:
				party.help_received[22] = 0;
				give_help(222,23,989);
				return;

			case 5: case 10: case 15: case 20: case 25: case 30:
				which_pc = (item_hit - 5) / 5;
				if (adven[which_pc].main_status != MAIN_STATUS_ABSENT)
					pick_pc_name(which_pc,989);
				put_party_stats();
				break;
			case 7: case 12: case 17: case 22: case 27: case 32:
				which_pc = (item_hit - 7) / 5;
				pick_race_abil(&adven[which_pc],0,989);
				put_party_stats();
				break;
			case 8: case 13: case 18: case 23: case 28: case 33:
				which_pc = (item_hit - 8) / 5;
				spend_xp(which_pc,0,989);
				put_party_stats();
				break;
			case 35: case 36: case 37: case 38: case 39: case 40:
				which_pc = item_hit - 35;

				if (adven[which_pc].main_status <= MAIN_STATUS_ABSENT)
					break;
				if (adven[which_pc].main_status != MAIN_STATUS_ABSENT)
					pick_pc_graphic(which_pc,1,989);
				put_party_stats();
				break;
			case 6: case 11: case 16: case 21: case 26: case 31:
				which_pc = (item_hit - 6) / 5;
				if (adven[which_pc].main_status != MAIN_STATUS_ABSENT) {
					if (FCD(1053,989) == 2)
						adven[which_pc].main_status = MAIN_STATUS_ABSENT;
					put_party_stats();
					}
					else {
						give_help(56,0,989);
						create_pc(which_pc,989);
						put_party_stats();
						cd_initial_draw(989); // extra redraw, just in case
						}
				break;
//			case 7: case 12: case 17: case 22: case 27: case 32:

			}

}
예제 #2
0
void pc_record_type::dumbfound(short how_much)
{
	short r1;

	if (!isAlive()) return;

	r1 = get_ran(1,0,90);

	if (hasAbilEquip(ITEM_WILL) < 24) {
		add_string_to_buf("  Ring of Will glows.");
		r1 -= 10;
		}

	if (r1 < level)
		how_much -= 2;

	if (how_much <= 0) {
		sprintf (c_line, "  %s saved.", name);
		add_string_to_buf(c_line);
		return;
		}

	status[STATUS_DUMB] = min(status[STATUS_DUMB] + how_much, 8);
	sprintf (c_line, "  %s dumbfounded.", name);
	add_string_to_buf(c_line);

	one_sound(67);
	put_pc_screen();
	adjust_spell_menus();
	give_help(28,0,0);
}
예제 #3
0
void pc_record_type::disease(short how_much)
{
	short r1, tlevel;

	if (!isAlive()) return;

	r1 = get_ran(1,0,100);

	if (r1 < level * 2)
		how_much -= 2;

	if (how_much <= 0)
	{
		sprintf (c_line, "  %s saved.", name);
		add_string_to_buf(c_line);
		return;
	}

	if ((tlevel = getProtLevel(ITEM_PROTECT_FROM_DISEASE)) > 0)
		how_much -= tlevel / 2;

	if ((traits[TRAIT_FRAIL] == true) && (how_much > 1))	how_much++;
	if ((traits[TRAIT_FRAIL] == true) && (how_much == 1) && (get_ran(1,0,1) == 0)) how_much++;

	status[STATUS_DISEASE] = min(status[STATUS_DISEASE] + how_much,8);
	sprintf (c_line, "  %s diseased.", name);
	add_string_to_buf(c_line);

	one_sound(66);
	put_pc_screen();
	give_help(29,0,0);
}
예제 #4
0
void handle_shop_event(POINT p)
{
	short i,store_what_picked;

	p.x -= 5;
	p.y -= 5;

	if (PtInRect(&talk_help_rect,p)) {
		click_shop_rect(talk_help_rect);
		party.help_received[26] = 0;
		give_help(226,27,0);
		return;
		}
	if (PtInRect(&shop_done_rect, p)) {
		click_shop_rect(shop_done_rect);
		end_shop_mode();
		return;
		}

	for (i = 0; i < 8; i++) {
		store_what_picked = i + GetScrollPos(shop_sbar,SB_CTL);
		if ((PtInRect(&shopping_rects[i][1],p)) && (store_shop_items[store_what_picked] >= 0)) {
			click_shop_rect(shopping_rects[i][1]);
			handle_sale(store_shop_items[store_what_picked],store_shop_costs[store_what_picked]);
			}
		if ((PtInRect(&shopping_rects[i][6],p)) && (store_shop_items[store_what_picked] >= 0)
			&& (store_shop_type != SHOP_HEALER) && (store_shop_type != SHOP_FOOD)){
			click_shop_rect(shopping_rects[i][6]);
			handle_info_request(store_shop_items[store_what_picked]);
			}
		}
}
예제 #5
0
void start_talk_mode(short m_num,short personality,unsigned char monst_type,short store_face_pic)////
{
	RECT area_rect, talk_edit_box_rect;
	char place_string1[256] = "";
	char place_string2[256] = "";

	store_personality = personality;

	store_monst_type = monst_type;
	store_m_num = m_num;
	store_talk_face_pic = store_face_pic; ////
	area_rect = talk_area_rect;
	OffsetRect(&area_rect, -1 * area_rect.left,-1 * area_rect.top);
   	talk_gworld = CreateCompatibleBitmap(main_dc,area_rect.right,area_rect.bottom);

    if(PSD[SDF_ASK_ABOUT_TEXT_BOX] == 1){
        talk_edit_box_rect = preset_words[8].word_rect;
        OffsetRect(&talk_edit_box_rect,ulx,uly+3);
    	talk_edit_box = CreateWindow("edit",NULL,WS_CHILD | WS_BORDER | WS_VISIBLE,
									talk_edit_box_rect.left+125,talk_edit_box_rect.top,
									140,
									20,
									mainPtr,(HMENU) 160,(HINSTANCE) store_hInstance,NULL);
        store_edit_parent =  mainPtr;
    	old_edit_proc = (WNDPROC) (GetWindowLong(talk_edit_box,GWL_WNDPROC));
    	SetWindowLong(talk_edit_box,GWL_WNDPROC,(LONG) edit_proc);
    	SetFocus(talk_edit_box);
        }

	// first make sure relevant talk strs are loaded in
	if (personality / 10 != cur_town_talk_loaded)
		load_town(personality / 10,1,0,NULL);

	// Dredge up critter's name
	sprintf((char *) title_string,"%s:",data_store3->talk_strs[personality % 10]);

	store_pre_talk_mode = overall_mode;
	overall_mode = MODE_TALKING;
	create_clip_region();
	talk_end_forced = false;
	stat_screen_mode = 1;

	// Bring up and place first strings.
	sprintf((char *) place_string1,"%s",data_store3->talk_strs[personality % 10 + 10]);
	strnum1 = personality % 10 + 10;
	strnum2 = 0;
	strcpy((char *) old_str1,(char *) place_string1);
	strcpy((char *) old_str2,(char *) place_string2);
	strcpy((char *) one_back1,(char *) place_string1);
	strcpy((char *) one_back2,(char *) place_string2);
	place_talk_str((char *) place_string1,(char *) place_string2,0,dummy_rect);

	put_item_screen(stat_window,0);
	give_help(5,6,0);

}
예제 #6
0
void pc_record_type::sleep(short how_much,short what_type,short adjust)
// higher adjust, less chance of saving
{
	short r1, tlevel;
	if (!isAlive()) return;

	if (how_much == 0)
		return;

	if ((what_type == STATUS_ASLEEP) || (what_type == STATUS_PARALYZED)) { ////
		if ((tlevel = getProtLevel(ITEM_WILL)) > 0)
			how_much -= tlevel / 2;
		if ((tlevel = getProtLevel(ITEM_FREE_ACTION)) > 0)
			how_much -= (what_type == STATUS_ASLEEP) ? tlevel : tlevel * 300;

		}

	r1 = get_ran(1,0,100) + adjust;
	if (r1 < 30 + level * 2)
		how_much = -1;
	if ((what_type == STATUS_ASLEEP) && ((traits[TRAIT_HIGHLY_ALERT] > 0) || (status[STATUS_ASLEEP] < 0)))
		how_much = -1;
	if (how_much <= 0) {
		sprintf (c_line, "  %s resisted.", name);
		add_string_to_buf( c_line);
		return;
		}
	if (isAlive()) {
		status[what_type] = how_much;
		if (what_type == STATUS_ASLEEP)
			sprintf (c_line, "  %s falls asleep.", name);
			else sprintf (c_line, "  %s paralyzed.", name);
		if (what_type == STATUS_ASLEEP)
			play_sound(96);
			else play_sound(90);
		add_string_to_buf(c_line);
		pc_moves[getNum()] = 0;
		}
	put_pc_screen();
	if (what_type == STATUS_ASLEEP)
		give_help(30,0,0);
		else give_help(32,0,0);
}
예제 #7
0
void pc_record_type::curse(short how_much)
{
	if (!isAlive()) return;

	status[STATUS_BLESS_CURSE] = max(status[STATUS_BLESS_CURSE] - how_much, -8);
	sprintf (c_line, "  %s cursed.", name);
	add_string_to_buf(c_line);

	put_pc_screen();
	give_help(59,0,0);
}
예제 #8
0
void pc_record_type::web(short how_much)
{
	if (!isAlive()) return;

	status[STATUS_WEBS] = min(status[STATUS_WEBS] + how_much,8);
	sprintf ((char *) c_line, "  %s webbed.",(char *) name);
	add_string_to_buf((char *) c_line);
	one_sound(17);

	put_pc_screen();
	give_help(31,0,0);
}
예제 #9
0
void pc_record_type::slow(short how_much)
{
	if (!isAlive()) return;

	status[STATUS_HASTE_SLOW] = minmax(-8,8,status[STATUS_HASTE_SLOW] - how_much);
	if (how_much < 0)
		sprintf ((char *) c_line, "  %s hasted.",(char *) name);
		else sprintf ((char *) c_line, "  %s slowed.",(char *) name);
	add_string_to_buf((char *) c_line);

	put_pc_screen();
	if (how_much < 0)
		give_help(35,0,0);
}
예제 #10
0
void record_display_strings(){
	bool had1 = false, had2 = false;
	unsigned int i;
	play_sound(0);
	for (i = 0; i < univ.party.special_notes.size(); i++)
		if ((store_str_label_1 == univ.party.special_notes[i].str_num) &&
			(store_str_label_1b == univ.party.special_notes[i].where))
			had1 = true;
	if (!had1) {
	   give_help(58,0,store_which_string_dlog);
	   univ.party.record(store_str_label_1, store_str_label_1b);
	}
	for (i = 0; i < univ.party.special_notes.size(); i++)
		if ((store_str_label_2 == univ.party.special_notes[i].str_num) &&
			(store_str_label_2b == univ.party.special_notes[i].where))
			had2 = true;
	if (!had2) {
	   univ.party.record(store_str_label_2,store_str_label_2b);
	}
}
예제 #11
0
void pick_preferences()
{
    get_reg_data();
	cur_display_mode = display_mode;

	SetCursor(sword_curs);

	cd_create_dialog(1099,mainPtr);

	cd_set_led(1099,4 + cur_display_mode,1);

	cd_set_led(1099,18,(party.stuff_done[SFD_NO_MAPS] != 0) ? 1 : 0);
	cd_set_led(1099,20,(play_sounds == false) ? 1 : 0);
	cd_set_led(1099,22,(party.stuff_done[SDF_NO_FRILLS] != 0) ? 1 : 0);
	cd_set_led(1099,24,(party.stuff_done[SDF_ROOM_DESCS_AGAIN] != 0) ? 1 : 0);
	cd_set_led(1099,27,(party.stuff_done[SDF_NO_INSTANT_HELP] != 0) ? 1 : 0);
	cd_set_led(1099,38,(party.stuff_done[SDF_EASY_MODE] != 0) ? 1 : 0);
	cd_set_led(1099,40,(party.stuff_done[SDF_LESS_WANDER_ENC] != 0) ? 1 : 0);
	cd_set_led(1099,43,(party.stuff_done[SDF_NO_TER_ANIM] != 0) ? 1 : 0);
	cd_set_led(1099,45,(party.stuff_done[SDF_NO_SHORE_FRILLS] != 0) ? 1 : 0);
	cd_set_led(1099,50,(party.stuff_done[SDF_NO_TARGET_LINE] != 0) ? 1 : 0);
	cd_set_led(1099,52,(party.stuff_done[SDF_LESS_SOUND] != 0) ? 1 : 0);
	cd_set_led(1099,54,(play_startup != false) ? 1 : 0);
	cd_set_led(1099,56,(party.stuff_done[SDF_FASTER_BOOM_SPACES] != 0) ? 1 : 0);
	cd_set_led(1099,58,(party.stuff_done[SDF_USE_DARKER_GRAPHICS] != 0) ? 1 : 0);
	cd_set_led(1099,60,(party.stuff_done[SDF_ASK_ABOUT_TEXT_BOX] != 0) ? 1 : 0);// talk edit box appearing ?
		cd_set_flag(1099,3,1);
	if (PSD[SDF_GAME_SPEED] == 3)
		cd_set_led(1099,47,1);
		else cd_set_led(1099,32 + PSD[SDF_GAME_SPEED] * 2,1);

	if (party.help_received[55] == 0) {
		cd_initial_draw(1099);
		give_help(55,0,1099);
		}

	while (dialog_not_toast)
		ModalDialog();
	cd_kill_dialog(1099,0);
	adjust_window_mode();
}
예제 #12
0
void edit_party()
{

	SetCursor(sword_curs);

	cd_create_dialog(989,mainPtr);

	put_party_stats();
	if (party.help_received[22] == 0) {
		cd_initial_draw(989);
		give_help(22,23,989);
		}
	while (dialog_not_toast)
		ModalDialog();
	cd_kill_dialog(989,0);

	if (adven[current_pc].isAlive() == false)
		current_pc = first_active_pc();


}
예제 #13
0
/*
shop_type:
0 - weapon shop
1 - armor shop
2 - misc shop
3 - healer
4 - food
5-9 - magic shop
10 - mage spells
11 - priest spells
12 alchemy
*/
void start_shop_mode(short shop_type,short shop_min,short shop_max,short cost_adj,char *store_name)
{
	RECT area_rect;

    if(PSD[SDF_ASK_ABOUT_TEXT_BOX] == 1)
    	ShowWindow(talk_edit_box, SW_HIDE);

	if (shop_max < shop_min)
		shop_max = shop_min; ////
	store_cost_mult = cost_adj;
	if (store_cost_mult > 6)
		store_cost_mult = 6;
	store_shop_type = shop_type;
	store_shop_min = shop_min;
	store_shop_max = shop_max;

	area_rect = talk_area_rect;
	strcpy((char *) store_store_name,store_name);

	OffsetRect(&area_rect, -1 * area_rect.left,-1 * area_rect.top);
	if (talk_gworld == NULL)
		 talk_gworld = CreateCompatibleBitmap(main_dc,area_rect.right,area_rect.bottom);

	store_pre_shop_mode = overall_mode;
	overall_mode = MODE_SHOPPING;
	stat_screen_mode = 1;
	create_clip_region();

	set_up_shop_array();
	put_background();

	draw_shop_graphics(0,area_rect);

	put_item_screen(stat_window,0);
	give_help(26,27,0);
}
예제 #14
0
void handle_menu_choice(eMenu item_hit) {
	std::string dialogToShow;
	sf::Event dummyEvent = {sf::Event::KeyPressed};
	short i, choice;
	
	switch(item_hit) {
		case eMenu::NONE: break;
		case eMenu::FILE_OPEN:
			do_load();
			break;
		case eMenu::FILE_SAVE:
			do_save(0);
			break;
		case eMenu::FILE_SAVE_AS:
			do_save(1);
			break;
		case eMenu::FILE_NEW:
			if(overall_mode != MODE_STARTUP) {
				std::string choice = cChoiceDlog("restart-game",{"okay","cancel"}).show();
				if(choice == "cancel")
					return;
				for(i = 0; i < 6; i++)
					univ.party[i].main_status = eMainStatus::ABSENT;
				party_in_memory = false;
				reload_startup();
				overall_mode = MODE_STARTUP;
				draw_startup(0);
			}
			start_new_game();
			draw_startup(0);
			menu_activate();
			break;
		case eMenu::FILE_ABORT:
			if(overall_mode != MODE_STARTUP) {
				std::string choice = cChoiceDlog("abort-game",{"okay","cancel"}).show();
				if (choice=="cancel") return;
				reload_startup();
				overall_mode = MODE_STARTUP;
			}
			party_in_memory = false;
			draw_startup(0);
			menu_activate();
			break;
		case eMenu::PREFS:
			pick_preferences();
			break;
		case eMenu::QUIT:
			if(overall_mode == MODE_STARTUP) {
				if(party_in_memory) {
					std::string choice = cChoiceDlog("quit-confirm-save", {"save","quit","cancel"}).show();
					if(choice == "cancel") break;
					if(choice == "save") {
						fs::path file = nav_put_party();
						if(!file.empty()) break;
						save_party(file, univ);
					}
				}
				All_Done = true;
				break;
			}
			if(overall_mode > MODE_TOWN) {
				std::string choice = cChoiceDlog("quit-confirm-nosave",{"quit","cancel"}).show();
				if(choice == "cancel")
					return;
			}
			else {
				std::string choice = cChoiceDlog("quit-confirm-save",{"quit","save","cancel"}).show();
				if(choice == "cancel")
					break;
				if(choice == "save") {
					if(univ.file.empty()) {
						univ.file = nav_put_party();
						if(univ.file.empty()) break;
					}
					save_party(univ.file, univ);
				}
			}
			All_Done = true;
			break;
		case eMenu::OPTIONS_PC_GRAPHIC:
			choice = char_select_pc(1,"New graphic for who?");
			if(choice < 6)
				pick_pc_graphic(choice,1,nullptr);
			draw_terrain();
			break;
			
		case eMenu::OPTIONS_DELETE_PC:
			if(!prime_time()) {
				ASB("Finish what you're doing first.");
				print_buf();
			}
			else {
				choice = char_select_pc(1,"Delete who?");
				if(choice < 6) {
					std::string confirm = cChoiceDlog("delete-pc-confirm",{"yes","no"}).show();
					if(confirm == "yes")
						kill_pc(univ.party[choice],eMainStatus::ABSENT);
				}
				draw_terrain();
			}
			break;
			
			
		case eMenu::OPTIONS_RENAME_PC:
			choice = char_select_pc(1,"Rename who?");
			if(choice < 6)
				pick_pc_name(choice,nullptr);
			put_pc_screen();
			put_item_screen(stat_window);
			break;
			
			
		case eMenu::OPTIONS_NEW_PC:
			if(!(is_town())) {
				add_string_to_buf("Add PC: Town mode only.");
				print_buf();
				break;
			}
			for(i = 0; i < 6; i++)
				if(univ.party[i].main_status == eMainStatus::ABSENT)
					i = 20;
			if(i == 6) {
				ASB("Add PC: You already have 6 PCs.");
				print_buf();
				break;
			}
			if(univ.town->has_tavern) {
				give_help(56,0);
				create_pc(6,nullptr);
			} else {
				add_string_to_buf("Add PC: You cannot add new characters in this town. Try in the town you started in.", 2);
			}
			print_buf();
			put_pc_screen();
			put_item_screen(stat_window);
			break;
			
		case eMenu::OPTIONS_JOURNAL:
			journal();
			break;
		case eMenu::OPTIONS_TALK_NOTES:
			if(overall_mode == MODE_TALKING) {
				ASB("Talking notes: Can't read while talking.");
				print_buf();
				return;
			}
			talk_notes();
			break;
		case eMenu::OPTIONS_ENCOUNTER_NOTES:
			adventure_notes();
			break;
		case eMenu::OPTIONS_STATS:
			if(overall_mode != MODE_STARTUP)
				print_party_stats();
			break;
		case eMenu::HELP_OUT:
			dialogToShow = "help-outdoor";
			break;
		case eMenu::HELP_TOWN:
			dialogToShow = "help-town";
			break;
		case eMenu::HELP_COMBAT:
			dialogToShow = "help-combat";
			break;
		case eMenu::HELP_BARRIER:
			dialogToShow = "help-fields";
			break;
		case eMenu::HELP_HINTS:
			dialogToShow = "help-hints";
			break;
		case eMenu::HELP_SPELLS:
			dialogToShow = "help-magic";
			break;
		case eMenu::ABOUT:
			dialogToShow = "about-boe";
			break;
		case eMenu::LIBRARY_MAGE:
			display_spells(eSkill::MAGE_SPELLS,100,0);
			break;
		case eMenu::LIBRARY_PRIEST:
			display_spells(eSkill::PRIEST_SPELLS,100,0);
			break;
		case eMenu::LIBRARY_SKILLS:
			display_skills(eSkill::INVALID,0);
			break;
		case eMenu::LIBRARY_ALCHEMY:
			// TODO: Create a dedicated dialog for alchemy info
			display_alchemy();
			break;
		case eMenu::LIBRARY_TIPS:
			tip_of_day();
			break;
		case eMenu::LIBRARY_INTRO:
			dialogToShow = "welcome";
			break;
		case eMenu::ACTIONS_ALCHEMY:
			dummyEvent.key.code = sf::Keyboard::A;
			dummyEvent.key.shift = true;
			handle_keystroke(dummyEvent);
			break;
		case eMenu::ACTIONS_WAIT:
			dummyEvent.key.code = sf::Keyboard::W;
			handle_keystroke(dummyEvent);
			break;
		case eMenu::ACTIONS_AUTOMAP:
			if(!prime_time()) {
				ASB("Finish what you're doing first.");
				print_buf();
			}
			else {
				give_help(62,0);
				display_map();
			}
			make_cursor_sword();
			break;
		case eMenu::HELP_TOC:
			if(fs::is_directory(progDir/"doc"))
				launchURL("file://" + (progDir/"doc/game/Contents.html").string());
			else launchURL("https://blades.calref.net/doc/game/Contents.html");
			break;
		case eMenu::ABOUT_MAGE:
		case eMenu::ABOUT_PRIEST:
			give_help(209,0);
			break;
		case eMenu::ABOUT_MONSTERS:
			give_help(212,0);
			break;
	}
	if(!dialogToShow.empty()) {
		cChoiceDlog dlog(dialogToShow);
		dlog.show();
	}
}
예제 #15
0
void handle_sale(short what_chosen,short cost)
{
	item_record_type base_item;
	short what_magic_shop,what_magic_shop_item,i;
	RECT dummy_rect = {0,0,0,0};

	switch (what_chosen / 100) {
		case 0: case 1: case 2: case 3: case 4:
			base_item = get_stored_item(what_chosen);
			base_item.item_properties = base_item.item_properties | 1;
			//cost = (base_item.charges == 0) ? base_item.value : base_item.value * base_item.charges;
			switch (adven[current_pc].okToBuy(cost,base_item)) {
				case 1: play_sound(-38); adven[current_pc].giveToPC(base_item,true); break;
				case 2: ASB("Can't carry any more items."); break;
				case 3: ASB("Not enough cash."); break;
				case 4: ASB("Item is too heavy."); break;
				case 5: ASB("You own too many of this."); break;
				}
			break;
		case 5:
			base_item = store_alchemy(what_chosen - 500);
			if (party.alchemy[base_item.item_level] == true)
				ASB("You already know that recipe.");
				else if (party.takeGold(cost, false) == false)
					ASB("Not enough gold.");
					else {
						play_sound(62);
						ASB("You buy an alchemical recipe.");
						party.alchemy[base_item.item_level] = true;
						}
			break;
		case 7:
			what_chosen -= 700;
			if (party.takeGold(cost, false) == false)
				ASB("Not enough gold.");
				else {
					ASB("You pay the healer.");
					play_sound(68);
					switch (what_chosen) {
						case 0:
							adven[current_pc].cur_health = adven[current_pc].max_health;
							break;
						case 1:
							adven[current_pc].status[STATUS_POISON] = 0;
							break;
						case 2:
							adven[current_pc].status[STATUS_DISEASE] = 0; break;
						case 3:
							adven[current_pc].status[STATUS_PARALYZED] = 0; break;
						case 4:
							for (i = 0; i < 24; i++)
								if ((adven[current_pc].equip[i] == true) &&
									(adven[current_pc].items[i].isCursed()))
										adven[current_pc].items[i].item_properties =
											adven[current_pc].items[i].item_properties & 239;
  							break;
						case 5: case 6: case 7:
							adven[current_pc].main_status = MAIN_STATUS_ALIVE; break;
						case 8:
							adven[current_pc].status[STATUS_DUMB] = 0; break;
						}
					}
			break;
		case 8:
			base_item = store_mage_spells(what_chosen - 800 - 30);
			if ((base_item.item_level < 0) || (base_item.item_level > 61)) {
				MessageBeep(MB_OK); ASB("Error 102: Report this!"); break;}
			if (adven[current_pc].mage_spells[base_item.item_level] == true)
				ASB("You already have this spell.");
				else if (party.takeGold(cost, false) == false)
					ASB("Not enough gold.");
					else {
						play_sound(62);
						ASB("You buy a spell.");
						adven[current_pc].mage_spells[base_item.item_level] = true;
						give_help(41,0,0);
						}
			break;
		case 9:
			base_item = store_priest_spells(what_chosen - 900 - 30);
			if ((base_item.item_level < 0) || (base_item.item_level > 61)) {
				MessageBeep(MB_OK); ASB("Error 101: Report this!"); break;}
			if (adven[current_pc].priest_spells[base_item.item_level] == true)
				ASB("You already have this spell.");
				else if (party.takeGold(cost, false) == false)
					ASB("Not enough gold.");
					else {
						play_sound(62);
						ASB("You buy a spell.");
						adven[current_pc].priest_spells[base_item.item_level] = true;
						give_help(41,0,0);
						}
			break;
		default:
			what_magic_shop = (what_chosen / 1000) - 1;
			what_magic_shop_item = what_chosen % 1000;
			base_item = party.magic_store_items[what_magic_shop][what_magic_shop_item];
			base_item.item_properties = base_item.item_properties | 1;
			switch (adven[current_pc].okToBuy(cost,base_item)) {
				case 1: play_sound(-38); adven[current_pc].giveToPC(base_item,true);
					party.magic_store_items[what_magic_shop][what_magic_shop_item].variety = ITEM_TYPE_NO_ITEM;
					break;
				case 2: ASB("Can't carry any more items."); break;
				case 3: ASB("Not enough cash."); break;
				case 4: ASB("Item is too heavy."); break;
				}
			break;
		}
	set_up_shop_array();

	if (overall_mode != MODE_SHOPPING) {
		MessageBeep(MB_OK);
		ASB("Shop error 1. Report This!");
		}
	draw_shop_graphics(0,dummy_rect);
	print_buf();
	put_pc_screen();
	put_item_screen(stat_window,0);
}
예제 #16
0
파일: boe.main.cpp 프로젝트: Ircher/CBoE
Boolean handle_menu (short item, HMENU)
{
    short choice,i;
    POINT x = {1001,0},pass_point;
    Boolean to_return = false;

    switch (item) {
    case 1:  // File Menu
        if (in_startup_mode == true) startup_load();
        else do_load();
        break;
    case 2:
        do_save(0);
        break;
    case 3:
        if (in_startup_mode == true) save_file(1);
        else do_save(1);
        break;
    case 4:
        if (in_startup_mode == false)
        {
            choice = FCD(1091,0);
            if (choice == 1) return false;
            for (i = 0; i < 6; i++)
                adven[i].main_status = MAIN_STATUS_ABSENT;
            party_in_memory = false;
            reload_startup();
            in_startup_mode = true;
            draw_startup(0);
        }
        start_new_game();
        draw_startup(0);
        break;
    case 6:
        pick_preferences();
        break;
    case 7:
        pick_compatibility();
        break;
    case 8:  // Quit
        if (in_startup_mode == true) {
            to_return = All_Done = true;
            break;
        }
        if (overall_mode > MODE_TOWN) {
            choice = FCD(1067,0);
            if (choice == 1) return All_Done;
        }
        else {
            choice = FCD(1066,0);
            if (choice == 3)
                break;
            if (choice == 1)
                save_file(0);
        }
        to_return = All_Done = true;
        break;

    // Options menu
    case 21:
        choice = char_select_pc(0,0,"New graphic for who?");
        if (choice < 6)
            pick_pc_graphic(choice,1,0);
        initiate_redraw();
        break;

    case 22:
        choice = select_pc(0,0);
        if (choice < 6)
            pick_pc_name(choice,0);
        put_pc_screen();
        put_item_screen(stat_window,0);
        break;


    case 23:
        if (!(is_town())) {
            add_string_to_buf("Add PC: Town mode only.");
            print_buf();
            break;
        }
        for (i = 0; i < NUM_OF_PCS; i++)
            if (adven[i].main_status == MAIN_STATUS_ABSENT)
                i = 20;
        if (i == INVALID_PC) {
            ASB("Add PC: You already have 6 PCs.");
            print_buf();
        }
        if (c_town.town_num == scenario.which_town_start) {
            give_help(56,0,0);
            create_pc(6,0);
        }
        else {
            add_string_to_buf("Add PC: You can only make new");
            add_string_to_buf("  characters in the town you ");
            add_string_to_buf("  started in.");
        }
        print_buf();
        put_pc_screen();
        put_item_screen(stat_window,0);
        break;

    case 24:
        if (prime_time() == false) {
            ASB("Finish what you're doing first.");
            print_buf();
        }
        else {
            choice = char_select_pc(0,0,"Delete who?");
            if (choice < 6) {
                if ((i = FCD(1053,0)) == 2)
                    adven[choice].kill(0);
            }
            initiate_redraw();
        }
        break;

    case 27:
        if (overall_mode == MODE_TALKING) {
            ASB("Talking notes: Can't read while talking.");
            print_buf();
            return to_return;
        }
        talk_notes();
        break;
    case 28:
        adventure_notes();
        break;
    case 29:
        if (in_startup_mode == false) print_party_stats();
        break;

    // Help menu
    case 41:
        FCD(1079,0);
        break;
    case 42:
        FCD(1080,0);
        break;
    case 43:
        FCD(1081,0);
        break;
    case 44:
        FCD(1072,0);
        break; // magic barriers
    case 46:
        FCD(1084,0);
        break;
    case 47:
        FCD(1088,0);
        break;

    // Library
    case 61:
        display_spells(0,100,0);
        break;
    case 62:
        display_spells(1,100,0);
        break;
    case 63:
        display_skills(100,0);
        break;
    case 64:
        display_help(0,0);
        break;
    case 65:
        tip_of_day();
        break;
    case 67:
        FCD(986,0);
        break;

    // Actions
    case 81:
        if (overall_mode != MODE_TOWN) {
            ASB("Alchemy: In town mode only.");
            print_buf();
            break;
        }
        pass_point.x = 1000;
        pass_point.y = 405;
        to_return = handle_action(pass_point,(WPARAM) 0,(LPARAM)-1);
        break;
    case 82:
        to_return = handle_action(x,(WPARAM) 0,(LPARAM)-1);
        break;
    case 84:
        if (prime_time() == false) {
            ASB("Finish what you're doing first.");
            print_buf();
        }
        else {
            give_help(62,0,0);
            display_map();
        }
        SetCursor(sword_curs);
        break;

    // Mage is 399
    case 399:
        give_help(209,0,0);
        party.help_received[9] = false;
        break;

    // Priest is 499
    case 499:
        give_help(209,0,0);
        party.help_received[9] = false;
        break;

    // Monsters is 599
    case 599:
        give_help(212,0,0);
        break;

    case 100: // Index
        WinHelp(mainPtr,"Blades of Exile.hlp",HELP_CONTENTS,0L);
        break;

    case 200: // About
        FCD(1062,0);
        break;

    default:
        if ((item >= 400) && (item < 500))  { // mage spell
            if (prime_time() == false) {
                ASB("Finish what you're doing first.");
                print_buf();
            }
            else handle_menu_spell(item - 400,0);
            break;
        }
        if ((item >= 500) && (item < 600))  { // priest spell
            if (prime_time() == false) {
                ASB("Finish what you're doing first.");
                print_buf();
            }
            else handle_menu_spell(item - 500,1);
            break;
        }
        if ((item >= 600) && (item < 700))  { // monster spell
            display_monst(item - 600,(creature_data_type *) NULL,1);
            break;
        }
        break;
    }
    if (in_startup_mode == true)
        menu_activate(0);
    else menu_activate(1);
    return to_return;
}
예제 #17
0
/*
 * parse_args()
 *
 * In:      argc - number of command-line arguments.
 *          argv - string array containing command-line arguments.
 *
 * Returns: an index into argv where we stopped parsing arguments.
 *
 * Abstract: Parses command-line arguments.  In some cases, it will
 *           set the appropriate global variables and return.  Otherwise,
 *           it performs the appropriate action and exits.
 *
 * Assumptions: Currently, we check to make sure that there are no arguments
 *              other than the defined options, so the return value is
 *              pretty useless and should be ignored.
 */
int parse_args(int argc, char **argv)
{
    int c;
    int gotdomain = 0;

    progname = strrchr(argv[0], '/');
    if (!progname) progname = argv[0];

    while(1) {
#if defined(__GNU_LIBRARY__)
	c = getopt_long(argc, argv, short_options, long_options, 0);
#else
	c = getopt(argc, argv, short_options);
#endif
	if (c == -1) break;
	switch(c) {
	  case 'a': {
	      if (!inet_aton(optarg, &recv_addr.sin_addr)) {
		  log_msg(LOG_ERR, "%s: Bad ip address \"%s\"\n",
			  progname, optarg);
		  exit(-1);
	      }
	      break;
	  }
	  case 'c': {
#ifdef ENABLE_CACHE
	      copy_string(cache_param, optarg, sizeof(cache_param));
#endif
	      break;
	  }
	  case 'd': {
	      opt_debug++;
	      break;
	  }
	  case 'h': {
	      give_help();
	      exit(0);
	      break;
	  }
	  case 'k': {
	      if (!kill_current()) {
		  printf("No %s daemon found.  Exiting.\n", progname);
	      }
	      exit(0);
	      break;
	  }
	  case 'l': {
	      gotterminal = 0;
	      break;
	  }
	  case 'm': {
#ifdef ENABLE_CACHE
	      copy_string(master_param, optarg, sizeof(master_param));
#endif
	      break;
	  }
	  case 's': {
	      char *sep = strchr(optarg, (int)':');
	      if (serv_cnt >= MAX_SERV) {
		  log_msg(LOG_ERR, "%s: Max. %d DNS servers allowed\n",
			  progname, MAX_SERV);
		  exit(-1);
	      }
	      if (gotdomain == -1) {
		  log_msg(LOG_ERR, "%s: When giving server arguments with "
			  "domain names,\nonly the last one is permitted to "
			  "not have a domain name.\n", progname);
		  exit(-1);
	      }
	      if (sep) {
		  dns_srv[serv_cnt].domain = make_cname(sep + 1);
		  if (gotdomain == -1) {
		      log_msg(LOG_ERR, "%s: Server arguments with domain "
			      "names must appear before\n"
			      "those without domain names.\n", progname);
		      exit(-1);
		  }
		  gotdomain = 1;
		  *sep = 0;
	      }
	      else if (gotdomain != 0) {
		  gotdomain = -1;
	      }
	      if (!inet_aton(optarg, &dns_srv[serv_cnt].addr.sin_addr)) {
		  log_msg(LOG_ERR, "%s: Bad ip address \"%s\"\n",
			  progname, optarg);
		  exit(-1);
	      }
	      if (sep) *sep = ':';
	      serv_cnt++;
	      break;
	  }
	  case 'u': {
	      char *ep;
	      struct passwd *pwent;
	      daemonuid = (uid_t)strtoul(optarg, &ep, 10);

	      pwent = *ep ? getpwnam(optarg) : getpwuid(daemonuid);
	      if (!pwent) {
		  log_msg(LOG_ERR, "%s: Bad uid \"%s\"\n", progname, optarg);
		  exit(-1);
	      }

	      daemonuid = pwent->pw_uid;
	      daemongid = pwent->pw_gid;
	      break;
	  }
	  case 'v': {
	      printf("dnrd version %s\n\n", version);
	      exit(0);
	      break;
	  }
	  case ':': {
	      log_msg(LOG_ERR, "%s: Missing parameter for \"%s\"\n",
		      progname, argv[optind]);
	      exit(-1);
	      break;
	  }
	  case '?':
	  default: {
	      /* getopt_long will print "unrecognized option" for us */
	      give_help();
	      exit(-1);
	      break;
	  }
	}
    }

    if (optind != argc) {
	log_msg(LOG_ERR, "%s: Unknown parameter \"%s\"\n",
		progname, argv[optind]);
	exit(-1);
    }
    return optind;
}
예제 #18
0
/*************************************************************************
 *
 * V e r i f y J a r
 */
int
VerifyJar(char *filename)
{
    FILE *fp;

    int ret;
    int status;
    int failed = 0;
    char *err;

    JAR *jar;
    JAR_Context *ctx;

    JAR_Item *it;

    jar = JAR_new();

    if ((fp = fopen(filename, "r")) == NULL) {
        perror(filename);
        exit(ERRX);
    } else
        fclose(fp);

    JAR_set_callback(JAR_CB_SIGNAL, jar, jar_cb);

    status = JAR_pass_archive(jar, jarArchGuess, filename, "some-url");

    if (status < 0 || jar->valid < 0) {
        failed = 1;
        PR_fprintf(outputFD,
                   "\nNOTE -- \"%s\" archive DID NOT PASS crypto verification.\n",
                   filename);
        if (status < 0) {
            const char *errtext;

            if (status >= JAR_BASE && status <= JAR_BASE_END) {
                errtext = JAR_get_error(status);
            } else {
                errtext = SECU_Strerror(PORT_GetError());
            }

            PR_fprintf(outputFD, "  (reported reason: %s)\n\n",
                       errtext);

            /* corrupt files should not have their contents listed */

            if (status == JAR_ERR_CORRUPT)
                return -1;
        }
        PR_fprintf(outputFD,
                   "entries shown below will have their digests checked only.\n");
        jar->valid = 0;
    } else
        PR_fprintf(outputFD,
                   "archive \"%s\" has passed crypto verification.\n", filename);

    if (verify_global(jar))
        failed = 1;

    PR_fprintf(outputFD, "\n");
    PR_fprintf(outputFD, "%16s   %s\n", "status", "path");
    PR_fprintf(outputFD, "%16s   %s\n", "------------", "-------------------");

    ctx = JAR_find(jar, NULL, jarTypeMF);

    while (JAR_find_next(ctx, &it) >= 0) {
        if (it && it->pathname) {
            rm_dash_r(TMP_OUTPUT);
            ret = JAR_verified_extract(jar, it->pathname, TMP_OUTPUT);
            /* if (ret < 0) printf ("error %d on %s\n", ret, it->pathname); */
            if (ret < 0)
                failed = 1;

            if (ret == JAR_ERR_PNF)
                err = "NOT PRESENT";
            else if (ret == JAR_ERR_HASH)
                err = "HASH FAILED";
            else
                err = "NOT VERIFIED";

            PR_fprintf(outputFD, "%16s   %s\n",
                       ret >= 0 ? "verified" : err, it->pathname);

            if (ret != 0 && ret != JAR_ERR_PNF && ret != JAR_ERR_HASH)
                PR_fprintf(outputFD, "      (reason: %s)\n",
                           JAR_get_error(ret));
        }
    }

    JAR_find_end(ctx);

    if (status < 0 || jar->valid < 0) {
        failed = 1;
        PR_fprintf(outputFD,
                   "\nNOTE -- \"%s\" archive DID NOT PASS crypto verification.\n",
                   filename);
        give_help(status);
    }

    JAR_destroy(jar);

    if (failed)
        return -1;
    return 0;
}
예제 #19
0
void handle_talk_event(POINT p)
{
	short i,j,force_special = 0,get_pc,s1 = -1,s2 = -1,s3 = -1;
	char asked[4];
	char place_string1[256] = "";
	char place_string2[256] = "";

	short a,b,c,d,ttype,which_talk_entry = -1;

	p.x -= 5;
	p.y -= 5;

	if (PtInRect(&talk_help_rect,p)) {
    	if (play_sounds == true) play_sound(37);
		party.help_received[5] = 0;
		give_help(205,6,0);
		return;
		}

	for (i = 0; i < 9; i++)
		if ((PtInRect(&preset_words[i].word_rect,p)) && ((talk_end_forced == false) || (i == 6) || (i == 5))) {
			click_talk_rect((char *) old_str1,(char *) old_str2,preset_words[i].word_rect);
			switch (i) {
				case 0: case 1: case 2: case 7: case 8:
					force_special = i + 1;
					break;
				case 3: case 4:
					force_special = i + 1;
					break;
				case 5: // save
					if (strnum1 <= 0) {
						MessageBeep(MB_OK);
						return;
						}
					for (j = 0; j < 120; j++)
						if ((party.talk_save[j].personality == store_personality) &&
						  (party.talk_save[j].str1 == strnum1) &&
						  (party.talk_save[j].str2 == strnum2)) {
						  	ASB("This is already saved.");
						  	print_buf();
						  	return;
						  	}
					for (j = 0; j < 120; j++)
						if (party.talk_save[j].personality <= 0) {
							give_help(57,0,0);
							play_sound(0);
							party.talk_save[j].personality = store_personality;
							party.talk_save[j].town_num = (unsigned char) c_town.town_num;
							party.talk_save[j].str1 = strnum1;
							party.talk_save[j].str2 = strnum2;
							ASB("Noted in journal.");
							j = 200;
							}
					if (j < 200) {
						MessageBeep(MB_OK);
						ASB("No more room in talking journal.");
						}
					print_buf();
					return;
					break;
				case 6: // quit
					end_talk_mode();

                	if(talk_end_forced == 10){ // party is in inn
                        talk_end_forced = true; // safety set
                        for(j=0; j < 700; j++){
                            party.age++;
                            // Specials countdowns
                            if ((party.age % 500 == 0) && (get_ran(1,0,5) == 3) && (adven.hasAbil(ITEM_DISEASE_PARTY) == true)) {
                                j = 900;
                                adven.disease(2);
                             }
                             // Plants and magic shops
                             if (party.age % 4000 == 0) refresh_store_items();

                             timed_special_happened = special_increase_age(0);//don't delay the trigger of the special, if there's a special

                             if(timed_special_happened && PSD[SDF_COMPATIBILITY_SPECIALS_INTERRUPT_REST] == 1){
                                j = 900;
               			        add_string_to_buf("  Rest interrupted.");
               			        print_buf();
                            }
                         }
                      }
					return;
					break;
				default:
					for (j = 0; j < 4; j++)
						asked[j] = preset_words[i].word[j];
					break;
				}
			i = 100;
			}
	if (i < 100) {
		for (i = 0; i < 50; i++)
			if ((PtInRect(&store_words[i].word_rect,p)) && (talk_end_forced == false)) {
				click_talk_rect((char *) old_str1,(char *) old_str2,store_words[i].word_rect);
				for (j = 0; j < 4; j++)
					asked[j] = store_words[i].word[j];

				i = 100;
				}
		}
    if(strcmp(talk_edit_string,"") != 0){
        for(j = 0; j < 4; j++)
            asked[j] = talk_edit_string[j];
        talk_edit_string[0] = '\0';
        i =  100;
        }

	if (i == 50) // no event
		return;
	if (force_special == 9) {
		get_text_response(1017,place_string1,0);
		asked[0] = place_string1[0];
		asked[1] = place_string1[1];
		asked[2] = place_string1[2];
		asked[3] = place_string1[3];
		}

	if ((asked[0] == 'n') && (asked[1] == 'a') &&(asked[2] == 'm') &&(asked[3] == 'e')) {
		force_special = 2;
		}
	if ((asked[0] == 'l') && (asked[1] == 'o') &&(asked[2] == 'o') &&(asked[3] == 'k')) {
		force_special = 1;
		}
	if (((asked[0] == 'j') && (asked[1] == 'o') &&(asked[2] == 'b')) ||
		((asked[0] == 'w') && (asked[1] == 'o') &&(asked[2] == 'r')&&(asked[3] == 'k')) ) {
		force_special = 3;
		}
	if((asked[0] == 'b') && (asked[1] == 'u') && (asked[2] == 'y'))
	   force_special = 4;
	if((asked[0] == 'b') && (asked[1] == 'y') && (asked[2] == 'e')){
		end_talk_mode();
        return;
        }

	if (force_special > 0) {
		switch (force_special) {
			case 1: case 2: case 3:
				GetIndString(place_string1,120 + ((store_personality - 1) / 10),
				 ((store_personality - 1) % 10) * 3 + 10 + force_special);
				sprintf((char *) place_string1,"%s",data_store3->talk_strs[store_personality % 10 + 10 * force_special]);

				oldstrnum1 = strnum1; oldstrnum2 = strnum2;
				strnum1 =  store_personality % 10 + 10 * force_special;
				strnum2 = 0;
				strcpy((char *) one_back1,(char *) old_str1);
				strcpy((char *) one_back2,(char *) old_str2);
				strcpy((char *) old_str1,(char *) place_string1);
				strcpy((char *) old_str2,(char *) place_string2);
				place_talk_str((char *) place_string1,(char *) place_string2,0,dummy_rect);
				return;
				break;
			case 4: // buy button
				asked[0] = 'p';asked[1] = 'u';asked[2] = 'r';asked[3] = 'c';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 's';asked[1] = 'a';asked[2] = 'l';asked[3] = 'e';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 'h';asked[1] = 'e';asked[2] = 'a';asked[3] = 'l';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 'i';asked[1] = 'd';asked[2] = 'e';asked[3] = 'n';
				if (scan_for_response(asked) >= 0)
					break;
				asked[0] = 't';asked[1] = 'r';asked[2] = 'a';asked[3] = 'i';
				if (scan_for_response(asked) >= 0)
					break;
				break;
			case 5: // sell button
				asked[0] = 's';asked[1] = 'e';asked[2] = 'l';asked[3] = 'l';
				if (scan_for_response(asked) >= 0)
					break;
				break;
			case 8: // back 1
				strnum1 = oldstrnum1; strnum2 = oldstrnum2;
				strcpy((char *) place_string1,(char *) one_back1);
				strcpy((char *) place_string2,(char *) one_back2);
				strcpy((char *) one_back1,(char *) old_str1);
				strcpy((char *) one_back2,(char *) old_str2);
				strcpy((char *) old_str1,(char *) place_string1);
				strcpy((char *) old_str2,(char *) place_string2);
				place_talk_str((char *) place_string1,(char *) place_string2,0,dummy_rect);
				return;
				break;
			}
		}

	which_talk_entry = scan_for_response(asked);
	if ((which_talk_entry < 0) || (which_talk_entry > 59)) {
		strcpy((char *) one_back1,(char *) old_str1);
		strcpy((char *) one_back2,(char *) old_str2);
		sprintf((char *) old_str2,"");
		sprintf((char *) old_str1,"%s",data_store3->talk_strs[store_personality % 10 + 160]);
		if (strlen((char *) old_str1) < 2)
			sprintf((char *) old_str1,"You get no response.");
		place_talk_str((char *) old_str1,(char *) old_str2,0,dummy_rect);
		strnum1 = -1;
		return;
		}

	ttype = talking.talk_nodes[which_talk_entry].type;
	a = talking.talk_nodes[which_talk_entry].extras[0];
	b = talking.talk_nodes[which_talk_entry].extras[1];
	c = talking.talk_nodes[which_talk_entry].extras[2];
	d = talking.talk_nodes[which_talk_entry].extras[3];

	sprintf(place_string1,"%s",data_store3->talk_strs[40 + which_talk_entry * 2]);
	sprintf(place_string2,"%s",data_store3->talk_strs[40 + which_talk_entry * 2 + 1]);

	oldstrnum1 = strnum1; oldstrnum2 = strnum2;
	strnum1 =  40 + which_talk_entry * 2; strnum2 = 40 + which_talk_entry * 2 + 1;

	switch(ttype) {
		case TALK_REGULAR:
			break;
		case TALK_DEP_ON_SDF:
			if (PSD[a][b] > c) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_SET_SDF:
			PSD[a][b] = 1;
			break;
		case TALK_INN:
			if (party.gold < a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
				else {
					talk_end_forced = true;
					party.gold -= a;
					put_pc_screen();
                    if(PSD[SDF_COMPATIBILITY_CHECK_TIMERS_WHILE_RESTING] == 1){
                       talk_end_forced = 10;
                       adven.heal(30 * b);
	                   adven.restoreSP(25 * b);
      				   c_town.p_loc.x = c;
	          		   c_town.p_loc.y = d;
			           center = c_town.p_loc;
                       }
					else{
                    adven.heal(30 * b);
					adven.restoreSP(25 * b);
					party.age += 700;
					c_town.p_loc.x = c;
					c_town.p_loc.y = d;
					center = c_town.p_loc;
                    }
				}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_DEP_ON_TIME:
			if (day_reached((unsigned char) a,0) == true) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_DEP_ON_TIME_AND_EVENT:
			if (day_reached((unsigned char) a,(unsigned char) b) == true) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_DEP_ON_TOWN:
			if (c_town.town_num != a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_BUY_ITEMS:
			c = minmax(1,30,(int)c);
			start_shop_mode(SHOP_MISC_SHOP,b,
				b + c - 1,a, place_string1);
			strnum1 = -1;
			return;
		case TALK_TRAINING:
			if ((get_pc = char_select_pc(1,0,"Train who?")) < 6) {
				strnum1 = -1;
				spend_xp(get_pc,1, 0);
				}
			sprintf(place_string1, "You conclude your training.");
            put_pc_screen();
			return;

		case TALK_BUY_MAGE: case TALK_BUY_PRIEST: case TALK_BUY_ALCHEMY:
			c = minmax(1,30,(int)c);
			start_shop_mode(ttype + 1,b,
				b + c - 1,a, place_string1);
			strnum1 = -1;
			return;
		case TALK_BUY_HEALING: //healer
			start_shop_mode(SHOP_HEALER,0,0,a, place_string1);
			strnum1 = -1;
			return;
			break;
		case TALK_SELL_WEAPONS: // sell weap
			strnum1 = -1;
			stat_screen_mode = 3;
			put_item_screen(stat_window,1);
			give_help(42,43,0);
			break;
		case TALK_SELL_ARMOR: // sell armor
			strnum1 = -1;
			stat_screen_mode = 4;
			put_item_screen(stat_window,1);
			give_help(42,43,0);
			break;
		case TALK_SELL_ITEMS: // sell misc
			strnum1 = -1;
			stat_screen_mode = 5;
			put_item_screen(stat_window,1);
			give_help(42,43,0);
			break;
		case TALK_IDENTIFY: case TALK_ENCHANT: // ident, enchant
            strnum1 = -1;
			stat_screen_mode = (ttype == 16) ? 2 : 6;
			shop_identify_cost = a;
			put_item_screen(stat_window,1);
			give_help(ttype - 16 + 44,0,0);
			break;
		case TALK_BUY_INFO:
			if (party.gold < a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
				else {
					party.gold -= a;
					put_pc_screen();

					}
			sprintf(place_string2,"");
			strnum2 = 0;
			break;
		case TALK_BUY_SDF:
			if ((sd_legit(b,c) == true) && (PSD[b][c] == d)) {
				sprintf(place_string1, "You've already learned that.");
				strnum1 = -1;
				}
			else if (party.gold < a) {
				strnum1 = strnum2;
				strcpy(place_string1, place_string2);
				}
				else {
					party.gold -= a;
					put_pc_screen();
					if (sd_legit(b,c) == true)
						PSD[b][c] = d;
						else give_error("Invalid Stuff Done flag called in conversation.","",0);
					}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_BUY_SHIP:
			if (party.gold < a) {
				strnum1 = strnum2;
				strnum2 = 0;
				strcpy(place_string1, place_string2);
				sprintf(place_string2,"");
				break;
				}
				else {
					for (i = b; i <= b + c; i++)
						if ((i >= 0) && (i < 30) && (party.boats[i].property == true)) {
							party.gold -= a;
							put_pc_screen();
							party.boats[i].property = false;
							sprintf(place_string2,"");
							strnum2 = 0;
							i = 1000;
							}
					if (i >= 1000)
						break;
					}
			sprintf(place_string1, "There are no boats left.");
			sprintf(place_string2,"");
			strnum1 = -1;
			strnum2 = -1;
			break;
		case TALK_BUY_HORSE:
			if (party.gold < a) {
				strnum1 = strnum2;
				strnum2 = 0;
				strcpy(place_string1, place_string2);
				sprintf(place_string2,"");
				break;
				}
				else {
					for (i = b; i <= b + c; i++)
						if ((i >= 0) && (i < 30) && (party.horses[i].property == true)) {
							party.gold -= a;
							put_pc_screen();
							party.horses[i].property = false;
							sprintf(place_string2,"");
							strnum2 = 0;
							i = 1000;
							}
					if (i >= 1000)
						break;
					}
			sprintf(place_string1, "There are no horses left.");
			sprintf(place_string2,"");
			strnum1 = -1;
			strnum2 = -1;
			break;
		case TALK_BUY_SPEC_ITEM:
			if (party.spec_items[a] > 0) {
				sprintf(place_string1, "You already have it.");
				strnum1 = -1;
				}
			else if (party.gold < b) {
				strcpy(place_string1, place_string2);
				strnum1 = strnum2;
				}
				else {
					party.gold -= b;
					put_pc_screen();
					party.spec_items[a] = 1;
					}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_BUY_JUNK:
			start_shop_mode(SHOP_MAGIC_SHOP_1 + b,0,
				9,a, place_string1);
			strnum1 = -1;
			return;
		case TALK_BUY_TOWN_LOC:
			if (party.can_find_town[b] > 0) {
				}
				else if (party.gold < a) {
					strnum1 = strnum2;
					strcpy(place_string1, place_string2);
					}
					else {
						party.gold -= a;
						put_pc_screen();
						party.can_find_town[b] = 1;
						}
			strnum2 = 0;
			sprintf(place_string2,"");
			break;
		case TALK_END_FORCE:
			talk_end_forced = true;
			break;
		case TALK_END_FIGHT:
			c_town.monst.dudes[store_m_num].attitude = 1;
			c_town.monst.dudes[store_m_num].mobile = 1;
			talk_end_forced = true;
			break;
		case TALK_END_ALARM:
			set_town_status(0);
			talk_end_forced = true;
			break;
		case TALK_END_DIE:
			c_town.monst.dudes[store_m_num].active = 0;
            // Special killing effects
            if (sd_legit(c_town.monst.dudes[store_m_num].monst_start.spec1,c_town.monst.dudes[store_m_num].monst_start.spec2) == true)
                party.stuff_done[c_town.monst.dudes[store_m_num].monst_start.spec1][c_town.monst.dudes[store_m_num].monst_start.spec2] = 1;
			talk_end_forced = true;
			break;
		case TALK_CALL_TOWN_SPEC: // town special
			 run_special(SPEC_TALK,2,a,c_town.p_loc,&s1,&s2,&s3);
			// check s1 & s2 to see if we got diff str, and, if so, munch old strs
			if ((s1 >= 0) || (s2 >= 0)) {
				strnum1 = -1;
				strnum2 = -1;
				sprintf(place_string1,"");
				sprintf(place_string2,"");
				}
			 get_strs(place_string1, place_string2,2,s1,s2);
			 if (s1 >= 0) strnum1 = 2000 + s1;
			 if (s2 >= 0) strnum2 = 2000 + s2;
			 put_pc_screen();
			 put_item_screen(stat_window,0);
			 break;
		case TALK_CALL_SCEN_SPEC: // scen special
			 run_special(SPEC_TALK,0,a,c_town.p_loc,&s1,&s2,&s3);
			// check s1 & s2 to see if we got diff str, and, if so, munch old strs
			if ((s1 >= 0) || (s2 >= 0)) {
				strnum1 = -1;
				strnum2 = -1;
				sprintf(place_string1,"");
				sprintf(place_string2,"");
				}
			 get_strs(place_string1, place_string2,0,s1,s2);
			 if (s1 >= 0) strnum1 = 3000 + s1;
			 if (s2 >= 0) strnum2 = 3000 + s2;
			put_pc_screen();
			put_item_screen(stat_window,0);
			break;
		}

	strcpy(one_back1, old_str1);
	strcpy(one_back2, old_str2);
	strcpy(old_str1, place_string1);
	strcpy(old_str2, place_string2);
	place_talk_str(old_str1, old_str2,0,dummy_rect);
}
예제 #20
0
파일: sdiff.c 프로젝트: 0mp/freebsd
/* interpret an edit command */
static bool
edit (struct line_filter *left, char const *lname, lin lline, lin llen,
      struct line_filter *right, char const *rname, lin rline, lin rlen,
      FILE *outfile)
{
  for (;;)
    {
      int cmd0, cmd1;
      bool gotcmd = false;

      cmd1 = 0; /* Pacify `gcc -W'.  */

      while (! gotcmd)
	{
	  if (putchar ('%') != '%')
	    perror_fatal (_("write failed"));
	  ck_fflush (stdout);

	  cmd0 = skip_white ();
	  switch (cmd0)
	    {
	    case '1': case '2': case 'l': case 'r':
	    case 's': case 'v': case 'q':
	      if (skip_white () != '\n')
		{
		  give_help ();
		  flush_line ();
		  continue;
		}
	      gotcmd = true;
	      break;

	    case 'e':
	      cmd1 = skip_white ();
	      switch (cmd1)
		{
		case '1': case '2': case 'b': case 'd': case 'l': case 'r':
		  if (skip_white () != '\n')
		    {
		      give_help ();
		      flush_line ();
		      continue;
		    }
		  gotcmd = true;
		  break;
		case '\n':
		  gotcmd = true;
		  break;
		default:
		  give_help ();
		  flush_line ();
		  continue;
		}
	      break;

	    case EOF:
	      if (feof (stdin))
		{
		  gotcmd = true;
		  cmd0 = 'q';
		  break;
		}
	      /* Fall through.  */
	    default:
	      flush_line ();
	      /* Fall through.  */
	    case '\n':
	      give_help ();
	      continue;
	    }
	}

      switch (cmd0)
	{
	case '1': case 'l':
	  lf_copy (left, llen, outfile);
	  lf_skip (right, rlen);
	  return true;
	case '2': case 'r':
	  lf_copy (right, rlen, outfile);
	  lf_skip (left, llen);
	  return true;
	case 's':
	  suppress_common_lines = true;
	  break;
	case 'v':
	  suppress_common_lines = false;
	  break;
	case 'q':
	  return false;
	case 'e':
	  {
	    int fd;

	    if (tmpname)
	      tmp = fopen (tmpname, "w");
	    else
	      {
		if ((fd = temporary_file ()) < 0)
		  perror_fatal ("mkstemp");
		tmp = fdopen (fd, "w");
	      }

	    if (! tmp)
	      perror_fatal (tmpname);

	    switch (cmd1)
	      {
	      case 'd':
		if (llen)
		  {
		    if (llen == 1)
		      fprintf (tmp, "--- %s %ld\n", lname, (long int) lline);
		    else
		      fprintf (tmp, "--- %s %ld,%ld\n", lname,
			       (long int) lline,
			       (long int) (lline + llen - 1));
		  }
		/* Fall through.  */
	      case '1': case 'b': case 'l':
		lf_copy (left, llen, tmp);
		break;

	      default:
		lf_skip (left, llen);
		break;
	      }

	    switch (cmd1)
	      {
	      case 'd':
		if (rlen)
		  {
		    if (rlen == 1)
		      fprintf (tmp, "+++ %s %ld\n", rname, (long int) rline);
		    else
		      fprintf (tmp, "+++ %s %ld,%ld\n", rname,
			       (long int) rline,
			       (long int) (rline + rlen - 1));
		  }
		/* Fall through.  */
	      case '2': case 'b': case 'r':
		lf_copy (right, rlen, tmp);
		break;

	      default:
		lf_skip (right, rlen);
		break;
	      }

	    ck_fclose (tmp);

	    {
	      int wstatus;
	      int werrno = 0;
	      ignore_SIGINT = true;
	      checksigs ();

	      {
#if ! (HAVE_WORKING_FORK || HAVE_WORKING_VFORK)
		char *command =
		  xmalloc (quote_system_arg (0, editor_program)
			   + 1 + strlen (tmpname) + 1);
		sprintf (command + quote_system_arg (command, editor_program),
			 " %s", tmpname);
		wstatus = system (command);
		if (wstatus == -1)
		  werrno = errno;
		free (command);
#else
		pid_t pid;

		pid = vfork ();
		if (pid == 0)
		  {
		    char const *argv[3];
		    int i = 0;

		    argv[i++] = editor_program;
		    argv[i++] = tmpname;
		    argv[i] = 0;

		    execvp (editor_program, (char **) argv);
		    _exit (errno == ENOENT ? 127 : 126);
		  }

		if (pid < 0)
		  perror_fatal ("fork");

		while (waitpid (pid, &wstatus, 0) < 0)
		  if (errno == EINTR)
		    checksigs ();
		  else
		    perror_fatal ("waitpid");
#endif
	      }

	      ignore_SIGINT = false;
	      check_child_status (werrno, wstatus, EXIT_SUCCESS,
				  editor_program);
	    }

	    {
	      char buf[SDIFF_BUFSIZE];
	      size_t size;
	      tmp = ck_fopen (tmpname, "r");
	      while ((size = ck_fread (buf, SDIFF_BUFSIZE, tmp)) != 0)
		{
		  checksigs ();
		  ck_fwrite (buf, size, outfile);
		}
	      ck_fclose (tmp);
	    }
	    return true;
	  }
	default:
	  give_help ();
	  break;
	}
    }
}