当前位置: 首页>>代码示例>>C++>>正文


C++ err_when函数代码示例

本文整理汇总了C++中err_when函数的典型用法代码示例。如果您正苦于以下问题:C++ err_when函数的具体用法?C++ err_when怎么用?C++ err_when使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了err_when函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: err_when

void RegionStat::update_stat()
{
	//------ save useful constant info ------//

	int 			regionId = region_id;
	RegionPath  reachableRegionArray[MAX_REACHABLE_REGION_PER_STAT];
	char			reachableRegionCount = reachable_region_count;

	err_when( sizeof(reachable_region_array) != sizeof(reachableRegionArray) );

	memcpy( reachableRegionArray, reachable_region_array, sizeof(reachable_region_array) );

	memset( this, 0, sizeof(RegionStat) );		// reset all data

	region_id = regionId;
	reachable_region_count = reachableRegionCount;

	memcpy( reachable_region_array, reachableRegionArray, sizeof(reachable_region_array) );

	//--------- update firm stat ---------//

	Firm* firmPtr;

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

		firmPtr = firm_array[i];

		if( firmPtr->region_id != region_id )
			continue;

		if( firmPtr->nation_recno==0 )		// monster firms
			continue;

      err_when( firmPtr->firm_id < 1 || firmPtr->firm_id > MAX_FIRM_TYPE );
		err_when( firmPtr->nation_recno < 1 || firmPtr->nation_recno > MAX_NATION );

		firm_type_count_array[firmPtr->firm_id-1]++;
		firm_nation_count_array[firmPtr->nation_recno-1]++;

		total_firm_count++;

		if( firmPtr->firm_id == FIRM_CAMP )
			camp_nation_count_array[firmPtr->nation_recno-1]++;

		if( firmPtr->firm_id == FIRM_HARBOR )
			harbor_nation_count_array[firmPtr->nation_recno-1]++;

		if( firmPtr->firm_id == FIRM_MINE )
			mine_nation_count_array[firmPtr->nation_recno-1]++;
	}

	//--------- update town stat ---------//

	Town* townPtr;

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

		townPtr = town_array[i];

		if( townPtr->region_id != region_id )
			continue;

		if( townPtr->nation_recno )
		{
			err_when( townPtr->nation_recno < 1 || townPtr->nation_recno > MAX_NATION );

			town_nation_count_array[townPtr->nation_recno-1]++;

			if( townPtr->is_base_town )
				base_town_nation_count_array[townPtr->nation_recno-1]++;

			nation_population_array[townPtr->nation_recno-1] += townPtr->population;
			nation_jobless_population_array[townPtr->nation_recno-1] += townPtr->jobless_population;
		}
		else
			independent_town_count++;

		total_town_count++;
	}

	//--------- update unit stat ---------//

	Unit* unitPtr;

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

		unitPtr = unit_array[i];

		if( unitPtr->region_id() != region_id )
			continue;
//.........这里部分代码省略.........
开发者ID:AMDmi3,项目名称:7kaa,代码行数:101,代码来源:OREGIONS.cpp

示例2: err_here

//------------ Begin of function Tutor::load -------------//
//
// <int> tutorId - id. of the tutorial
//
void Tutor::load(int tutorId)
{
	cur_tutor_id = tutorId;

	//------- get the tutor msgs from the resource file -------//

	int   dataSize;
	File* filePtr = res_tutor_text.get_file( tutor[tutorId]->code, dataSize);

	if( !filePtr )       // if error getting the tutor resource
	{
		err_here();
		return;
	}

	//------ Open the file and allocate buffer -----//

	FileTxt fileTxt( filePtr, dataSize );  // initialize fileTxt with an existing file stream

	if( dataSize > tutor_text_buf_size )
	{
		tutor_text_buf      = mem_resize( tutor_text_buf, dataSize );       // allocate a buffer larger than we need for the largest size possible
		tutor_text_buf_size = dataSize;
	}

	//-------- read in tutor info one by one --------//

	TutorTextBlock* tutorTextBlock = text_block_array;
	char*     textPtr = tutor_text_buf;
	int       readLen, totalReadLen=0;    // total length of text read into the tutor_text_buf
	int		 loopCount=0;
	char*		 tokenStr;

	text_block_count=0;

	fileTxt.next_line();    // by pass the first two lines of file description
	fileTxt.next_line();

	while( !fileTxt.is_eof() )
	{
		err_when( loopCount++ > 10000 );

		tokenStr = fileTxt.get_token(0);		// don't advance the pointer

		if( !tokenStr )
			break;

		//------ read in the display button code of the tutorial segment -------//

		if( strcmpi( tokenStr, "Button" ) == 0 )
		{
			fileTxt.get_token(1);		// advance the pointer

			tokenStr = fileTxt.get_token(1);

			strncpy( tutorTextBlock->button_code, tokenStr, tutorTextBlock->BUTTON_CODE_LEN );
			tutorTextBlock->button_code[tutorTextBlock->BUTTON_CODE_LEN] = '\0';
		}
		else
		{
			tutorTextBlock->button_code[0] = '\0';
		}

		//------- read in the tutorial text -------//

		readLen = fileTxt.read_paragraph(textPtr, tutor_text_buf_size-totalReadLen);

		tutorTextBlock->text_ptr = textPtr;
		tutorTextBlock->text_len = readLen;

		textPtr      += readLen;
		totalReadLen += readLen;

		err_when( totalReadLen>tutor_text_buf_size );

		//----------- next tutor block -------------//

		fileTxt.next_line();      // pass the page break line

		text_block_count++;
		tutorTextBlock++;

		err_when( text_block_count >= MAX_TUTOR_TEXT_BLOCK );
	}

	cur_text_block_id = 1;
	last_text_block_id = 0;
}
开发者ID:Stummi,项目名称:7kaa,代码行数:92,代码来源:OTUTOR.cpp

示例3: err_when

