Esempio n. 1
0
//------ Begin of function TalkRes::del_talk_msg ------//
//
void TalkRes::del_talk_msg(int talkMsgRecno)
{
	err_when( is_talk_msg_deleted(talkMsgRecno) );

	TalkMsg* talkMsg = get_talk_msg(talkMsgRecno);

	//--- if this message is sent to an AI nation ---//

	Nation* nationPtr = nation_array[talkMsg->to_nation_recno];

	if( nationPtr->nation_type == NATION_AI &&
		 (talkMsg->reply_type == REPLY_NOT_NEEDED ||		// even if a reply is not needed, the message will still be sent to the AI for notification. 
		  talkMsg->reply_type == REPLY_WAITING) )
	{
		//--- it may still have the message in its action queue ---//

		ActionNode* actionNode;

		for( int i=nationPtr->action_count() ; i>0 ; i-- )
		{
			if( nationPtr->is_action_deleted(i) )
				continue;

			actionNode = nationPtr->get_action(i);

			if( actionNode->action_mode == ACTION_AI_PROCESS_TALK_MSG &&
				 actionNode->action_para == talkMsgRecno )
			{
				nationPtr->del_action(i);
				break;
			}
		}
	}

	//----- delete the message from the news array -----//

	if( talkMsg->to_nation_recno == nation_array.player_recno ||
		 talkMsg->from_nation_recno == nation_array.player_recno )
	{
		news_array.remove( NEWS_DIPLOMACY, talkMsgRecno );
	}

	//----- link it out from talk_msg_array -----//

	talk_msg_array.linkout(talkMsgRecno);
}
Esempio n. 2
0
//--------- Begin of function Unit::next_day ---------//
//
void Unit::next_day()
{
	int unitRecno = sprite_recno;

   err_when( unit_array.is_deleted(unitRecno) );

	err_when( race_id && !is_visible() && unit_mode==0 );

	err_when( team_info && !mem.get_mem_size(team_info) );

	// ##### begin Gilbert 2/3 #####//
	err_when( race_id && unit_id != UNIT_WAGON && !name_id );
	// ##### end Gilbert 2/3 #####//

	//------- functions for non-independent nations only ------//

   if( nation_recno )
   {
      pay_expense();

		if( unit_array.is_deleted(unitRecno) )		// if its hit points go down to 0, is_deleted() will return 1.
			return;

		//------- update loyalty -------------//

		if( info.game_date%30 == sprite_recno%30 )
		{
			update_loyalty();
		   err_when( unit_array.is_deleted(unitRecno) );
		}

		//------- think about rebeling -------------//

		if( info.game_date%15 == sprite_recno%15 )
		{
			if( think_betray() )
				return;
		}
	}

	//------- recover from damage -------//

	if( info.game_date%4 == sprite_recno%4 )   // recover points per 4 days 
	{
		process_recover();
		err_when( unit_array.is_deleted(unitRecno) );
	}

   //------- restore cur_power --------//

	cur_power += 5;

	if( cur_power > max_power)
		cur_power = max_power;

	// ------ process magic effect ---------//

	if( invulnerable_day_count > 0 )
		--invulnerable_day_count;

   //------- king undie flag (for testing games only) --------//

   if( config.king_undie_flag && rank_id == RANK_KING &&
       nation_recno && !nation_array[nation_recno]->is_ai() )
   {
		hit_points = (float) max_hit_points();
		// ####### begin Gilbert 27/1 ######//
		if( invulnerable_day_count == 0 )
			++invulnerable_day_count;
		// ####### end Gilbert 27/1 ######//
	}

	//-------- if aggresive_mode is 1 --------//

	if( is_visible() )
		think_aggressive_action();

	// --------- process item -------//
	
	item.next_day();

	//---------- debug ------------//

#ifdef DEBUG
   err_when( race_id &&
		unit_res[unit_id]->unit_class != UNIT_CLASS_HUMAN && 
		unit_res[unit_id]->unit_class != UNIT_CLASS_MONSTER && 
		unit_res[unit_id]->unit_class != UNIT_CLASS_WAGON );

	if( unit_mode == UNIT_MODE_CONSTRUCT_TOWN )
		err_when( town_array[unit_mode_para]->builder_recno != sprite_recno );

	err_when( unit_mode==UNIT_MODE_REBEL && nation_recno );		// rebels must be independent

	//------ debug: spy ----------//

	if( spy_recno )
	{
		err_when( spy_array.is_deleted(spy_recno) );

		Spy* spyPtr = spy_array[spy_recno];

		err_when( nation_recno != spyPtr->cloaked_nation_recno );

		if( unit_mode == UNIT_MODE_OVERSEE )
		{
			err_when( spyPtr->spy_place != SPY_FIRM );
			err_when( spyPtr->spy_place_para != unit_mode_para );
		}
		else
		{
			err_when( spyPtr->spy_place != SPY_MOBILE );
			err_when( spyPtr->spy_place_para != sprite_recno );
		}

		// ####### begin Gilbert 24/2 ########//
		err_when( unique_id != spyPtr->unique_id );
		// ####### end Gilbert 24/2 ########//
	}

	//------ debug: team ----------//

	if( leader_unit_recno )
	{
      Unit* unitPtr = unit_array[leader_unit_recno];

		err_when( unitPtr->rank_id != RANK_GENERAL && unitPtr->rank_id != RANK_KING );
	}

	err_when( (rank_id == RANK_GENERAL || rank_id == RANK_KING) &&
				 !team_info );

	if( team_info )
	{
		for( int i=0 ; i<team_info->member_count ; i++ )
		{
			Unit* unitPtr = unit_array[team_info->member_unit_array[i]];

			if( unitPtr->sprite_recno == sprite_recno )		// the same unit
				continue;

			err_when( unitPtr->leader_unit_recno != sprite_recno );
		}
	}

	if( leader_unit_recno && unit_mode != UNIT_MODE_REBEL )		// in rebel mode, the leader_unit_recno is not linked to team_info
	{
		Unit* leaderUnit = unit_array[leader_unit_recno];

		err_when( !leaderUnit->team_info );

		for( int i=0 ; i<leaderUnit->team_info->member_count ; i++ )
		{
			if( leaderUnit->team_info->member_unit_array[i] == sprite_recno )
				break;
		}

		err_when( i==leaderUnit->team_info->member_count );		// not found

		err_when( unit_array.is_truly_deleted(leader_unit_recno) );
		err_when( unit_array[leader_unit_recno]->nation_recno != nation_recno );
//		err_when( unit_array[leader_unit_recno]->team_id != team_id );
	}

	//------ debug: AI action ----------//

	if( cur_order.ai_action_id )
	{
		Nation* nationPtr = nation_array[nation_recno];

		for( int actionRecno=nationPtr->action_count() ; actionRecno>0 ; actionRecno-- )
		{
			if( nationPtr->is_action_deleted(actionRecno) )
				continue;

			ActionNode* actionNode = nationPtr->get_action(actionRecno);

			if( cur_order.ai_action_id == actionNode->action_id )
			{
				err_when( actionNode->processing_instance_count<1 );
				break;
			}
		}
	}

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

	err_when( hit_points > max_hit_points() );
	err_when( max_hit_points() == 0 );

   err_when( combat_level()<0 );
	err_when( combat_level()>1000 );

	err_when( unit_mode==UNIT_MODE_REBEL && spy_recno );			// no rebel spies
	err_when( unit_mode==UNIT_MODE_REBEL && nation_recno );		// all rebels must be independent units

	err_when( unit_mode==UNIT_MODE_TOWN_DEFENDER && spy_recno );			// no rebel spies

	err_when( loyalty < 0 || loyalty > 100 );

	err_when( nation_contribution < 0 );
	err_when( nation_contribution > MAX_NATION_CONTRIBUTION );

	err_when( is_ai && ( !nation_recno || !nation_array[nation_recno]->is_ai() ) );

#else		// fix bug on fly in the release version

	// ######## begin Gilbert 5/2 #####//
//	if( combat_level() > skill.max_combat_level )
//		combat_level() = skill.max_combat_level;
	if( skill.actual_combat_level(NULL) > skill.max_combat_level )		// raw combat level
		set_combat_level( skill.max_combat_level );
	// ######## end Gilbert 5/2 #####//

#endif
}