Example #1
0
int AssocPair::rmv_relation(int iface_no, iBase_EntitySetHandle *sets,
                            int num_sets)
{
  if (relStatus[iface_no] == iRel_NOTEXIST)
    ERRORR(iBase_FAILURE, "Relation does not exist on this side");

  // TODO: handle "both" case

  // Remove the opposite side first
  if (relStatus[!iface_no] == iRel_ACTIVE) {
    if (entOrSet[!iface_no] == iRel_ENTITY) {
      std::vector<iBase_EntityHandle> other_entities(num_sets);
      CHK_ERRORR( get_relation(iface_no, sets, num_sets, &other_entities[0]) );
      CHK_ERRORR( relSides[!iface_no]->rmv_relation_side(&other_entities[0],
                                                         num_sets) );
    }
    else {
      std::vector<iBase_EntitySetHandle> other_sets(num_sets);
      CHK_ERRORR( get_relation(iface_no, sets, num_sets, &other_sets[0]) );
      CHK_ERRORR( relSides[!iface_no]->rmv_relation_side(&other_sets[0],
                                                         num_sets) );
    }
  }

  return relSides[iface_no]->rmv_relation_side(sets, num_sets);
}
Example #2
0
//----- Begin of function Nation::should_diplomacy_retry -----//
//
int Nation::should_diplomacy_retry(int talkId, int nationRecno)
{
	if( !talk_res.can_send_msg(nationRecno, nation_recno, talkId ) )
		return 0;

	int retryInterval;

	//--- shorter retry interval for demand talk message ----//

	if( talkId == TALK_DEMAND_TRIBUTE ||
		 talkId == TALK_DEMAND_AID ||
		 talkId == TALK_EXCHANGE_TECH )
	{
		retryInterval = 60 + 60 * (100-pref_diplomacy_retry) / 100;		// 2-4 months
	}
	else
	{
		retryInterval = 90 + 270 * (100-pref_diplomacy_retry) / 100;		// 3 months to 12 months before next try
	}

	if( info.game_date <
		get_relation(nationRecno)->never_accept_until_date_array[talkId-1] )
	{
		return 0;
	}

	return info.game_date >
			 get_relation(nationRecno)->last_talk_reject_date_array[talkId-1] + retryInterval;
}
short path_consistency_method_tripple(struct allen_web* web, unsigned int a,
		unsigned int b, unsigned int c) {
	allen_relation ab = get_relation(web, a, b);
	allen_relation bc = get_relation(web, b, c);
	allen_relation ac = get_relation(web, a, c);

	//calculate the ac
	allen_relation cal_ac = allen_p_function(ab, bc);

	//intersect the calculated one with the existing one
	allen_relation new_ac = intersect_relation(web, a, c, cal_ac);

	//error in the web
	if (new_ac == 0) {
		log(ERROR, "Consistency check of %d,%d and %d failed!",
				get_mapped_nr(web, a), get_mapped_nr(web, b),
				get_mapped_nr(web, c));
		return -1;
	}
	//nothing changed
	else if (new_ac == ac)
		return 0;
	//value changed
	else {
		return 1;
	}
}
short check_tripple_consistency(struct allen_web* web, unsigned int a,
		unsigned int b, unsigned int c) {
	allen_relation ab = get_relation(web, a, b);
	allen_relation bc = get_relation(web, b, c);
	allen_relation ac = get_relation(web, a, c);

	if (check_allen_rel_consistency(ab, bc, ac) != 0) {
		log(ERROR, "Consistency check of %d,%d and %d failed!", a, b, c);
		return 1;
	} else
		return 0;
}
Example #5
0
//----- Begin of function Nation::consider_trade_embargo -----//
//
int Nation::consider_trade_embargo(TalkMsg* talkMsg)
{
	int fromRelationRating    = ai_overall_relation_rating(talkMsg->from_nation_recno);
	int againstRelationRating = ai_overall_relation_rating(talkMsg->talk_para1);

	NationRelation* fromRelation 	  = get_relation(talkMsg->from_nation_recno);
	NationRelation* againstRelation = get_relation(talkMsg->talk_para1);

	//--- if we don't have a good enough relation with the requesting nation, turn down the request ---//

	if( fromRelation->good_relation_duration_rating < 5 )
		return 0;

	//--- if we are more friendly with the against nation than the requesting nation, turn down the request ---//

	if( againstRelation->good_relation_duration_rating >
		 fromRelation->good_relation_duration_rating )
	{
		return 0;
	}

	//--- if we have a large trade with the against nation or have a larger trade with the against nation than the requesting nation ---//

	int fromTrade 	  = trade_rating(talkMsg->from_nation_recno);
	int againstTrade = trade_rating(talkMsg->talk_para1);

	if( againstTrade > 40 ||
		 ( againstTrade > 10 && againstTrade - fromTrade > 15 ) )
	{
		return 0;
	}

	//--- if the nation is having a financial difficulty, it won't agree ---//

	if( cash < 2000 * pref_cash_reserve / 100  )
		return 0;

	//--------------------------------------------//

	int acceptRating = 75;

	//--- it won't declare war with a friendly or allied nation easily ---//

	if( againstRelation->status >= RELATION_FRIENDLY )		// no need to handle RELATION_ALLIANCE separately as ai_overall_relation_relation() has already taken it into account
		acceptRating += 100;

	return fromRelationRating - againstRelationRating > acceptRating;
}
Example #6
0
//----- Begin of function Nation::ai_surrender_to_rating -----//
//
// return a rating on how much the nation will tend to surrender
// to the specific nation.
//
int Nation::ai_surrender_to_rating(int nationRecno)
{
	Nation* 			 nationPtr = nation_array[nationRecno];
	NationRelation* nationRelation = get_relation(nationRecno);

	//--- higher tendency to surrender to a powerful nation ---//

	int curRating = nationPtr->overall_rank_rating() - overall_rank_rating();

	curRating += (nationRelation->ai_relation_level-40);

	curRating += (int) nationRelation->good_relation_duration_rating*3;

	curRating += (int) nationPtr->reputation/2;

	//------ shouldn't surrender to an enemy --------//

	if( nationRelation->status == NATION_HOSTILE )
		curRating -= 100;

	//--- if the race of the kings are the same, the chance is higher ---//

	if( race_res.is_same_race( nationPtr->race_id, race_id ) )
		curRating += 20;

	return curRating;
}
Example #7
0
//----- Begin of function Nation::consider_alliance_treaty -----//
//
int Nation::consider_alliance_treaty(int withNationRecno)
{
	if( nation_array[withNationRecno]->is_human() != is_human() )
		return 0;

	NationRelation* nationRelation = get_relation(withNationRecno);

	if( nationRelation->status >= RELATION_ALLIANCE )		// already has a friendly relationship
		return -1;			// -1 means don't reply

	if( nationRelation->ai_relation_level < 40 )
		return -1;

	//------- some consideration first -------//

	if( !should_consider_friendly(withNationRecno) )
		return -1;

	//------ total import and export amounts --------//

	int curRating = consider_alliance_rating(withNationRecno);

	int acceptRating = 80 - pref_allying_tendency/4 - pref_peacefulness/8;  // range of acceptRating: 43 to 80

	return curRating - acceptRating;
}
Example #8
0
//----- Begin of function Nation::think_trade_treaty -----//
//
int Nation::think_trade_treaty()
{
	Nation* 			nationPtr;
	NationRelation *ourRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationPtr = nation_array[i];

		ourRelation = get_relation(i);

		if( !ourRelation->has_contact )
			continue;

		//------- propose a trade treaty --------//

		if( !ourRelation->trade_treaty )
		{
			if( consider_trade_treaty(i) > 0 )
			{
				if( should_diplomacy_retry(TALK_PROPOSE_TRADE_TREATY, i) )
				{
					talk_res.ai_send_talk_msg(i, nation_recno, TALK_PROPOSE_TRADE_TREATY);
					ourRelation->ai_demand_trade_treaty = 0;
					return 1;
				}
			}
		}
	}

	return 0;
}
Example #9
0
//----- Begin of function Nation::consider_alliance_rating -----//
//
// Return a rating from 0 to 100 for whether this nation should ally
// with the given nation.
//
int Nation::consider_alliance_rating(int nationRecno)
{
	Nation* nationPtr = nation_array[nationRecno];

	//---- the current relation affect the alliance tendency ---//

	NationRelation* nationRelation = get_relation(nationRecno);

	int allianceRating = nationRelation->ai_relation_level-20;

	//--- if the nation has a bad record of starting wars with us before, decrease the rating ---//

	allianceRating -= nationRelation->started_war_on_us_count * 20;

	//------ add the trade rating -------//

	int tradeRating = trade_rating(nationRecno) +				// existing trade amount
							ai_trade_with_rating(nationRecno)/2;	// possible trade

	allianceRating += tradeRating;

	//---- if the nation's power is larger than us, it's a plus ----//

	int powerRating = nationPtr->military_rank_rating() - military_rank_rating();		// if the nation's power is larger than ours, it's good to form treaty with them

	if( powerRating > 0 )
		allianceRating += powerRating;

	return allianceRating;
}
Example #10
0
//--------- Begin of function Nation::ai_improve_relation --------//
//
// This function is called once every year.
//
void Nation::ai_improve_relation()
{
	NationRelation* nationRelation;

	for( int i=nation_array.size() ; i>0 ; i-- )
	{
		if( nation_array.is_deleted(i) )
			continue;

		nationRelation = get_relation(i);

		if( nationRelation->status == NATION_HOSTILE )
			continue;

		//--- It improves the AI relation with nations that have trade with us. ---//

		change_ai_relation_level( i, trade_rating(i) / 10 );

		//--- decrease the started_war_on_us_count once per year, gradually forgiving other nations' wrong doing ---//

		if( nationRelation->started_war_on_us_count > 0
			 && misc.random(5-pref_forgiveness/20) > 0 )
		{
			nationRelation->started_war_on_us_count--;
		}
	}
}
void print_web(struct allen_web* web, FILE* file, char delimiter) {
	int i, j;
	if (file == NULL)
		return;

	//table header with node identifiers
	fprintf(file, "%c", delimiter);
	for (i = 0; i < web->size; i++) {
		fprintf(file, "%d", get_mapped_nr(web, i));
		fprintf(file, "%c", delimiter);
	}
	fprintf(file, "\n");

	//table content
	for (i = 0; i < web->size; ++i) {
		//node identifier
		fprintf(file, "%d%c", get_mapped_nr(web, i), delimiter);
		for (j = 0; j < web->size; ++j) {

			char* rel = allen_rel_to_ascii(get_relation(web, i, j));
			fprintf(file, "%s%c", rel, delimiter);
			free(rel);
		}
		fprintf(file, "\n");
	}

	fflush(file);
}
Example #12
0
//----- Begin of function Nation::consider_give_tribute -----//
//
// talkMsg->talk_para1 - amount of the tribute.
//
int Nation::consider_give_tribute(TalkMsg* talkMsg)
{
	//-------- don't give tribute too frequently -------//

	NationRelation* nationRelation = get_relation(talkMsg->from_nation_recno);

	if( info.game_date < nationRelation->never_accept_until_date_array[TALK_GIVE_TRIBUTE-1] )
		return 0;

	//---------------------------------------------//

	int relationStatus = get_relation_status(talkMsg->from_nation_recno);
	Nation* fromNation = nation_array[talkMsg->from_nation_recno];

	if( true_profit_365days() < 0 )		// don't give tribute if we are losing money
		return 0;

	int reserveYears = 1 + 3 * pref_cash_reserve / 100;			// 1 to 4 years

	if( cash-talkMsg->talk_para1 < fixed_expense_365days() * reserveYears )
		return 0;

	int militaryDiff = fromNation->military_rank_rating() - military_rank_rating();

	if( militaryDiff > 10+pref_military_courage/2 )
	{
		nationRelation->set_never_accept_until_date(TALK_GIVE_TRIBUTE, 180);
		return 1;
	}

	return 0;
}
Example #13
0
//----- Begin of function Nation::consider_give_aid -----//
//
// talkMsg->talk_para1 - amount of the tribute.
//
int Nation::consider_give_aid(TalkMsg* talkMsg)
{
	//-------- don't give tribute too frequently -------//

	NationRelation* nationRelation = get_relation(talkMsg->from_nation_recno);

	if( info.game_date < nationRelation->never_accept_until_date_array[TALK_GIVE_AID-1] )
		return 0;

	//--------------------------------------------------//

	int importanceRating = (int) nationRelation->good_relation_duration_rating;

	if( nationRelation->status >= RELATION_FRIENDLY &&
		 ai_should_spend( importanceRating, talkMsg->talk_para1 ) )        // 0-importance is 0
	{
		if( info.game_date > nationRelation->last_change_status_date
			 + 720 - pref_allying_tendency )						// we have allied with this nation for quite some while
		{
			nationRelation->set_never_accept_until_date(TALK_GIVE_AID, 180);		// don't give aid again too soon 
			return 1;
		}
	}

	return 0;
}
Example #14
0
//----- Begin of function Nation::consider_declare_war -----//
//
// Consider the request of declaring war on the target nation.
//
// talk_para1 - the recno nation to declare war with.
//
int Nation::consider_declare_war(TalkMsg* talkMsg)
{
	//--- if it even won't consider trade embargo, there is no reason that it will consider declaring war ---//

	if( !consider_trade_embargo(talkMsg) )
		return 0;

	//---------------------------------------//

	int fromRelationRating    = ai_overall_relation_rating(talkMsg->from_nation_recno);
	int againstRelationRating = ai_overall_relation_rating(talkMsg->talk_para1);

	Nation* againstNation = nation_array[talkMsg->talk_para1];

	NationRelation* fromRelation 	  = get_relation(talkMsg->from_nation_recno);
	NationRelation* againstRelation = get_relation(talkMsg->talk_para1);

	//--- if we don't have a good enough relation with the requesting nation, turn down the request ---//

	if( fromRelation->good_relation_duration_rating < 10 )
		return 0;

	//--- if we are more friendly with the against nation than the requesting nation, turn down the request ---//

	if( againstRelation->good_relation_duration_rating >
		 fromRelation->good_relation_duration_rating )
	{
		return 0;
	}

	//--- if the nation is having a financial difficulty, it won't agree ---//

	if( cash < 2000 * pref_cash_reserve / 100  )
		return 0;

	//--------------------------------------------//

	int acceptRating = 100 + againstNation->total_enemy_military() -
							 military_rank_rating();

	//--- it won't declare war with a friendly or allied nation easily ---//

	if( againstRelation->status >= RELATION_FRIENDLY )		// no need to handle RELATION_ALLIANCE separately as ai_overall_relation_relation() has already taken it into account
		acceptRating += 100;

	return fromRelationRating - againstRelationRating > acceptRating;
}
Example #15
0
 /**
  * Get a vector with pointers to all Relations that could not
  * be completed, because members were missing in the input
  * data.
  *
  * Note that these pointers point into memory allocated and
  * owned by the Collector object.
  */
 std::vector<const osmium::Relation*> get_incomplete_relations() const {
     std::vector<const osmium::Relation*> relations;
     for (const auto& relation_meta : m_relations) {
         if (!relation_meta.has_all_members()) {
             relations.push_back(&get_relation(relation_meta));
         }
     }
     return relations;
 }
