Example #1
0
int main()
{
  char* input = NULL;
  char** arg_list = NULL;
  int status = 0;
  int args = 0;
  int mode = 0;
  char * spec_res = NULL;
  do
  {
    args = 0;
    input = NULL;
    arg_list = NULL;
    status = dsh_prompt( &input );
    scanf( "%*1c" );
    
    if( !status )
    {
      status = parse_input( &args, input, &arg_list );
      mode = parse_special( arg_list , &spec_res );
      fflush(stdout);
      if( mode == -1 )
        fprintf( stderr , "Parse error: Verify command and order of operators\n" );
      else if( mode == 0 )
        status = run_command( args , arg_list ); 
      else
        status = run_special( spec_res , mode );   
    }
    
    if( input != NULL )
      free( input );
    if( arg_list != NULL )
      free( arg_list );
  }while( status < 2 );

  return 0;
}
Example #2
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);
}