Exemplo n.º 1
0
void CampaignEastWest::plot_d2_create_game()
{
	// find a non-own nation
	int srcNation;
	for( srcNation = nation_array.size(); srcNation > 0; --srcNation)
	{
		if( !nation_array.is_deleted(srcNation)
			&& !nation_array[srcNation]->is_own() )
		{
			break;
		}
	}

	//
	int unitId;
	short kingXLoc = -1, kingYLoc;
	if(srcNation)
	{
		Nation *nationPtr = nation_array[srcNation];
		if( nationPtr->is_human() )
			unitId = race_res[nationPtr->race_id]->infantry_unit_id;
		else
			unitId = monster_res[nationPtr->monster_id()]->unit_id;

		if( nationPtr->king_unit_recno )
		{
			unit_array[nationPtr->king_unit_recno]->get_cur_loc( kingXLoc, kingYLoc);
		}
	}
	else
		unitId = 0;


	Town *targetTown;

	// find a town and turn it independent

	int count = 1;
	for(int townRecno = 1; townRecno <= town_array.size() && count > 0; ++townRecno )
	{
		if( town_array.is_deleted(townRecno) )
			continue;

		targetTown = town_array[townRecno];
		if( targetTown->is_own() )
		{
			targetTown->set_nation(0);

			// ----- create a monster next to town -------//

			if( unitId && kingXLoc >= 0)
			{
				int unitRecno = targetTown->create_unit(unitId);
				if( unitRecno )
				{
					unit_array[unitRecno]->betray(srcNation);
					unit_array[unitRecno]->move(kingXLoc, kingYLoc, true);
				}
			}

			--count;
		}
	}
}
Exemplo n.º 2
0
// -------- begin of function ItemRes::use_manually ----------//
//
void ItemRes::use_manually( Item &item, int unitRecno, int targetBaseObjRecno, int para2)
{
	if( !item.id )
		return;
	err_when( item.id > ITEM_TYPE_COUNT );

	ItemInfo *itemInfo = item_info_array + item.id - 1;
	err_when( itemInfo->item_id != item.id );

	if( itemInfo->para_type == ITEM_PARA_USE_MANUAL )
	{
		if( unit_array.is_deleted(unitRecno) )
			return;

		Unit *unitPtr = unit_array[unitRecno];

		if( !unitPtr->is_visible() )
			return;

		switch( item.id )
		{
		case ITEM_SUMMON_SCROLL:
			{
				// create a random monster

				int summonUnitId = monster_res[misc.random(MAX_MONSTER_TYPE) + 1]->unit_id;
				SpriteInfo *summonSpriteInfo = sprite_res[unit_res[summonUnitId]->sprite_id];

				int r;
				for( r = 0; r <= 2; ++r )
				{
					int xLoc1 = unitPtr->obj_loc_x1() - summonSpriteInfo->loc_width - r;
					int yLoc1 = unitPtr->obj_loc_y1() - summonSpriteInfo->loc_height - r;
					int xLoc2 = unitPtr->obj_loc_x2() + summonSpriteInfo->loc_width + r;
					int yLoc2 = unitPtr->obj_loc_y2() + summonSpriteInfo->loc_height + r;

					if( world.locate_space( xLoc1, yLoc1, xLoc2, yLoc2,
						summonSpriteInfo->loc_width, summonSpriteInfo->loc_height) )
					{
						int summonRecno = unit_array.add_unit( summonUnitId, unitPtr->nation_recno, RANK_SOLDIER, 100, xLoc1, yLoc1 );
						if( summonRecno )
						{
							// ####### begin Gilbert 23/2 #########//
							Unit *summonUnit = unit_array[summonRecno];
							// ------- use monster level to determinte combat skill ------//

							int monsterLevel = monster_res[summonUnit->monster_id()]->level;
							err_when( monsterLevel < 3 || monsterLevel > 9 );	// tuned for level between 3 and 9
							int combatSkill = (7 * MAX_COMBAT_TRAIN + misc.random(MAX_COMBAT_TRAIN)) / (5 + monster_res[summonUnit->monster_id()]->level);
							combatSkill = MIN( combatSkill, MAX_COMBAT_TRAIN);
							summonUnit->set_combat_level( combatSkill );
							summonUnit->skill.set_skill_level(CITIZEN_SKILL_LEVEL);
							// ####### end Gilbert 19/2 #########//
							use_now(item);
							break;
						}
					}
				}

				// ####### begin Gilbert 5/3 #########//
				if( r > 2 && unitPtr->is_own() )		// failed
				{
					// failed sound effect
					se_ctrl.immediate_sound("TURN_OFF");
				}
				// ####### end Gilbert 5/3 #########//
			}
			break;

		case ITEM_UNIT_CHANGE_NATION:
			{
				// change unit to my nation

				Unit *targetUnit;
				if( !base_obj_array.is_deleted(targetBaseObjRecno)
					&& (targetUnit = base_obj_array[targetBaseObjRecno]->cast_to_Unit() )
					&& targetUnit->is_visible()
					&& targetUnit->rank_id != RANK_KING
					&& targetUnit->nation_recno != 0 && unitPtr->nation_recno != 0
					&& !targetUnit->is_nation(unitPtr->nation_recno)
					&& unitPtr->area_distance(targetUnit) <= 8
					&& targetUnit->betray(unitPtr->nation_recno) )
				{
					use_now(item);
				}
				else
				{
					if( unitPtr->is_own() )		// failed
					{
						// failed sound effect
						se_ctrl.immediate_sound("TURN_OFF");
					}
				}
			}
			break;

		case ITEM_TOWN_CHANGE_NATION:
			{
				// change town to our nation

				Town *targetTown;
				if( !base_obj_array.is_deleted(targetBaseObjRecno)
					&& (targetTown = base_obj_array[targetBaseObjRecno]->cast_to_Town() )
					&& !targetTown->under_construction
					&& unitPtr->nation_recno != 0
					&& targetTown->nation_recno != unitPtr->nation_recno
					&& unitPtr->area_distance(targetTown) <= 8
					&& (targetTown->surrender(unitPtr->nation_recno), targetTown->nation_recno == unitPtr->nation_recno) )
				{
					use_now(item);
				}
				else
				{
					if( unitPtr->is_own() )
					{
						// failed sound effect
						se_ctrl.immediate_sound("TURN_OFF");
					}
				}
			}
			break;

		case ITEM_TOWN_FREE:
			{
				// change town to independent nation

				Town *targetTown;
				if( !base_obj_array.is_deleted(targetBaseObjRecno)
					&& (targetTown = base_obj_array[targetBaseObjRecno]->cast_to_Town() )
					&& !targetTown->under_construction
					&& targetTown->nation_recno != 0
					&& unitPtr->area_distance(targetTown) <= 8
					&& (targetTown->set_nation(0), targetTown->nation_recno == 0) )
				{
					use_now(item);
				}
				else
				{
					if( unitPtr->is_own() )
					{
						// failed sound effect
						se_ctrl.immediate_sound("TURN_OFF");
					}
				}
			}
			break;

		case ITEM_TELEPORT:
			{
				// targetBaseObjRecno is xLoc,
				// para2 is yLoc
				if( unitPtr->teleport( targetBaseObjRecno, para2 ) )
				{
					use_now(item);
				}
				else
				{
					if( unitPtr->is_own() )
					{
						// failed sound effect
						se_ctrl.immediate_sound("TURN_OFF");
					}
				}
			}
			break;

		default:
			err_here();
		}
	}
}