Example #16
0
//----- Begin of function Nation::think_demand_tech -----//
//
int Nation::think_demand_tech()
{
	if( m.random(10) > 0 )		// only 1/10 chance of calling this function
		return 0;

	Nation* nationPtr;
	int	  totalNation=nation_array.size();
	int	  nationRecno=m.random(totalNation)+1;

	for( int i=totalNation ; i>0 ; i-- )
	{
		if( ++nationRecno > totalNation )
			nationRecno = 1;

		if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno )
			continue;

		nationPtr = nation_array[nationRecno];

		if( nationPtr->total_tech_level() == 0 )
			continue;

		if( !should_diplomacy_retry(TALK_DEMAND_TECH, nationRecno) )
			continue;

		//--- don't request from hostile or tense nations -----//

		if( get_relation(nationRecno)->status < NATION_NEUTRAL )
			continue;

		//---- scan which tech that the nation has but we don't have ----//

		int techId;
		for( techId=1 ; techId<=tech_res.tech_count ; techId++ )
		{
			TechInfo *techInfo = tech_res[techId];

			if( techInfo->get_nation_tech_level(nation_recno)==0 &&
				 techInfo->get_nation_tech_level(nationRecno) > 0 )
			{
				break;
			}
		}

		if( techId > tech_res.tech_count )
			continue;

		//-------- send the message now ---------//

		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_DEMAND_TECH, techId);
		return 1;
	}

	return 0;
}
Example #17
0
int AssocPair::get_relation(int iface_no, iBase_EntitySetHandle *sets,
                            int num_sets, iBase_EntityIterator *tag_values)
{
  std::vector<iBase_EntitySetHandle> sets2(num_sets);
  CHK_ERRORR( get_relation(iface_no, sets, num_sets, &sets2[0]) );

  for(int i=0; i<num_sets; i++)
    CHK_ERRORR( relSides[iface_no]->get_iterator(sets2[i], &tag_values[i]) );

  RETURNR(iBase_SUCCESS);
}
Example #18
0
void prepare_data( RTC_Clock clock)
{	 
	power_screen(true);
	display_clear();
	show_picture(15, 30, IMAGE_LOGO);
//	get_up_config();
	get_down_config();
//	get_gen_config();
	get_relation();
	get_base();
	get_act();
	get_step();
	get_position();
	get_event();		
}
Example #19
0
//----- Begin of function Nation::ai_overall_relation_rating -----//
//
// Return the overall relation rating of this nation with the
// specific nation.
//
int Nation::ai_overall_relation_rating(int withNationRecno)
{
	NationRelation* nationRelation = get_relation(withNationRecno);
	Nation* 			 nationPtr = nation_array[withNationRecno];

	int overallRating = nationRelation->ai_relation_level +
							  (int) nationRelation->good_relation_duration_rating +
							  (int) nationPtr->reputation +
							  nationPtr->military_rank_rating() +
							  trade_rating(withNationRecno) +
							  ai_trade_with_rating(withNationRecno)/2 +
							  nationPtr->total_alliance_military();

	return overallRating;
}
Example #20
0
static ir_tarval *fold_binary_comparison(
		binary_expression_t const *const binexpr)
{
	ir_tarval   *const left   = fold_expression(binexpr->left);
	ir_tarval   *const right  = fold_expression(binexpr->right);
	type_t      *const atype  = skip_typeref(binexpr->left->base.type);
	ir_mode     *const amode  = get_ir_mode_arithmetic(atype);
	assert(amode == get_ir_mode_arithmetic(skip_typeref(binexpr->right->base.type)));
	ir_tarval   *const lefta  = tarval_convert_to(left, amode);
	ir_tarval   *const righta = tarval_convert_to(right, amode);

	type_t      *const type = skip_typeref(binexpr->base.type);
	ir_mode     *const mode = get_ir_mode_arithmetic(type);
	ir_relation  const rel  = get_relation(binexpr->base.kind);
	return create_tarval_from_bool(mode, tarval_cmp(lefta, righta) & rel);
}
Example #21
0
//----- Begin of function Nation::ai_end_treaty -----//
//
// Terminate the treaty with the given nation.
//
// <int> nationRecno - the nation to terminate treaty with.
//
void Nation::ai_end_treaty(int nationRecno)
{
	NationRelation *nationRelation = get_relation(nationRecno);

	err_when( nationRelation->status < NATION_FRIENDLY );

	if( nationRelation->status == NATION_FRIENDLY )
	{
		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_END_FRIENDLY_TREATY, 0, 0, 1);		// 1-force send
	}
	else if( nationRelation->status == NATION_ALLIANCE )
	{
		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_END_ALLIANCE_TREATY, 0, 0, 1);
	}

	err_when( nationRelation->status >= NATION_FRIENDLY );		// when the status is still friendly or alliance
}
Example #22
0
//----- Begin of function Nation::consider_trade_treaty -----//
//
// Consider agreeing to open up trade with the given nation.
//
int Nation::consider_trade_treaty(int withNationRecno)
{
	if( nation_array[withNationRecno]->is_human() != is_human() )
		return 0;

	NationRelation* nationRelation = get_relation(withNationRecno);

	//---- don't accept new trade treaty soon when the trade treaty was terminated not too long ago ----//

	if( info.game_date < nationRelation->never_accept_until_date_array[TALK_END_TRADE_TREATY-1] )
		return 0;

	//-- if we look forward to have a trade treaty with this nation ourselves --//

	if( nationRelation->ai_demand_trade_treaty )
		return 1;

	return ai_trade_with_rating(withNationRecno) > 0;
}
Example #23
0
//----- Begin of function Nation::think_request_cease_war -----//
//
int Nation::think_request_cease_war()
{
	Nation* 			 nationPtr;
	NationRelation* nationRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationPtr = nation_array[i];

		nationRelation = get_relation(i);

		if( nationRelation->status != RELATION_HOSTILE )
			continue;

		if( !should_diplomacy_retry(TALK_REQUEST_CEASE_WAR, i) )
			continue;

		//----- think about if it should cease war with the nation ------//

		if( consider_cease_war(i) > 0 )
		{
			talk_res.ai_send_talk_msg(i, nation_recno, TALK_REQUEST_CEASE_WAR);
		}

		//--------------------------------------------//
		// The relation improves slowly if there is
		// no attack. However, if there is any battles
		// started between the two nations, the status will be
		// set to hostile and ai_relation_level will be set to 0 again.
		//--------------------------------------------//

		else
		{
			change_ai_relation_level(i, 1);
		}
	}

	return 0;
}
Example #24
0
//----- Begin of function Nation::ai_should_attack_friendly -----//
//
// This function returns whether this nation should attack
// the given friendly nation.
//
// <int> friendlyNationRecno - the nation recno of the friendly nation.
// <int> attackTemptation    - a rating from 0 to 100 indicating
//										 temptation of attacking the target.
//
int Nation::ai_should_attack_friendly(int friendlyNationRecno, int attackTemptation)
{
	Nation  			*friendlyNation = nation_array[friendlyNationRecno];
	NationRelation *nationRelation = get_relation(friendlyNationRecno);

	//--- don't change terminate treaty too soon ---//

	if( info.game_date < nationRelation->last_change_status_date+60+pref_honesty/2 )		// only after 60 to 110 days
		return 0;

	//------------------------------------------------//

	int resistanceRating = friendlyNation->military_rank_rating()
								  - military_rank_rating();

	resistanceRating += nationRelation->ai_relation_level - 50;

	resistanceRating += trade_rating(friendlyNationRecno);

	return attackTemptation > resistanceRating;
}
Example #25
0
//----- Begin of function Nation::think_propose_alliance_treaty -----//
//
int Nation::think_propose_alliance_treaty()
{
	//--- think about which nation this nation should propose treaty to ---//

	int				 curRating, bestRating=0, bestNationRecno=0;
	NationRelation* nationRelation;

	for( int i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		if( nation_array[i]->is_human() != is_human() )
			continue;

		nationRelation = get_relation(i);

		if( !nationRelation->has_contact || nationRelation->status == RELATION_ALLIANCE )
			continue;

		if( !should_diplomacy_retry(TALK_PROPOSE_ALLIANCE_TREATY, i) )
			continue;

		curRating = consider_alliance_treaty(i);

		if( curRating > bestRating )
		{
			bestRating 	 	 = curRating;
			bestNationRecno = i;
		}
	}

	if( bestNationRecno )
	{
		talk_res.ai_send_talk_msg(bestNationRecno, nation_recno, TALK_PROPOSE_ALLIANCE_TREATY );
		return 1;
	}

	return 0;
}
Example #26
0
//----- Begin of function Nation::consider_take_aid -----//
//
// talkMsg->talk_para1 - amount of the tribute.
//
int Nation::consider_take_aid(TalkMsg* talkMsg)
{
	int cashSignificance = 100 * talkMsg->talk_para1 / max(1000, (int) cash);		

	//--- It does not necessarily want the tribute ---//

	int aiRelationLevel = get_relation(talkMsg->from_nation_recno)->ai_relation_level;

	if( true_profit_365days() > 0 &&
		 cashSignificance < (100-aiRelationLevel)/5 )
	{
		return 0;
	}

	//----------- take the tribute ------------//

	int relationChange = cashSignificance * (100+pref_cash_reserve) / 200; 

	change_ai_relation_level( talkMsg->from_nation_recno, relationChange );

	return 1;
}
Example #27
0
//----- Begin of function Nation::think_exchange_tech -----//
//
int Nation::think_exchange_tech()
{
	if( m.random(10) > 0 )		// only 1/10 chance of calling this function
		return 0;

	Nation* nationPtr;
	int	  totalNation=nation_array.size();
	int	  nationRecno=m.random(totalNation)+1;

	for( int i=totalNation ; i>0 ; i-- )
	{
		if( ++nationRecno > totalNation )
			nationRecno = 1;

		if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno )
			continue;

		nationPtr = nation_array[nationRecno];

		if( nationPtr->total_tech_level() == 0 )
			continue;

		if( !should_diplomacy_retry(TALK_EXCHANGE_TECH, nationRecno) )
			continue;

		//--- don't request from hostile or tense nations -----//

		if( get_relation(nationRecno)->status < RELATION_NEUTRAL )
			continue;

		//---- scan which tech that the nation has but we don't have ----//

		int getTechId=0, getTechLevel=0, giveTechId=0, giveTechLevel=0;

		int techId;
		for( techId=1 ; techId<=tech_res.tech_count ; techId++ )
		{
			TechInfo *techInfo = tech_res[techId];

			// ###### patch begin Gilbert 24/1 #####//
			// human kingdoms won't ask for fryhtan tech
			if( techInfo->is_monster_tech() && (is_human() || nationPtr->is_human())  )
				continue;
			// won't give fryhtan tech to human 
			// ###### patch end Gilbert 24/1 #####//

			// ####### begin Gilbert 24/12 ####//
//			for( int j=1 ; j<=techInfo->max_tech_level ; j++ )
			for( int j=1 ; j<=techInfo->max_tech_level(nation_recno) || j<=techInfo->max_tech_level(nationRecno); j++ )
			// ####### end Gilbert 24/12 ####//
			{
				if( !giveTechId )
				{
					if( techInfo->get_nation_tech_level(nation_recno) >= j &&
						 techInfo->get_nation_tech_level(nationRecno)  <  j )
					{
						giveTechId 	  = techId;
						giveTechLevel = j;
						break;
					}
				}

				if( !getTechId )
				{
					if( techInfo->get_nation_tech_level(nation_recno) <  j &&
						 techInfo->get_nation_tech_level(nationRecno)  >= j )
					{
						getTechId 	  = techId;
						getTechLevel = j;
						break;
					}
				}
			}
		}

		//---- if there is a tech we want to give and one we want to get ----//

		if( !giveTechId || !getTechId )
			continue;

		//--------- send the diplomatic message now --------//

		// ###### patch begin Gilbert 24/1 #####//
//		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_EXCHANGE_TECH,
//			giveTechId, getTechId, giveTechLevel, getTechLevel );
		talk_res.ai_send_talk_msg(nationRecno, nation_recno, TALK_EXCHANGE_TECH,
			giveTechId, getTechId, 0, giveTechLevel, getTechLevel );	// 0=don't force send
		// ###### end begin Gilbert 24/1 #####//

		return 1;
	}

	return 0;
}
Example #28
0
//----- Begin of function Nation::think_demand_tribute_aid -----//
//
// Demand tribute when the nation's economy is good and its
// military is weak.
//
int Nation::think_demand_tribute_aid()
{
	if( info.game_date < info.game_start_date + 180 + nation_recno*50 )		// don't ask for tribute too soon, as in the beginning, the ranking are all the same for all nations
		return 0;

	//--------------------------------------//

	Nation* nationPtr;
	int	  totalNation=nation_array.size();
	int	  nationRecno=m.random(totalNation)+1;
	int	  curRating, requestRating;
	int	  talkId;
	int	  ourMilitary = military_rank_rating();
	int	  ourEconomy  = economic_rank_rating();

	for( int i=totalNation ; i>0 ; i-- )
	{
		if( ++nationRecno > totalNation )
			nationRecno = 1;

		if( nation_array.is_deleted(nationRecno) || nationRecno==nation_recno )
			continue;

		nationPtr = nation_array[nationRecno];

		//-- only demand tribute from non-friendly nations --//

		if( get_relation(nationRecno)->status <= RELATION_NEUTRAL )
			talkId = TALK_DEMAND_TRIBUTE;
		else
			talkId = TALK_DEMAND_AID;

		//-----------------------------------------------//

		float fixedExpense = fixed_expense_365days();

		if( talkId == TALK_DEMAND_TRIBUTE )
		{
			if( !should_diplomacy_retry(talkId, nationRecno) )
				continue;

			curRating = ourMilitary - nationPtr->military_rank_rating();

			//---- if this is a Fryhtan nation, the tendency to request tribute is higher -----//

			if( is_monster() && nationPtr->is_human() )	// and the target is a human nation
			{
				curRating *= 2;

				//-- if we are running low of live points, it's time to kill somebody --//

				if( live_points < 500 * (100+pref_live_points_reserve) / 100 )
					curRating *= 2;
			}

			if( curRating < 0 )
				continue;

			//----------------------------------------------//
			//
			// Some nation will actually consider the ability
			// of the target nation to pay tribute, so nation
			// will not and just ask anyway.
			//
			//----------------------------------------------//

			if( pref_economic_development > 50 )
			{
				int addRating = nationPtr->economic_rank_rating()-ourEconomy;

				if( addRating > 0 )
					curRating += addRating;
			}

			requestRating = 20 + trade_rating(nationRecno)/2 +
								(100-pref_peacefulness)/3;

			if( cash < fixedExpense && fixedExpense != 0 )
				requestRating -= int( (float) requestRating * cash / fixedExpense);

		}
		else
		{
			if( cash >= fixedExpense )
				continue;

			if( cash > fixedExpense * (50+pref_cash_reserve) / 300 &&		// if the nation is runing short of cash, don't wait a while until next retry, retry immediately
				 !should_diplomacy_retry(talkId, nationRecno) )
			{
				continue;
			}

			//----- only ask for aid when the nation is short of cash ----//

			curRating = (ourMilitary - nationPtr->military_rank_rating())/2 +
							( nationPtr->economic_rank_rating()-ourEconomy );

			requestRating = 20 + 50 * (int)(cash / fixedExpense);
		}

		//----- if the target is a human player's nation -----//

		if( !nationPtr->is_ai() )
		{
			switch( config.ai_aggressiveness )
			{
				case OPTION_NONE:
					requestRating += 60;		// don't go against the player too easily
					break;

				case OPTION_LOW:
					requestRating += 40;		// don't go against the player too easily
					break;

				case OPTION_HIGH:
					requestRating -= 20;
					break;

				case OPTION_VERY_HIGH:
					requestRating -= 40;
					break;
			}

			//--- if the nation has plenty of cash, demand from it ----//

			if( nationPtr->cash > cash && config.ai_aggressiveness >= OPTION_HIGH )
			{
				requestRating -= (int) (nationPtr->cash - cash)/500;
			}
		}

		//--------------------------------------//

		if( curRating > requestRating )
		{
			int tributeAmount;

			if( curRating - requestRating > 120 )
				tributeAmount = 4000;

			else if( curRating - requestRating > 80 )
				tributeAmount = 3000;

			else if( curRating - requestRating > 40 )
				tributeAmount = 2000;

			else if( curRating - requestRating > 20 )
				tributeAmount = 1000;

			else
				tributeAmount = 500;

			//------ stop in here if in tutorial mode -----//
			if( game.game_mode != GAME_TUTORIAL )
			{	
				cash += tributeAmount;
				return 0;
			}

			talk_res.ai_send_talk_msg(nationRecno, nation_recno, talkId, tributeAmount);

			return 1;
		}
	}

	return 0;
}
Example #29
0
//----- Begin of function Nation::think_give_tribute_aid -----//
//
// This function is called when a nation rejected our request
// which is important to us and we want to give tribute to the
// nation so it may accept next time.
//
// <TalkMsg*> rejectedMsg - the TalkMsg that has been rejected.
//
int Nation::think_give_tribute_aid(TalkMsg* rejectedMsg)
{
	//-----------get the talk id. ------------//

	int talkId;
	int talkNationRecno = rejectedMsg->to_nation_recno;
	int rejectedTalkId  = rejectedMsg->talk_id;
	NationRelation* nationRelation = get_relation(talkNationRecno);

	if( nationRelation->status >= RELATION_FRIENDLY )
		talkId = TALK_GIVE_AID;
	else
		talkId = TALK_GIVE_TRIBUTE;

	//-------- don't give tribute too frequently -------//

	if( info.game_date < nationRelation->never_accept_until_date_array[talkId-1] )
		return 0;

	//---- think if the nation should spend money now ----//

	static short tributeAmountArray[] = { 500, 1000 };
	int tributeAmount = tributeAmountArray[m.random(2)];

	if( !ai_should_spend(0, (float) tributeAmount) )		// importance rating is 0
		return 0;

	//--------------------------------------//

	Nation* talkNation = nation_array[talkNationRecno];
	int	  rc;

	if( rejectedTalkId == TALK_PROPOSE_TRADE_TREATY )
	{
		rc = ai_trade_with_rating(talkNationRecno) > 100-pref_trading_tendency/2;
	}

	else if ( rejectedTalkId == TALK_PROPOSE_FRIENDLY_TREATY ||
				 rejectedTalkId == TALK_PROPOSE_ALLIANCE_TREATY )
	{
		int curRating = talkNation->trade_rating(talkNationRecno) +
							 ai_trade_with_rating(talkNationRecno) +
							 talkNation->overall_rating - overall_rating;

		int acceptRating = 200-pref_trading_tendency/4
									 -pref_allying_tendency/4;

		rc = curRating >= acceptRating;
	}

	//--------------------------------------//

	else if( rejectedTalkId == TALK_REQUEST_CEASE_WAR )
	{
		rc = talkNation->military_rank_rating() >
			  military_rank_rating() + (100-pref_peacefulness)/2;
	}

	//--------------------------------------//

	if( rc )
	{
		//------ give tribute --------//

		talk_res.ai_send_talk_msg(talkNationRecno, nation_recno, talkId, tributeAmount);

		nationRelation->set_never_accept_until_date(talkId, 100);		// don't offer tribute too often

		//------ request again after giving tribute ----//

		nationRelation->last_talk_reject_date_array[rejectedTalkId-1] = 0;		// reset the rejected talk id.
		nationRelation->never_accept_until_date_array[rejectedTalkId-1] = 0;		// reset the rejected talk id.

		talk_res.ai_send_talk_msg(talkNationRecno, nation_recno, rejectedTalkId, rejectedMsg->talk_para1, rejectedMsg->talk_para2 );
	}

	return rc;
}
Example #30
0
//----- Begin of function Nation::think_declare_war -----//
//
int Nation::think_declare_war()
{
	NationRelation* nationRelation;
	int rc=0;

	//---- don't declare a new war if we already has enemies ---//

	int i;
	for( i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		if( get_relation(i)->status == RELATION_HOSTILE )
			return 0;
	}

	//------------------------------------------------//

	int targetStrength, minStrength=0x1000, bestTargetNation=0;

	for( i=1 ; i<=nation_array.size() ; i++ )
	{
		if( nation_array.is_deleted(i) || i==nation_recno )
			continue;

		nationRelation = get_relation(i);

		if( !nationRelation->has_contact )
			continue;

		if( nationRelation->status == RELATION_HOSTILE )		// already at war
			continue;

		if( nationRelation->ai_relation_level >= 10 )
			continue;

		if( !ai_should_spend( 100-trade_rating(i) ) )		// if trade_rating is 0, importanceRating will be 100, if trade_rating is 100, importanceRating will be 0
			continue;

		//----------------------------------------//

		Nation* targetNation = nation_array[i];

		targetStrength = targetNation->military_rank_rating() +
							  targetNation->population_rank_rating()/2 +
							  targetNation->economic_rank_rating()/3;

		if( targetStrength < minStrength )
		{
			minStrength = targetStrength;
			bestTargetNation = i;
		}
	}

	//------------------------------------------//

	if( bestTargetNation )
	{
		if( should_diplomacy_retry(TALK_DECLARE_WAR, bestTargetNation) )
		{
			talk_res.ai_send_talk_msg(bestTargetNation, nation_recno, TALK_DECLARE_WAR);
			return 1;
		}
	}

	return 0;
}