コード例 #1
0
ファイル: otornado.cpp プロジェクト: 112212/7k2
// ---------- Begin of function Sprite::is_stealth --------//
int Tornado::is_stealth()
{
	err_when( cur_x_loc() < 0 || cur_x_loc() >= MAX_WORLD_X_LOC );
	err_when( cur_y_loc() < 0 || cur_y_loc() >= MAX_WORLD_Y_LOC );
	// if the visibility of location is just explored, consider stealth
	// ######## begin Gilbert 19/2 ########//
	return config.blacken_map && !config.explore_whole_map 
		&& !world.get_loc(cur_x_loc(), cur_y_loc())->explored();
	// ######## end Gilbert 19/2 ########//
}
コード例 #2
0
ファイル: oun_proc.cpp プロジェクト: 112212/7k2
//--------- Begin of function Unit::can_spy_change_nation ---------//
//
// Whether the spy unit can change its spy cloak now or not.
//
// If there are enemy nearby, the unit cannot change its cloak.
//
int Unit::can_spy_change_nation()
{
	if( !spy_recno )
		return 0;

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

	int xLoc1=cur_x_loc()-SPY_ENEMY_RANGE, yLoc1=cur_y_loc()-SPY_ENEMY_RANGE;
	int xLoc2=cur_x_loc()+SPY_ENEMY_RANGE, yLoc2=cur_y_loc()+SPY_ENEMY_RANGE;

	xLoc1 = max(0, xLoc1);
	yLoc1 = max(0, yLoc1);
	xLoc2 = min(MAX_WORLD_X_LOC-1, xLoc2);
	yLoc2 = min(MAX_WORLD_Y_LOC-1, yLoc2);

	int       xLoc, yLoc;
	int       unitRecno, trueNationRecno = true_nation_recno();
   Location* locPtr;

   for( yLoc=yLoc1 ; yLoc<=yLoc2 ; yLoc++ )
   {
      locPtr = world.get_loc(xLoc1, yLoc);

      for( xLoc=xLoc1 ; xLoc<=xLoc2 ; xLoc++, locPtr++ )
      {
			if( locPtr->unit_recno(UNIT_LAND) )
            unitRecno = locPtr->unit_recno(UNIT_LAND);

			else if( locPtr->unit_recno(UNIT_SEA) )
				unitRecno = locPtr->unit_recno(UNIT_SEA);

			else if( locPtr->unit_recno(UNIT_AIR) )
            unitRecno = locPtr->unit_recno(UNIT_AIR);

         else
            continue;

         if( unit_array.is_deleted(unitRecno) )    // the unit is dying, its recno is still in the location
            continue;

			Unit* unitPtr = unit_array[unitRecno];

			if( unitPtr->true_nation_recno() != trueNationRecno &&
				 unitPtr->nation_recno != trueNationRecno )
			{
				return 0;
			}
		}
	}

	return 1;
}
コード例 #3
0
ファイル: osprite2.cpp プロジェクト: mecirt/7k2
//--------- Begin of function Sprite::process_attack --------//
//
// Return: <int> 1 - if the sprite just finished its current attack
//					  0 - other statuses - either waiting for next attack
//					      or is attacking.
//
int Sprite::process_attack()
{
	if(remain_attack_delay && cur_frame==1)
		return 0;

	//------- next attack frame --------//
	SpriteAttack* spriteAttack = cur_sprite_attack();

	// ------ sound effect --------//
	char action[] = "A1";
	action[1] += cur_attack;
	se_res.sound(cur_x_loc(), cur_y_loc(), cur_frame, 'S', sprite_id, action);

#ifdef DEBUG
	UCHAR oldCurFrame = cur_frame;
#endif

	if( ++cur_frame > spriteAttack->frame_count )
	{
		cycle_eqv_attack();		// assume only unit can attack
		cur_frame = 1;

		set_remain_attack_delay();		// set it to the max and start the backward counting
		return 1;
	}

	return 0;
}
コード例 #4
0
ファイル: OU_MONS.cpp プロジェクト: spippolatore/7kaa
//------- Begin of function UnitMonster::die -------//
//
void UnitMonster::die()
{
	if( !is_visible() )
		return;

	//--- check if the location where the unit dies already has an item ---//

	int xLoc = cur_x_loc();
	int yLoc = cur_y_loc();

	if( !world.get_loc(xLoc, yLoc)->can_build_site() )
	{
		int txLoc, tyLoc, foundFlag=0;

		for( tyLoc=max(yLoc-1,0) ; tyLoc<=min(yLoc+1,MAX_WORLD_Y_LOC-1) && !foundFlag ; tyLoc++ )
		{
			for( txLoc=max(xLoc-1,0) ; txLoc<=min(xLoc+1,MAX_WORLD_X_LOC-1) ; txLoc++ )
			{
				if( world.get_loc(txLoc,tyLoc)->can_build_site() )
				{
					xLoc = txLoc;
					yLoc = tyLoc;
					foundFlag = 1;
					break;
				}
			}
		}

		if( !foundFlag )
			return;
	}

	//--- when a general monster is killed, it leaves gold coins ---//

	if( !nation_recno && get_monster_id() != 0)	// to skip monster_res[ get_monster_id() ] error in test game 2
	{
		MonsterInfo* monsterInfo = monster_res[ get_monster_id() ];

		if( rank_id == RANK_GENERAL )
		{
			int goldAmount = 2 * max_hit_points * monsterInfo->level * (100+m.random(30)) / 100;

			site_array.add_site( xLoc, yLoc, SITE_GOLD_COIN, goldAmount );
			site_array.ai_get_site_object();		// ask AI units to get the gold coins
		}

		//--- when a king monster is killed, it leaves a scroll of power ---//

		else if( rank_id == RANK_KING )
		{
			king_leave_scroll();
		}
	}

	//---------- add news ----------//

	if( rank_id == RANK_KING )
		news_array.monster_king_killed( get_monster_id(), next_x_loc(), next_y_loc() );
}
コード例 #5
0
ファイル: ob_proj.cpp プロジェクト: mecirt/7k2
// --------- Begin of function Projectile::init --------//
//### begin alex 3/5 ###//
void Projectile::init(char parentType, short parentRecno, short targetXLoc, short targetYLoc, char targetMobileType)
{
	Bullet::init(parentType, parentRecno, targetXLoc, targetYLoc, targetMobileType);
//#### end alex 3/5 ####//
	short spriteId = sprite_info->get_sub_sprite_info(1)->sprite_id;
	act_bullet.init( spriteId, cur_x_loc(), cur_y_loc() );
	short shadowSpriteId = sprite_info->get_sub_sprite_info(2)->sprite_id;
	bullet_shadow.init( shadowSpriteId, cur_x_loc(), cur_y_loc() );

	// calculate z_coff;
	z_coff = (float)1.0;
	/*
	float dz = z_coff * total_step;
	if( dz >= 10.0)
		cur_dir = cur_dir & 7 | 8;					// pointing up
	else if( dz <= -10.0)
		cur_dir = cur_dir & 7 | 16;				// pointing down
	else
		cur_dir &= 7;
	*/

	// --------- recalcuate spriteFrame pointer ----------//
	SpriteFrame* spriteFrame = cur_sprite_frame();
}
コード例 #6
0
ファイル: osprite2.cpp プロジェクト: mecirt/7k2
//--------- Begin of function Sprite::process_die --------//
//
// return : <int> 1 - dying animation completes.
//					   0 - still dying
// 
int Sprite::process_die()
{
	//--------- next frame ---------//

//	if( sys.frame_count%2 == 0 )
//	{
		if (cur_frame == 1)
		{
			BaseObj *baseObj = base_obj_array[base_obj_recno];
			Unit* unitPtr = baseObj->cast_to_Unit();
			if (unitPtr)
				unitPtr->add_die_effect();
		}
		se_res.sound(cur_x_loc(), cur_y_loc(), cur_frame, 'S',sprite_id,"DIE");
		if( ++cur_frame > sprite_info->die.frame_count )
			return 1;
//	}

	return 0;
}
コード例 #7
0
ファイル: ounitb.cpp プロジェクト: mecirt/7k2
//--------- Begin of function UnitB::next_move ---------//
//
//	If there is unprocessed node(s) in the result_node_array,
// then next unprocessed node will be set to be the next location
// to move to. (i.e. go_? = location of the unprocessed node)
//
void UnitB::next_move()
{
	if( cur_path == NULL || !cur_path_result_id )
		return;

	//------------ all nodes are visited --------------//

	err_when(cur_x!=next_x || cur_y!=next_y);

	set_idle();

	//---- order the unit to move to the next checkpoint following the path ----//

	PathResult* pathResult = cur_path + cur_path_result_id - 1;
	cur_path_result_id--;

	err_when( pathResult->loc_x == cur_x_loc() && pathResult->loc_y == cur_y_loc() );

	sprite_move( pathResult->loc_x * LOCATE_WIDTH, pathResult->loc_y * LOCATE_HEIGHT );

	err_when(cur_x==go_x && cur_y==go_y && (cur_x!=next_x || cur_y!=next_y));
}
コード例 #8
0
ファイル: OU_MARI.cpp プロジェクト: spippolatore/7kaa
void UnitMarine::init(int unitId, int nationRecno, int rankId, int unitLoyalty, int startX, int startY)
{
	attack_mode_selected = 0;       // for fix_attack_info() to set attack_info_array

	Unit::init(unitId, nationRecno, rankId, unitLoyalty, startX, startY);

	short spriteId = sprite_info->get_sub_sprite_info(1)->sprite_id;
	splash.init( spriteId, cur_x_loc(), cur_y_loc() );
	splash.cur_frame = 1;

	//------- set carry_goods_capacity -------//

	carry_goods_capacity = unit_res[unitId]->carry_goods_capacity;

	//------- set menu mode of the unit -------//

	UnitInfo* unitInfo = unit_res[unitId];

	if( unitInfo->carry_unit_capacity==0 && unitInfo->carry_goods_capacity>0 )		// if this ship only carries goods
		menu_mode = SHIP_MENU_GOODS;
	else
		menu_mode = SHIP_MENU_UNIT;
}
コード例 #9
0
ファイル: OBULLET.cpp プロジェクト: LibreGames/7kaa
//--------- Begin of function Bullet::process_die --------//
//
// return : <int> 1 - dying animation completes.
//					   0 - still dying 
//
int Bullet::process_die()
{

	// ------- sound effect --------//
	se_res.sound(cur_x_loc(), cur_y_loc(), cur_frame, 'S',sprite_id,"DIE");

	//--------- next frame ---------//
	if( ++cur_frame > sprite_info->die.frame_count )
	// ####### begin Gilbert 28/6 ########//
	if( ++cur_frame > sprite_info->die.frame_count )
	{
		// ------- set fire on the target area --------//
		if( fire_radius > 0)
		{
			Location *locPtr;
			if( fire_radius == 1)
			{
				locPtr = world.get_loc(target_x_loc, target_y_loc);
				if( locPtr->can_set_fire() && locPtr->fire_str() < 30 )
					locPtr->set_fire_str(30);
				if( locPtr->fire_src() > 0 )
					locPtr->set_fire_src(1);		// such that the fire will be put out quickly
			}
			else
			{
				short x, y, x1, y1, x2, y2;
				// ##### begin Gilbert 2/10 ######//
				x1 = target_x_loc - fire_radius + 1;
				if( x1 < 0 )
					x1 = 0;
				y1 = target_y_loc - fire_radius + 1;
				if( y1 < 0 )
					y1 = 0;
				x2 = target_x_loc + fire_radius - 1;
				if( x2 >= world.max_x_loc )
					x2 = world.max_x_loc-1;
				y2 = target_y_loc + fire_radius - 1;
				if( y2 >= world.max_y_loc )
					y2 = world.max_y_loc-1;
				// ##### end Gilbert 2/10 ######//
				for( y = y1; y <= y2; ++y)
				{
					locPtr = world.get_loc(x1, y);
					for( x = x1; x <= x2; ++x, ++locPtr)
					{
						// ##### begin Gilbert 30/10 ######//
						int dist = abs(x-target_x_loc) + abs(y-target_y_loc);
						if( dist > fire_radius)
							continue;
						int fl = 30 - dist * 7;
						if( fl < 10 )
							fl = 10;
						if( locPtr->can_set_fire() && locPtr->fire_str() < fl )
							locPtr->set_fire_str(fl);
						if( locPtr->fire_src() > 0 )
							locPtr->set_fire_src(1);		// such that the fire will be put out quickly
						// ##### begin Gilbert 30/10 ######//
					}
				}
			}
		}
		return 1;
	}
	// ####### end Gilbert 28/6 ########//
	return 0;
}
コード例 #10
0
ファイル: oun_act.cpp プロジェクト: mecirt/7k2
void Unit::gain_experience()
{
	//#### begin Gilbert 22/4 ######//

//	if( !race_id )
//		return; 		// no experience gain if unit is a living being

	UnitInfo *unitInfo = unit_res[unit_id];

	//---- increase the unit's contribution to the nation ----//

	if( !unitInfo->class_info.has_weapon_version		// get_weapon_level() share nation_contribution
		&& unitInfo->class_info.has_loyalty )
	{
		if( nation_contribution < MAX_NATION_CONTRIBUTION )
		{
			nation_contribution++;

			err_when( nation_contribution < 0 );		// overflow
		}
	}

	//------ increase combat skill -------//

	if( unitInfo->class_info.has_combat_level )
	{
		// test raw combat level
		err_when( skill.actual_combat_level()<0 || skill.actual_combat_level(NULL)>1000);

		skill.inc_combat_level(0.10f);

		// ------ effect of god ----------//

		// ##### patch begin Gilbert 16/2 #######//
		//if( race_id == RACE_CELTIC && nation_recno
		//	&& god_res[GOD_CELTIC]->nation_prayer_count(nation_recno) > 0 )
		if( nation_recno && god_res[GOD_CELTIC]->nation_prayer_count(nation_recno) > 0 )
		{
			if( race_id == RACE_CELTIC )
				skill.inc_combat_level(0.10f);		// skill increase greatly in battle
			else
				skill.inc_combat_level(0.04f);		// skill increase greatly in battle
		}
		// ##### patch end Gilbert 16/2 #######//
	}

	//--- if this is a soldier led by a commander, increase the leadership of its commander -----//

	if( !unit_array.is_deleted(leader_unit_recno) )
	{
		Unit* leaderUnit = unit_array[leader_unit_recno];
		int	leaderXLoc= -1, leaderYLoc;

		if( leaderUnit->is_visible() )
		{
			leaderXLoc = cur_x_loc();
			leaderYLoc = cur_y_loc();
		}
		else if( leaderUnit->unit_mode == UNIT_MODE_OVERSEE )
		{
			Firm* firmPtr = firm_array[leaderUnit->unit_mode_para];

			leaderXLoc = firmPtr->center_x;
			leaderYLoc = firmPtr->center_y;
		}
		else
			leaderXLoc = -1;

		if( leaderXLoc >= 0 &&
			 m.points_distance( cur_x_loc(), cur_y_loc(), leaderXLoc, leaderYLoc ) <= EFFECTIVE_LEADING_DISTANCE )
		{
			leaderUnit->skill.inc_skill_level(0.06f);

			//-- give additional increase if the leader has skill potential on leadership --//

			if( leaderUnit->skill.skill_potential > 0 )
			{
				if( m.random(10-leaderUnit->skill.skill_potential/10)==0 )
					leaderUnit->skill.inc_skill_level(0.12f);
			}
		}

		//--- if this soldier has leadership potential and is led by a commander ---//
		//--- he learns leadership by watching how the commander commands the troop --//

		if( unitInfo->class_info.has_skill_level )
		{
			if( skill.skill_potential > 0 )
			{
				if( m.random(10-skill.skill_potential/10)==0 )
					skill.inc_skill_level(0.12f);
			}
		}
	}

	//#### end Gilbert 22/4 ######//
}
コード例 #11
0
ファイル: OSPRITE.cpp プロジェクト: AMDmi3/7kaa
// ---------- Begin of function Sprite::is_shealth --------//
int Sprite::is_shealth()
{
	// if the visibility of location is just explored, consider shealth
	return config.fog_of_war && world.get_loc(cur_x_loc(), cur_y_loc())->visibility() <= EXPLORED_VISIBILITY;
}