//--------- Begin of function FirmWar::disp_build_menu ---------//
//
void FirmWar::disp_build_menu(int refreshFlag)
{
	int x1 = INFO_X1+13;
	int y1 = INFO_Y1+5;

	vga.active_buf->put_bitmap( INFO_X1, INFO_Y1, image_gameif.read("BLDGWEAP") );


	if( refreshFlag == INFO_REPAINT )
	{
		added_count=0;
	}
	int b = 0;

	TechClass *techClass = tech_res.tech_class(war_tech_class);	// war_tech_class is set the which tech class of weapon to build

	// int x=INFO_X1+2, y=INFO_Y1;

	for( int techId = techClass->first_tech_id; techId<techClass->first_tech_id+techClass->tech_count; ++techId )
	{
		short unitId = tech_res[techId]->unit_id;
		if( !unitId )
			continue;

		UnitInfo* unitInfo = unit_res[unitId];

		if( unitInfo->unit_class != UNIT_CLASS_WEAPON )
			continue;

		if( refreshFlag == INFO_REPAINT )
		{
			err_when( b != added_count);

			button_queue_weapon[added_count].create(x1+20, y1+5, x1+49, y1+34, 
				i_disp_queue_button, ButtonCustomPara(this, unitId) );
			button_queue_weapon[added_count].set_help_code( "WEAPNUM" );

			button_weapon[added_count].create(x1, y1+35, x1+67, y1+114,
				i_disp_build_button, ButtonCustomPara(&button_queue_weapon[added_count], unitId) );

			added_count++;
			x1 += 68;
			if (added_count == 3)
			{
				x1 = INFO_X1+13;
				y1 = INFO_Y1+121;
			}

			err_when(added_count > MAX_WEAPON_TYPE);
		}

		if( unitInfo->get_nation_tech_level(nation_recno) > 0 )
			button_queue_weapon[b].visible_flag = button_weapon[b].visible_flag = 1;
		else
			button_queue_weapon[b].visible_flag = button_weapon[b].visible_flag = 0;

		button_queue_weapon[b].paint();
		button_weapon[b].paint();

		++b;
	}
			
	if( refreshFlag==INFO_REPAINT )
	{
		// ##### begin Gilbert 8/2 ######//
		int x1 = INFO_X1 +13 +BUTTON_DISTANCE*3;
		int y1 = INFO_Y1 +281;
		// button_cancel.create( x1+7, y1+9, "OK-U", "OK-D" );
		button_cancel.create( x1, y1, 'A', "CANCEL" );
		// ##### end Gilbert 8/2 ######//
	}
	button_cancel.paint();
}
开发者ID:112212,项目名称:7k2,代码行数:75,代码来源:of_wari.cpp

示例4: switch

