//------- Begin of function TalkRes::reply_talk_msg --------// // // If the nation which receives this message decides to accept // the offer of this message, this function is called. // // <int> talkMsgRecno - the recno of the TalkMsg // <char> replyType - reply type, either REPLY_ACCEPT or REPLY_REJECT // <char> remoteAction - remote action type // void TalkRes::reply_talk_msg(int talkMsgRecno, char replyType, char remoteAction) { //-------- send multiplayer -----------// if( !remoteAction && remote.is_enable() ) { // packet structure : <talkRecno:int> <reply type:char> <padding:char> char* charPtr = remote.new_send_queue_msg( MSG_REPLY_TALK_MSG, sizeof(int)+2*sizeof(char) ); *(int *)charPtr = talkMsgRecno; charPtr[sizeof(int)] = replyType; charPtr[sizeof(int)+sizeof(char)] = 0; return; } //-------------------------------------// err_when( is_talk_msg_deleted(talkMsgRecno) ); TalkMsg* talkMsgPtr = get_talk_msg(talkMsgRecno); Nation* fromNation = nation_array[talkMsgPtr->from_nation_recno]; err_when( talkMsgPtr->reply_type == REPLY_NOT_NEEDED ); err_when( replyType != REPLY_ACCEPT && replyType != REPLY_REJECT ); talkMsgPtr->reply_type = replyType; talkMsgPtr->reply_date = info.game_date; switch( fromNation->nation_type ) { case NATION_OWN: news_array.diplomacy( talkMsgRecno ); // ###### begin Gilbert 9/10 ########// // sound effect se_ctrl.immediate_sound("GONG"); // ###### end Gilbert 9/10 ########// break; case NATION_AI: fromNation->ai_notify_reply( talkMsgRecno ); // notify the AI nation about this reply. break; case NATION_REMOTE: break; } //---- set the replying nation's never accept date so that the replying nation will not make an offer soon after it rejects the offer nation_array[talkMsgPtr->to_nation_recno]->get_relation(talkMsgPtr->from_nation_recno) ->set_never_accept_until_date(talkMsgPtr->talk_id, 30); //------- if the offer is accepted -------// if( talkMsgPtr->reply_type == REPLY_ACCEPT ) talkMsgPtr->process_accepted_reply(); //--- if the player has replyed the message, remove it from the news display ---// if( talkMsgPtr->to_nation_recno == nation_array.player_recno ) news_array.remove(NEWS_DIPLOMACY, talkMsgRecno); }
//----- Begin of function Nation::ai_process_talk_msg -----// // // action_para - recno of the message in talk_res.talk_msg_array. // int Nation::ai_process_talk_msg(ActionNode* actionNode) { if( talk_res.is_talk_msg_deleted(actionNode->action_para) ) // if the talk message has been deleted return -1; TalkMsg* talkMsg = talk_res.get_talk_msg(actionNode->action_para); err_when( talkMsg->talk_id < 1 || talkMsg->talk_id > MAX_TALK_TYPE ); err_when( talkMsg->from_nation_recno == nation_recno ); err_when( talkMsg->to_nation_recno != nation_recno ); if( !talkMsg->is_valid_to_reply() ) // if it is no longer valid return -1; //----- call the consider function -------// if( talkMsg->reply_type == REPLY_WAITING ) { int rc = consider_talk_msg(talkMsg); if( rc==1 ) // if rc is not 1 or 0, than the consider function have processed itself, no need to call reply_talk_msg() here talk_res.reply_talk_msg( actionNode->action_para, REPLY_ACCEPT, COMMAND_AI ); else if( rc==0 ) talk_res.reply_talk_msg( actionNode->action_para, REPLY_REJECT, COMMAND_AI ); // don't reply if rc is neither 0 or 1 } else err_here(); return -1; // always return -1 to remove the action from action_array. }
//------ Begin of function News::diplomacy -----// // // Diplomatic messages from other nations. // // short_para1 = the recno of TalkMsg in talk_res.talk_msg_array. // void News::diplomacy() { err_when( talk_res.is_talk_msg_deleted(short_para1) ); TalkMsg* talkMsgPtr = talk_res.get_talk_msg(short_para1); str = talkMsgPtr->msg_str(nation_array.player_recno); }
//-------- Begin of static function put_talk_msg_rec --------// // static void put_talk_msg_rec(int recNo, int x1, int y, int refreshFlag) { TalkMsgDisp* talkMsgDisp = (TalkMsgDisp*) info.talk_msg_disp_array.get(recNo); TalkMsg* talkMsg = talk_res.get_talk_msg(talkMsgDisp->recno); int x=x1, isTo; x+=3; y+=2; if( !talkMsgDisp->is_reply ) // if not a replying message isTo = talkMsg->from_nation_recno == info.viewing_nation_recno; // you send a message to a nation else isTo = talkMsg->from_nation_recno != info.viewing_nation_recno; //---------------------------------------// // char* str1; // if( isTo ) // str1 = translate.process("To"); // else // str1 = translate.process("From"); // font_bld.put( x , y, str1 ); // x += font_bld.text_width(str1)+5; x = font_bld.put( x, y, isTo?text_reports.str_send_to():text_reports.str_send_from() ); x += 5; //---------------------------------------// if( talkMsg->from_nation_recno == info.viewing_nation_recno ) nation_array[talkMsg->to_nation_recno]->disp_nation_color(x, y+2); else nation_array[talkMsg->from_nation_recno]->disp_nation_color(x, y+2); x+=18; String str; // str = translate.process("on "); // if( talkMsgDisp->is_reply ) // str += date.date_str(talkMsg->reply_date); // else // str += date.date_str(talkMsg->date); // str += " :"; // font_bld.put( x , y, str ); if( talkMsgDisp->is_reply ) str = date.date_str(talkMsg->reply_date); else str = date.date_str(talkMsg->date); font_bld.put( x, y, text_reports.str_on_date((char *)str) ); font_bld.put( x1, y+13, talkMsg->msg_str(info.viewing_nation_recno, talkMsgDisp->is_reply), 0, browse_talk_msg.ix2 ); }
void TalkRes::player_reply(int talkMsgRecno) { //------- set the reply choices --------// err_when( is_talk_msg_deleted(talkMsgRecno) ); TalkMsg* talkMsg = get_talk_msg(talkMsgRecno); if( nation_array.is_deleted(talkMsg->from_nation_recno) ) return; init_conversion(talkMsg->from_nation_recno); talk_choice_count = 0; cur_choice_id = 0; reply_talk_msg_recno = talkMsgRecno; //--------- add talk choices ---------// static String msgStr, msgStr2; msgStr = talkMsg->msg_str(nation_array.player_recno); // make a static copy of it. choice_question = msgStr; //---- see if this message has a second line -----// msgStr2 = talkMsg->msg_str(nation_array.player_recno, 0, 1); // 1-display the second line of the question if( msgStr!=msgStr2 ) choice_question_second_line = msgStr2; else choice_question_second_line = NULL; //--------- add choices to the question ---------// if( talkMsg->can_accept() ) // whether the replier can accept the request or demand of the message add_talk_choice( text_talk.str_accept_(), 1 ); // "Accept.", 1 ); add_talk_choice( text_talk.str_reject_(), 0 ); // "Reject.", 0 ); //--- switch to the nation report mode and go to the diplomacy mode ---// info.init_player_reply( talkMsg->from_nation_recno ); save_view_mode = sys.view_mode; sys.set_view_mode(MODE_NATION); }
//------- Begin of function TalkRes::del_all_nation_msg --------// // // Delete all messages related to this nation. // void TalkRes::del_all_nation_msg(int nationRecno) { int i; TalkMsg* talkMsg; for( i=talk_msg_count() ; i>0 ; i-- ) { if( is_talk_msg_deleted(i) ) continue; talkMsg = get_talk_msg(i); if( talkMsg->from_nation_recno == nationRecno || talkMsg->to_nation_recno == nationRecno || !talkMsg->is_valid_to_disp() ) // if the nation is the talk_para1 (e.g. TRADE_EMBARGO), is_valid_to_disp() will return 0 and the talk message should than be deleted { del_talk_msg(i); } } }
//--------- Begin of static function disp_talk_msg_sent ---------// // static void disp_talk_msg_sent(int refreshFlag) { //--- filter out talk messages sent by this nation and sort them by date ---// TalkMsg* talkMsg; TalkMsgDisp talkMsgDisp; static short lastNationRecno=0; int nationRecno = nation_filter(info.browse_nation_recno); if( lastNationRecno != nationRecno ) { info.browse_talk_msg_recno = 1; // reset the browser recno of the viewing nation has been changed lastNationRecno = nationRecno; } //--------------------------------------------// info.talk_msg_disp_array.zap(); for( short i=1 ; i<=talk_res.talk_msg_count() ; i++ ) { if( talk_res.is_talk_msg_deleted(i) ) continue; talkMsg = talk_res.get_talk_msg(i); if( !talkMsg->is_valid_to_disp() ) // don't link it out, otherwise it may cause multiplayer sync problem. continue; if( talkMsg->from_nation_recno == nationRecno || talkMsg->to_nation_recno == nationRecno ) { if( talkMsg->from_nation_recno == info.viewing_nation_recno || talkMsg->to_nation_recno == info.viewing_nation_recno ) { if( !nation_array.is_deleted(talkMsg->from_nation_recno) && !nation_array.is_deleted(talkMsg->to_nation_recno) ) { talkMsgDisp.recno = i; talkMsgDisp.date = talkMsg->date; talkMsgDisp.is_reply = 0; info.talk_msg_disp_array.linkin(&talkMsgDisp); if( talkMsg->reply_date ) { talkMsgDisp.recno = i; talkMsgDisp.date = talkMsg->reply_date; talkMsgDisp.is_reply = 1; info.talk_msg_disp_array.linkin(&talkMsgDisp); } } } } } if( info.talk_msg_disp_array.size() > 0 ) info.talk_msg_disp_array.quick_sort(sort_talk_msg); //----- display a browser of the talk msg sent -----// if( refreshFlag == INFO_REPAINT || !browse_talk_msg.init_flag ) { browse_talk_msg.init( REPORT_DET_X1, REPORT_DET_Y1, REPORT_DET_X2, REPORT_DET_Y2, 0, 30, info.talk_msg_disp_array.size(), put_talk_msg_rec, 1 ); browse_talk_msg.open(info.browse_talk_msg_recno); } else { browse_talk_msg.paint(); browse_talk_msg.open(info.browse_talk_msg_recno, info.talk_msg_disp_array.size()); } info.browse_talk_msg_recno = browse_talk_msg.recno(); }