//--------- Begin of function FirmCamp::disp_camp_info ---------//
//
void FirmCamp::disp_camp_info(int dispY1, int refreshFlag)
{
	if( is_own() )
	{
		int x1 = INFO_X1 +13;
		int y1 = INFO_Y1 +235;
		int x2 = INFO_X1 +13;
		int y2 = INFO_Y1 +281;
		if( refreshFlag==INFO_REPAINT )
		{
			// ##### begin Gilbert 31/12 #######//
			// button_patrol.create( INFO_X1+13, INFO_Y1+235, 'A', "PATROL" );
			// button_reward.create( INFO_X1+13+BUTTON_DISTANCE, INFO_Y1+235, 'A', "REWARDCB" );
			// button_defense.create( INFO_X1+13+2*BUTTON_DISTANCE, INFO_Y1+235, 'A', defense_flag ? "DEFENSE1" : "DEFENSE0" );

			if (!is_monster())
				button_patrol.create( INFO_X1+13+BUTTON_DISTANCE, INFO_Y1+281, 'A', "PATROL" );
			else
				button_patrol.create( INFO_X1+13+BUTTON_DISTANCE, INFO_Y1+281, 'A', "F_PATROL" );

			if (!is_monster())
				button_reward.create( INFO_X1+13, INFO_Y1+235, 'A', "REWARD" );				
			else
				button_reward.create( INFO_X1+13, INFO_Y1+235, 'A', "F_REWARD" );				
							
			if (!is_monster())
				button_defense.create( INFO_X1+13+2*BUTTON_DISTANCE, INFO_Y1+281, 'A', defense_flag ? "DEFENSE1" : "DEFENSE0" );
			else
				button_defense.create( INFO_X1+13+2*BUTTON_DISTANCE, INFO_Y1+281, 'A', defense_flag ? "F_DEFEN1" : "F_DEFEN0" );
				
			if (!is_monster())
				button_promote.create( INFO_X1+13+2*BUTTON_DISTANCE , INFO_Y1+235, 'A', "PROMOTE" );
			else
				button_promote.create( INFO_X1+13+2*BUTTON_DISTANCE , INFO_Y1+235, 'A', "F_PROMOT" );
			// ##### end Gilbert 31/12 #######//
		}
		if( overseer_recno )
		{
			button_patrol.enable_flag = 1;
		}
		else
		{
			for( int i = 0; i < soldier_count && soldier_array[i].is_under_training(); ++i );
			button_patrol.enable_flag = i < soldier_count;
		}
		
		String str;
		switch(patrol_state)
		{
			case PATROL_ALL:
			//	str = "Sortie All";
				str = "";
				break;
			case PATROL_NO_GENERAL:
				str = "Sortie No Leader";
				break;
			case PATROL_NO_INJURED_SOILDER:
				str = "Sortie No Injured";
				break;
			default:
				break;
		}

		button_patrol.paint();
	//	vga.active_buf->bar_alpha( button_patrol.x1, button_patrol.y1+15, button_patrol.x1+BUTTON_ACTION_WIDTH-1, button_patrol.y1+BUTTON_ACTION_HEIGHT-16, 1, 0 );
		font_whbl.center_put_paragraph( button_patrol.x1, button_patrol.y1, button_patrol.x1+BUTTON_ACTION_WIDTH-1, button_patrol.y1+BUTTON_ACTION_HEIGHT-1, str );

		// ###### begin Gilbert 15/4 ########//
		if( nation_array[nation_recno]->cash >= REWARD_COST &&
			 ( (overseer_recno && unit_array[overseer_recno]->rank_id != RANK_KING && unit_res[unit_array[overseer_recno]->unit_id]->class_info.has_loyalty)
			  || (selected_soldier_id && selected_soldier_id <= soldier_count && unit_res[soldier_array[selected_soldier_id-1].unit_id]->class_info.has_loyalty)) )
			button_reward.enable_flag = 1;			// call paint
		// ###### end Gilbert 15/4 ########//
		else
			button_reward.enable_flag = 0;		// call paint
		button_reward.paint();

		if (!is_monster())
			button_defense.update_bitmap( defense_flag ? "DEFENSE1" : "DEFENSE0" );		// call paint
		else
			button_defense.update_bitmap( defense_flag ? "F_DEFEN1" : "F_DEFEN0" );

		if( (button_promote.visible_flag = !overseer_recno) )
		{
			button_promote.enable_flag = 0;
			if( selected_soldier_id > 0 && selected_soldier_id <= soldier_count )
			{
				Soldier *soldierPtr = soldier_array + selected_soldier_id - 1;
				// ##### begin Gilbert 24/3 ######//
				err_when( soldierPtr->unit_id == UNIT_WAGON );

				if( soldierPtr->race_id != 0
					&& soldierPtr->rank_id == RANK_SOLDIER 
					&& !soldierPtr->is_under_training()
					&& soldierPtr->skill_level() > 0 )
				// ##### end Gilbert 24/3 ######//
				{
					button_promote.enable_flag = 1;
//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:of_campi.cpp

示例5: err_when

//--------- Begin of function Firm::spy_birbe_succeed_chance ---------//
//
// The money the spy offers to bribe the unit.
//
// <int>   bribeAmount	  - the amount offered
// <short> birberSpyRecno - spy recno of the briber
// <short> workerId		  - if 0, then bribe the overseer,
//									 if >0, then bribe a worker.
//
// return: <int> 1 - bribing succeeded
//					  0 - bribing failed
//
int Firm::spy_bribe_succeed_chance(int bribeAmount, short briberSpyRecno, short workerId)
{
	Spy* spyPtr = spy_array[briberSpyRecno];

	err_when( spyPtr->spy_place != SPY_FIRM );
	err_when( spyPtr->spy_place_para != firm_recno );

	//---- if the bribing target is a worker ----//

	int unitLoyalty, unitRaceId, targetSpyRecno, unitCommandPower;

	if( workerId )
	{
		Worker* workerPtr = worker_array+workerId-1;

		unitLoyalty = workerPtr->loyalty();
		unitRaceId  = workerPtr->race_id;
		unitCommandPower = 0;
		targetSpyRecno = workerPtr->spy_recno;
	}
	else if( overseer_recno )
	{
		Unit* unitPtr = unit_array[overseer_recno];

		unitLoyalty = unitPtr->loyalty;
		unitRaceId  = unitPtr->race_id;
		unitCommandPower = unitPtr->commander_power();
		targetSpyRecno = unitPtr->spy_recno;
	}
	else
		err_here();

	err_when( unitRaceId < 1 || unitRaceId > MAX_RACE );

	//---- determine whether the bribe will be successful ----//

	int succeedChance;

	if( targetSpyRecno )		// if the bribe target is also a spy
	{
		err_when( spy_array[targetSpyRecno]->true_nation_recno == spyPtr->true_nation_recno );		// the player shouldn't be able to bribe units of his own

		succeedChance = 0;
	}
	else
	{
		succeedChance = spyPtr->spy_skill - unitLoyalty - unitCommandPower
							 + (int) nation_array[spyPtr->true_nation_recno]->reputation
							 + 200 * bribeAmount / MAX_BRIBE_AMOUNT;

		//-- the chance is higher if the spy or the spy's king is racially homongenous to the bribe target,

		int spyKingRaceId = nation_array[ spyPtr->true_nation_recno ]->race_id;

		succeedChance += race_res.is_same_race(spyPtr->race_id, unitRaceId) * 10 +
							  race_res.is_same_race(spyKingRaceId, unitRaceId) * 10;

		if( unitLoyalty > 60 )			// harder for bribe units with over 60 loyalty
			succeedChance -= (unitLoyalty-60);

		if( unitLoyalty > 70 )			// harder for bribe units with over 70 loyalty
			succeedChance -= (unitLoyalty-70);

		if( unitLoyalty > 80 )			// harder for bribe units with over 80 loyalty
			succeedChance -= (unitLoyalty-80);

		if( unitLoyalty > 90 )			// harder for bribe units with over 90 loyalty
			succeedChance -= (unitLoyalty-90);

		if( unitLoyalty == 100 )
			succeedChance = 0;
	}

	return succeedChance;
}
开发者ID:AMDmi3,项目名称:7kaa,代码行数:87,代码来源:OFIRMIF3.cpp

示例6: err_when

//--------- Begin of function FirmCamp::disp_overseer_info ---------//
//
void FirmCamp::disp_overseer_info(int dispY1, int refreshFlag)
{
	disp_soldier_info_y1 = dispY1;

	if( !overseer_recno )
		return;

	Unit* unitPtr = unit_array[overseer_recno];
	UnitInfo *unitInfo = unit_res[unitPtr->unit_id];

	int x=INFO_X1+20, y=dispY1;
	int x2;

	// --- display name_id, can spot spy ----- //

	String str;

	str  = unitPtr->unit_name();
	str += " (";

	if( unitPtr->is_human() )
		str += race_res[unitPtr->race_id]->name;
	else
		str += monster_res[unitPtr->monster_id()]->name;

	str += ")";

	font_snds.put( x, y, str, 0, INFO_X2-8, 1 );

	// line spacing 24

	// ------- display loyalty ---------//

	if( unitInfo->class_info.has_loyalty && unitPtr->rank_id != RANK_KING && unitPtr->nation_recno )
	{
		err_when( unitPtr->unit_id == UNIT_WAGON );

		if (unitPtr->loyalty != unitPtr->target_loyalty)
			info.disp_loyalty( x, y+12, INFO_X2-99 - font_snds.text_width(m.format(unitPtr->loyalty, 4)) -
						font_snds.text_width(m.format(unitPtr->target_loyalty, 4)) -
						font_snds.text_width("11"),
						unitPtr->loyalty, unitPtr->target_loyalty, nation_recno, refreshFlag, disp_combat_or_skill==4 );
		else
			info.disp_loyalty( x, y+12, INFO_X2-99 - font_snds.text_width(m.format(unitPtr->loyalty, 4)),
						unitPtr->loyalty, unitPtr->target_loyalty, nation_recno, refreshFlag, disp_combat_or_skill==4 );
	}

	// ------- display combat ----------//

	if( unitInfo->class_info.has_combat_level )
	{
		x2 = (disp_combat_or_skill==1?font_blu2:font_snds).put( x+110, y+12, "Combat" ) + 10;
		font_snds.right_put( INFO_X2-10, y+12, m.format(unitPtr->combat_level(),4) );
	}
		
		// ------- display leadership -------//

	if( unitInfo->class_info.has_skill_level && unitPtr->skill_level() > 0 )
	{
		x2 = (disp_combat_or_skill==2?font_blu2:font_snds).put( x+110, y+26, "Leadership" ) + 10;
		font_snds.right_put( INFO_X2-10, y+26, m.format(unitPtr->skill_level(),4) );
	}

	// ----- display hit point ---------//

	x2 = font_snds.put( x, y+26, "Hit Points" ) + 10;
	str = m.format((int)unitPtr->hit_points, 4);
	str += "/";
	str += m.format(unitPtr->max_hit_points(), 4);
	font_snds.right_put( INFO_X2-100, y+26, str );
}
开发者ID:mecirt,项目名称:7k2,代码行数:73,代码来源:of_campi.cpp

示例7: err_when

//------- Begin of function Firm::change_nation ---------//
//
void Firm::change_nation(int newNationRecno)
{
    if( nation_recno == newNationRecno )
        return;

    //---------- stop all attack actions to this firm ----------//

    unit_array.stop_attack_obj(base_obj_recno);
    rebel_array.stop_attack_firm(firm_recno);

    Nation *oldNationPtr = NULL;
    Nation *newNationPtr = NULL;

    if( nation_recno )
        oldNationPtr = nation_array[nation_recno];

    if( newNationRecno )
        newNationPtr = nation_array[newNationRecno];

    //------ if there is a builder in this firm, change its nation also ----//

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

        unitPtr->change_nation(newNationRecno);

        //--- if this is a spy, chance its cloak ----//

        if( unitPtr->spy_recno )
            spy_array[unitPtr->spy_recno]->cloaked_nation_recno = newNationRecno;
    }

    //---------- stop all actions attacking this firm --------//

    unit_array.stop_attack_obj(base_obj_recno);

    //---- update nation_unit_count_array[] ----//

    FirmInfo* firmInfo = firm_res[firm_id];

    if( nation_recno )
        firmInfo->dec_nation_firm_count(nation_recno);

    if( newNationRecno )
        firmInfo->inc_nation_firm_count(newNationRecno);

    //---- reset should_close_flag -----//

    if( is_ai )
    {
        if( should_close_flag )
        {
            if( oldNationPtr )
            {
                oldNationPtr->firm_should_close_array[firm_id-1]--;
                err_when( oldNationPtr->firm_should_close_array[firm_id-1] < 0 );
            }

            should_close_flag = 0;
        }
    }

    //------- update player_spy_count -------//

    spy_array.update_firm_spy_count(firm_recno);

    //--- update the cloaked_nation_recno of all spies in the firm ---//

    spy_array.change_cloaked_nation(SPY_FIRM, firm_recno, nation_recno, newNationRecno);		// check the cloaked nation recno of all spies in the firm

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

    if( oldNationPtr )
        oldNationPtr->del_firm_info(firm_id, firm_recno);

    //------ update power nation recno ----------//

    if( should_set_power )
        world.restore_power(loc_x1, loc_y1, loc_x2, loc_y2, 0, firm_recno);

    should_set_power = get_should_set_power();

    if( should_set_power )
        world.set_power(loc_x1, loc_y1, loc_x2, loc_y2, newNationRecno);        // set power of the new nation

    //------------ update link --------------//

    release_link();		// need to update link because firms are only linked to firms of the same nation

    nation_recno = newNationRecno;

    setup_link();

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

    if (!newNationRecno)
        is_ai = 1;
//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:ofirm.cpp

示例8: deinit

//--------- Begin of function Firm::deinit --------//
//
void Firm::deinit()
{
    if( !firm_recno )    // already deleted
        return;

    if( power.command_firm_recno == firm_recno )
        power.reset_command();

    // ##### begin Gilbert 30/10 ######//
//	mem_del(firm_cur_frame);
//	firm_cur_frame = NULL;
//	mem_del(firm_remain_frame_delay);
//	firm_remain_frame_delay = NULL;
    // ##### end Gilbert 30/10 ######//

    is_being_deleted = 1;	// whether the place is currently being deleted, if it is set to true, some functions will be executed in an exceptional way, it is set in deinit()

    Place::deinit();			// parent class deinit()

    deinit_derived();

    //------- delete AI info ----------//

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

        nationPtr->del_firm_info(firm_id, firm_recno);

        if(is_ai)
        {
            if( should_close_flag )
                nationPtr->firm_should_close_array[firm_id-1]--;

            err_when( nationPtr->firm_should_close_array[firm_id-1] < 0 );

        }
    }

    //--------- clean up related stuff -----------//

    restore_world_matrix();
    release_link();

    //-------- dynamic unloading of firm bitmaps ---------//

    FirmBuild* firmBuild = firm_res.get_build(firm_build_id);
    firmBuild->free_bitmap_res();

    //------ all workers and the overseer resign ------//

    if( !sys.signal_exit_flag )
    {
        //	char* name1 = "Wilde Lishorr";
        //	char* name2 = "Lishorr";
        //	if( !under_construction && hit_points < 1 && strcmp(name1, firm_name()) && strcmp(name2, firm_name()) )
        if( !under_construction && hit_points < 1 )
        {
            // -------- create a firm die record ------//
            // can be called as soon as restore_world_matrix

            static int effectId = sprite_res.search_sprite( "FIRE_EFF" );
            err_when( !effectId );
            Effect::create(effectId, loc_x1 *LOCATE_WIDTH, loc_y1 *LOCATE_HEIGHT, SPRITE_IDLE, 1, 8, 0);

            FirmDie firmDie3;
            if (firmBuild->loc_width == 3 && firmBuild->loc_height == 3)
                firmDie3.init(this, 6);
            else if (firmBuild->loc_width == 6 && firmBuild->loc_height == 6)
                firmDie3.init(this, 5);
            else
                firmDie3.init(this, 4);
            firm_die_array.add(&firmDie3);
        }
    }

    free_all_people();
    //--------- decrease firm counter -----------//

    if( nation_recno )
        nation_array[nation_recno]->nation_firm_count--;

    //------ update firm counter -------//

    FirmInfo* firmInfo = firm_res[firm_id];

    firmInfo->total_firm_count--;

    if( nation_recno )
        firmInfo->dec_nation_firm_count(nation_recno);

    //------- update town border ---------//

    loc_x1 = -1;      // mark deleted

    //------- if the current firm is the selected -----//

    if( firm_array.selected_recno == firm_recno )
//.........这里部分代码省略.........
开发者ID:mecirt,项目名称:7k2,代码行数:101,代码来源:ofirm.cpp

示例9: while

//---------- Begin of function Game::scenario_editor_menu ----------//
//
void Game::scenario_editor_menu()
{
	int refreshFlag = SPOPTION_ALL;

	mouse_cursor.set_icon(CURSOR_NORMAL);

	{
		VgaFrontLock vgaLock;

		while(1)
		{
#if 0  // FIXME
			MSG msg;
			if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
			{
				if (!GetMessage( &msg, NULL, 0, 0))
				{
					sys.signal_exit_flag = 1;
					// BUGHERE : vga_front is unlocked
					return;
				}
				TranslateMessage(&msg);
				DispatchMessage(&msg);
				continue;
			}
			else if( sys.paused_flag || !sys.active_flag )
			{
				WaitMessage();
				continue;
			}
#endif
			if( sys.need_redraw_flag )
			{
				refreshFlag = SPOPTION_ALL;
				sys.need_redraw_flag = 0;
			}

			VgaFrontReLock vgaReLock;

			// -------- display ----------//

			if( refreshFlag )
			{
				if( refreshFlag & SPOPTION_PAGE )
				{
					vga.use_back();
					vga_util.disp_image_file("M_MAIN");

					// ------ display button ------//

					font_thin_black.center_put_paragraph(
						BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2, 
						text_game_menu.str_new_game(), 0 );
					font_thin_black.center_put_paragraph(
						BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2, 
						text_game_menu.str_load_game(), 0 );
					font_thin_black.center_put_paragraph(
						BUTTON8_X1, BUTTON8_Y1, BUTTON8_X2, BUTTON8_Y2, 
						text_game_menu.str_cancel(), 0 );

					vga_util.blt_buf( 0, 0, VGA_WIDTH-1, VGA_HEIGHT-1, 0 );
					vga.use_front();
				}

				refreshFlag = 0;
			}

			sys.blt_virtual_buf();		// blt the virtual front buffer to the screen
			sys.yield();
			mouse.get_event();
			if( config.music_flag )
			{
				if( !music.is_playing(3) )
					music.play(3, sys.cdrom_drive ? MUSIC_CD_THEN_WAV : 0 );
			}
			else
			{
				music.stop();
			}

			// --------- detect -------//

			// detect new 
			if( mouse.single_click( BUTTON2_X1, BUTTON2_Y1, BUTTON2_X2, BUTTON2_Y2) )
			{
				game_file_array.init( DIR_SCENARIO, "*.SCN" );	// necessary to set the path and extension

				single_player_game(0);
				break;
			}

			// detect load game
			else if( mouse.single_click( BUTTON4_X1, BUTTON4_Y1, BUTTON4_X2, BUTTON4_Y2) )
			{
				err_when( MAX_SCENARIO_PATH <= 1 );
				game_file_array.init( DIR_SCENARIO, "*.SCN" );	// necessary to set the path and extension

				// ##### begin Gilbert 20/1 #######//
//.........这里部分代码省略.........
开发者ID:MicroVirus,项目名称:7k2,代码行数:101,代码来源:ogammain.cpp

示例10: multi_player_game

//#ifndef DISABLE_MULTI_PLAYER
//---------- Begin of function Game::multi_player_menu ----------//
//
void Game::multi_player_menu(char *cmdLine)
{
	mouse_cursor.set_icon(CURSOR_NORMAL);

	if( cmdLine != NULL && mp_obj.init_flag && mp_obj.is_lobbied() )
	{
		// find player profile
		char* lobbiedName = mp_obj.get_lobbied_name();
		// find profile with the same login name

		if( lobbiedName && player_profile.load_by_login_name(lobbiedName) )
		{
			if( player_profile.mp_new_game_flag == 1 )		// new game
			{
				player_profile.mp_new_game_flag = 0;
				player_profile.save();

				game_file_array.init( player_profile.save_game_path(NULL), "*.SVM" );	// necessary to set the path and extension
				multi_player_game(cmdLine);

				return;
			}
			else if ( player_profile.mp_new_game_flag == 2 )		// load game
			{
				player_profile.mp_new_game_flag = 0;

				// if load file is specified in the profile
				game_file_array.init( player_profile.save_game_path(NULL), "*.SVM" );	// necessary to set the path and extension

				char loadFileName[16];
				if( player_profile.mp_load_file_name[0] )
				{
					strcpy(loadFileName, player_profile.mp_load_file_name);
					strcat( loadFileName, ".SVM" ),		// append extension
					player_profile.mp_load_file_name[0] = '\0';
				}
				else
				{
					loadFileName[0] = '\0';
				}

				player_profile.save();

				if( loadFileName[0]
					&& game_file.load_game(player_profile.save_game_path(NULL), loadFileName) )
				{
					load_mp_game( loadFileName, cmdLine );
				}
				else
				{
					// conventional choose load game
					int loadedRecno;
					if( game_file_array.menu(3, &loadedRecno) == 1 )
					{
						err_when( !loadedRecno );
						load_mp_game(game_file_array[loadedRecno]->file_name, cmdLine);
					}
				}
				{
					char signalExitFlagBackup = sys.signal_exit_flag;
					sys.signal_exit_flag = 2;
					game.deinit();		// game.deinit() is needed if game_file_array.menu fails
					sys.signal_exit_flag = signalExitFlagBackup;
				}
				return;
			}
			else
			{
				return;	// quit

				// player_profile.mp_new_game_flag not specified
				// continue to interface
			}
		}	// end if load by login name
#ifdef DEBUG
		else
		{
			if( lobbiedName )
				err.msg( "Cannot find profile" );
		}
#endif
	}	// end if launchMode

//	char optionFlag[5] = { 1, 1, 1, 1, 1, };

	int refreshFlag = SPOPTION_ALL;
	bool launchMode = (cmdLine != NULL);

	{
		VgaFrontLock vgaLock;

		while(1)
		{
#if 0  // FIXME
			MSG msg;
			if (PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE))
			{
//.........这里部分代码省略.........
开发者ID:MicroVirus,项目名称:7k2,代码行数:101,代码来源:ogammain.cpp

示例11: err_when

//------- Begin of function FirmMarket::ai_create_new_trade ------//
//
int FirmMarket::ai_create_new_trade(Firm* firmPtr, int stop1PickUpType, int stop2PickUpType)
{
	//---- see if there is already a caravan moving along the route -----//

	Nation* 		 ownNation = nation_array[nation_recno];
	UnitCaravan* unitCaravan;
	int			 rc, stop1Id, stop2Id;
	int			 caravanInRouteCount=0;

	for( int i=ownNation->ai_caravan_count-1 ; i>=0 ; i-- )
	{
		unitCaravan = (UnitCaravan*) unit_array[ ownNation->ai_caravan_array[i] ];

		err_when( unitCaravan->nation_recno != nation_recno );
		err_when( unitCaravan->unit_id != UNIT_CARAVAN );

		if( unitCaravan->stop_defined_num < 2 )
			continue;

		if( unitCaravan->stop_array[0].firm_recno == firm_recno &&
			 unitCaravan->stop_array[1].firm_recno == firmPtr->firm_recno )
		{
			stop1Id = 1;
			stop2Id = 2;
		}
		else if( unitCaravan->stop_array[1].firm_recno == firm_recno &&
					unitCaravan->stop_array[0].firm_recno == firmPtr->firm_recno )
		{
			stop1Id = 2;
			stop2Id = 1;
		}
		else
		{
			continue;
		}

		//------- add the goods to the pick up list ----//

		rc = 0;

		if( stop1PickUpType && !unitCaravan->has_pick_up_type(stop1Id, stop1PickUpType) )
		{
			if( unitCaravan->is_visible() )		// can't set stop when the caravan is in a firm
				unitCaravan->set_stop_pick_up(stop1Id, stop1PickUpType, COMMAND_AI);
			rc = 1;
		}

		if( stop2PickUpType && !unitCaravan->has_pick_up_type(stop2Id, stop2PickUpType) )
		{
			if( unitCaravan->is_visible() )		// can't set stop when the caravan is in a firm
				unitCaravan->set_stop_pick_up(stop2Id, stop2PickUpType, COMMAND_AI);
			rc = 1;
		}

		if( rc )			// don't add one if we can utilize an existing one.
			return 1;

		caravanInRouteCount++;
	}

	if( caravanInRouteCount >= 2 )		// don't have more than 2 caravans on a single route
		return 0;

	//----------- hire a new caravan -----------//

	int unitRecno = hire_caravan(COMMAND_AI);

	if( !unitRecno )
		return 0;

	//----------- set up the trade route ----------//

	unitCaravan = (UnitCaravan*) unit_array[unitRecno];

	unitCaravan->set_stop(2, firmPtr->loc_x1, firmPtr->loc_y1, COMMAND_AI);

	err_when( unitCaravan->stop_array[0].firm_recno == firmPtr->firm_recno );		// cannot set both stops to the same firm

	unitCaravan->set_stop_pick_up(1, NO_PICK_UP, COMMAND_AI);
	unitCaravan->set_stop_pick_up(2, NO_PICK_UP, COMMAND_AI);

	if( stop1PickUpType )
		unitCaravan->set_stop_pick_up(1, stop1PickUpType, COMMAND_AI);

	if( stop2PickUpType )
		unitCaravan->set_stop_pick_up(2, stop2PickUpType, COMMAND_AI);

	return 1;
}
开发者ID:mecirt,项目名称:7k2,代码行数:91,代码来源:of_marka.cpp

示例12: memset

//------- Begin of function FirmMarket::think_import_new_product ------//
//
// Think about importing goods to sell in this market place.
//
int FirmMarket::think_import_new_product()
{
	//--- update what products are needed for this market place ---//

	int	i, j;
	Town* townPtr;
	short needProductSupplyPop[MAX_PRODUCT];			// the total population in the towns linked to the market that needs the supply of the product
	Nation* nationPtr = nation_array[nation_recno];

	memset( needProductSupplyPop, 0, sizeof(needProductSupplyPop) );

	for( i=0; i<linked_town_count; i++ )
	{
		err_when(!linked_town_array[i] || town_array.is_deleted(linked_town_array[i]));

		if( linked_town_enable_array[i] != LINK_EE )
			continue;

		townPtr = town_array[linked_town_array[i]];

		if( townPtr->region_id != region_id )
			continue;

		if( !townPtr->is_base_town )		// don't import if it isn't a base town
			continue;

		//------------------------------------------------//
		//
		// Only if the population of the town is equal or
		// larger than minTradePop, the AI will try to do trade.
		// The minTradePop is between 10 to 20 depending on the
		// pref_trading_tendency.
		//
		//------------------------------------------------//

		townPtr->update_product_supply();

		for( j=0 ; j<MAX_PRODUCT ; j++ )
		{
			if( !townPtr->has_product_supply[j] )
				needProductSupplyPop[j] += townPtr->population;
		}
	}

	//---- think about importing the products that need supply ----//

	int minTradePop = 10;

	for( int productId=1 ; productId<=MAX_PRODUCT ; productId++ )
	{
		if( needProductSupplyPop[productId-1] >= minTradePop )
		{
			if( think_import_specific_product(productId) )
			{
				last_import_new_goods_date = info.game_date;
				return 1;
			}
		}
	}

	//----------------------------------------------------------//
	// Think about importing the raw materials of the needed
	// products and build factories to manufacture them ourselves
	//----------------------------------------------------------//

	//--- first check if we can build a new factory to manufacture the products ---//

	if( is_market_linked_to_town(1) )		// 1-only count towns that are our own and are base towns
	{
		if( !no_neighbor_space &&
			 nationPtr->total_jobless_population >= MAX_WORKER*2 &&
			 can_hire_caravan() >= 2 )		// if there is a shortage of caravan supplies, use it for transporting finished products instead of raw materials
		{
			if( nationPtr->can_ai_build(FIRM_FACTORY) )
			{
				for( int productId=1 ; productId<=MAX_PRODUCT ; productId++ )
				{
					if( needProductSupplyPop[productId-1] >= minTradePop )
					{
						if( think_mft_specific_product(productId) )
						{
							last_import_new_goods_date = info.game_date;
							return 1;
						}
					}
				}
			}
		}
	}

	return 0;
}
开发者ID:mecirt,项目名称:7k2,代码行数:96,代码来源:of_marka.cpp

示例13: generate_raw_site

//--------- Begin of function SiteArray::next_day ----------//
//
void SiteArray::next_day()
{
	if( info.game_date%30 == 0 )
	{
		generate_raw_site();		// check if we need to generate existing raw sites are being used up and if we need to generate new ones
	}

	//-- if there is any scroll or gold coins available, ask AI to get them --//

	// #### begin Gilbert 3/11 ######//
	if(scroll_count || gold_coin_count || item_count || weapon_blueprint_count )
	// #### end Gilbert 3/11 ######//
	{
		int aiGetSiteObject = (info.game_date%5 == 0);

		Site* sitePtr;
		Location *locPtr;

		for(int i=size(); i; i--)
		{
			if(is_deleted(i))
				continue;

			sitePtr = site_array[i];

			switch(sitePtr->site_type)
			{
				case SITE_SCROLL:
				case SITE_GOLD_COIN:
				case SITE_ITEM:
				case SITE_WEAPON_BLUEPRINT:
					locPtr = world.get_loc(sitePtr->map_x_loc, sitePtr->map_y_loc);

					//---- if the unit is standing on a scroll site -----//

					if(locPtr->unit_recno(UNIT_LAND))
					{
						// ####### begin Gilbert 25/5 ##########//
						int unitRecno = locPtr->unit_recno(UNIT_LAND);
						if( !unit_array.is_deleted(unitRecno) )
							sitePtr->get_site_object( unitRecno );
						// ####### end Gilbert 25/5 ##########//
					}
					else if(aiGetSiteObject)
					{
						sitePtr->ai_get_site_object();
               }
					break;
			}
		}
	}

	//-------- debug testing --------//

#ifdef DEBUG

	if( info.game_date%10 == 0 )
	{
		Site* sitePtr;
		Location* locPtr;

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

			sitePtr = site_array[i];

			locPtr = world.get_loc( sitePtr->map_x_loc, sitePtr->map_y_loc );

			err_when( !locPtr->has_site() );
			err_when( locPtr->site_recno() != i );

			if( sitePtr->has_mine )
			{
				err_when( !locPtr->is_firm() );
				err_when( firm_array[locPtr->firm_recno()]->firm_id != FIRM_MINE
					&& firm_array[locPtr->firm_recno()]->firm_id != FIRM_ALCHEMY );
			}
			else
			{
				// disable because a mine can be upon more than one mine
				// err_when( locPtr->is_firm() || locPtr->is_town() );
			}
		}
	}
#endif
}
开发者ID:112212,项目名称:7k2,代码行数:90,代码来源:osite.cpp

示例14: spy_bribe_succeed_chance

//--------- Begin of function Firm::spy_bribe ---------//
//
// The money the spy offers to bribe the unit.
//
// <int>   bribeAmount	  - the amount offered
// <short> birberSpyRecno - spy recno of the briber
// <short> workerId		  - if 0, then bribe the overseer,
//									 if >0, then bribe a worker.
//
// return: <int> >0 - bribing succeeded, return the spy recno of the bribed unit (as it has been turned into a spy)
//					  0 - bribing failed
//
int Firm::spy_bribe(int bribeAmount, short briberSpyRecno, short workerId)
{
	if( !can_spy_bribe(workerId, spy_array[briberSpyRecno]->true_nation_recno) )		// this can happen in multiplayer as there is a one frame delay when the message is sent and when it is processed
		return 0;

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

	int succeedChance = spy_bribe_succeed_chance(bribeAmount, briberSpyRecno, workerId);

	Spy* spyPtr = spy_array[briberSpyRecno];

	nation_array[spyPtr->true_nation_recno]->add_expense( EXPENSE_BRIBE, (float) bribeAmount, 0 );

	//------ if the bribe succeeds ------//

	if( succeedChance > 0 && misc.random(100) < succeedChance )
	{
		int spyRecno = spy_array.add_spy();		// add a new Spy record

		Spy* newSpy = spy_array[spyRecno];

		newSpy->spy_skill = 10;
		newSpy->action_mode = SPY_IDLE;
		newSpy->spy_loyalty = MIN( 100, MAX(30,succeedChance) );		// within the 30-100 range

		newSpy->true_nation_recno    = spyPtr->true_nation_recno;
		newSpy->cloaked_nation_recno = spyPtr->cloaked_nation_recno;

		if( workerId )
		{
			Worker* workerPtr = worker_array+workerId-1;

			workerPtr->spy_recno = spyRecno;
			newSpy->race_id = workerPtr->race_id;
			newSpy->name_id = workerPtr->name_id;

			err_when( newSpy->race_id < 1 || newSpy->race_id > MAX_RACE );

			if( !newSpy->name_id )		// if this worker does not have a name, give him one now as a spy must reserve a name (see below on use_name_id() for reasons)
				newSpy->name_id = race_res[newSpy->race_id]->get_new_name_id();
		}
		else if( overseer_recno )
		{
			Unit* unitPtr = unit_array[overseer_recno];

			unitPtr->spy_recno = spyRecno;
			newSpy->race_id = unitPtr->race_id;
			newSpy->name_id = unitPtr->name_id;

			err_when( newSpy->race_id < 1 || newSpy->race_id > MAX_RACE );
		}
		else
			err_here();

		newSpy->set_place( SPY_FIRM, firm_recno );

		//-- Spy always registers its name twice as his name will be freed up in deinit(). Keep an additional right because when a spy is assigned to a town, the normal program will free up the name id., so we have to keep an additional copy

		race_res[newSpy->race_id]->use_name_id(newSpy->name_id);

		bribe_result = BRIBE_SUCCEED;

		if( firm_recno == firm_array.selected_recno )
			info.disp();

		return newSpy->spy_recno;
	}
	else //------- if the bribe fails --------//
	{
		spyPtr->get_killed(0);		// the spy gets killed when the action failed.
											// 0 - don't display new message for the spy being killed, so we already display the msg on the interface
		bribe_result = BRIBE_FAIL;

		if( firm_recno == firm_array.selected_recno )
			info.disp();

		return 0;
	}
}
开发者ID:AMDmi3,项目名称:7kaa,代码行数:91,代码来源:OFIRMIF3.cpp

示例15: switch

//---------- Begin of function Student::think_graduate -----------//
//!
//! graduate (use cummulative passed courses in general and grad prob for doctor);
//!
int Student::think_graduate() {
    //----- a student graduate when he/she has completed all the required number of courses ----//

    int requiredCourseCount;

    switch( student_level ) {
    case UG_TRADITION:
    case UG_NONTRADITION:
    case DISTANCE_LEARN:
	//32
	requiredCourseCount = COURSE_COUNT_REQUIRED_FOR_BACHELOR;
	break;

    case MASTER:
	//8
	requiredCourseCount = COURSE_COUNT_REQUIRED_FOR_MASTER;
	break;

    case DOCTOR:
	//16
	requiredCourseCount = COURSE_COUNT_REQUIRED_FOR_DOCTOR;
	break;
    }

    //##### begin fred 980915 #####//

    //Department* deptPtr = department_recno?department_array[department_recno] : department_res.general_dept;

    if( total_course_all < requiredCourseCount ) {
	//		info.debug_enroll++;   //## chea 281099
	return 0;
    }

    err_when(department_recno == 0);
    Department* deptPtr = department_array[department_recno];

    if ( student_level == DOCTOR ) {
	err_when(department_recno == 0);

	char yearIn = min(year_in_program-1, MAX_GRADUATE_YEARS-1);
	float gradProb = department_res[deptPtr->department_id]->doctor_graduate_trans_prob[yearIn];

	//
	float input[2];
	float multiplier = 1;
	//0223
	input[0] = math.dual_response_func(0.80f, 1.02f, 1.30f, 0.891f, 1.295f, 0.557f, 2.326f, 0);
	//0223
	input[1] = math.dual_response_func(0.80f, 1.00f, 1.30f, -0.912f, -0.863f, 2.502f, 0.489f, 0);

	multiplier = 0.5f * input[0] + 0.5f * input[1];
	// response_func var 28: multiplier = math.latency_func(0.33f, multiplier, lastMultiplier);

	if ( math.get_random_float() > gradProb * multiplier ) {
	    //			info.debug_enroll++;
	    return 0;
	}
    }
    //##### end fred 980915 #####//

    //-------- graduate now ----------------//

    //----- update the graduation count -----//

    switch( student_level ) {
    case UG_TRADITION:
    case UG_NONTRADITION:
	if ( student_level == UG_TRADITION ) {
	    deptPtr->student_array.cur_bachelor_degree++;
	    deptPtr->student_array.last_year_degree[0]++;
	}
	else {
	    deptPtr->student_array.cur_non_ug_bachelor_degree++;
	    deptPtr->student_array.last_year_degree[1]++;
	}
	deptPtr->student_array.time_to_degree_cumm[BACHELOR_DEGREE] += year_in_program;
	break;

    case MASTER:
	deptPtr->student_array.cur_master_degree++;
	deptPtr->student_array.last_year_degree[2]++;
	deptPtr->student_array.time_to_degree_cumm[MASTER_DEGREE] += year_in_program;
	break;

    case DOCTOR:
	deptPtr->student_array.cur_doctor_degree++;
	deptPtr->student_array.last_year_degree[3]++;
	deptPtr->student_array.time_to_degree_cumm[DOCTOR_DEGREE] += year_in_program;
	break;
    }

    //-- update average time to graduation for traditional undergraduates --//

    if( student_level == UG_TRADITION ) {

	int graduationTime = info.game_date - date_admitted;
//.........这里部分代码省略.........
开发者ID:ndilday,项目名称:virtualu,代码行数:101,代码来源:Ostudent.cpp


注:本文中的err_when函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。