コード例 #1
0
ファイル: c1_Runtime1_sparc.cpp プロジェクト: pombreda/graal
static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true) {
  assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words),
         "mismatch in calculation");
  __ save_frame_c1(frame_size_in_bytes);

  // Record volatile registers as callee-save values in an OopMap so their save locations will be
  // propagated to the caller frame's RegisterMap during StackFrameStream construction (needed for
  // deoptimization; see compiledVFrame::create_stack_value).  The caller's I, L and O registers
  // are saved in register windows - I's and L's in the caller's frame and O's in the stub frame
  // (as the stub's I's) when the runtime routine called by the stub creates its frame.
  // OopMap frame sizes are in c2 stack slot sizes (sizeof(jint))

  int i;
  for (i = 0; i < FrameMap::nof_cpu_regs; i++) {
    Register r = as_Register(i);
    if (r == G1 || r == G3 || r == G4 || r == G5) {
      int sp_offset = cpu_reg_save_offsets[i];
      __ st_ptr(r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
    }
  }

  if (save_fpu_registers) {
    for (i = 0; i < FrameMap::nof_fpu_regs; i++) {
      FloatRegister r = as_FloatRegister(i);
      int sp_offset = fpu_reg_save_offsets[i];
      __ stf(FloatRegisterImpl::S, r, SP, (sp_offset * BytesPerWord) + STACK_BIAS);
    }
  }

  return generate_oop_map(sasm, save_fpu_registers);
}
コード例 #2
0
ファイル: salary.c プロジェクト: ekuznets/PKM2
void CalculateInfoData()
{
	int i,cn,crewQ;
	ref mchref,chref;

	crewQ = 0;
	mchref = GetMainCharacter();
	for(i=0; i<4; i++)
	{
		cn = GetCompanionIndex(mchref,i);
		if( cn>=0 && GetRemovable(&Characters[cn]) )
		{
			chref = GetCharacter(cn);
			crewQ += GetCrewQuantity(chref);
		}
	}

	int nLeaderShip = GetSummonSkillFromName(mchref,SKILL_LEADERSHIP);
	nPaymentQ = 5 + crewQ*(16-nLeaderShip);
	if( CheckAttribute(mchref,"CrewPayment") ) {
		nPaymentQ += makeint( stf(mchref.CrewPayment)*(11.0-SKILL_LEADERSHIP)/10.0 );
	}

	nMoraleDecreaseQ = 30-nLeaderShip;
	if( CheckCharacterPerk(mchref,"IronWill") ) nMoraleDecreaseQ /= 2;

	CreateString(true,"payment",""+nPaymentQ,FONT_NORMAL,COLOR_NORMAL,320,258,SCRIPT_ALIGN_CENTER,1.0);

	if( sti(mchref.Money) < nPaymentQ )
	{
		SetSelectable("B_OK",false);
		SetCurrentNode("B_CANCEL");
	}
}
コード例 #3
0
inline void MacroAssembler::store_double_argument( FloatRegister s, Argument& a ) {
  if (a.is_float_register())
// V9 ABI has D0, D2, D4 are used to pass instead of O0, O1, O2
    fmov(FloatRegisterImpl::D, s, a.as_double_register() );
  else
    stf(FloatRegisterImpl::D, s, a.as_address());
}
コード例 #4
0
ファイル: SignTestByGene.cpp プロジェクト: A1kmm/suvetma
int
main(int argc, char** argv)
{
  po::options_description desc;
  std::string controlMatrix, modelMatrix, geneList;

  desc.add_options()
    ("controlmatrix", po::value<std::string>(&controlMatrix),
     "The error matrix for the model expected to fit poorly")
    ("modelmatrix", po::value<std::string>(&modelMatrix),
     "The error matrix for the model expected to fit well")
    ("genelist", po::value<std::string>(&geneList),
     "The file containing the list of genes")
    ;

  po::variables_map vm;

  po::store(po::parse_command_line(argc, argv, desc), vm);
  po::notify(vm);

  std::string wrong;
  if (!vm.count("help"))
  {
    if (!vm.count("controlmatrix"))
      wrong = "controlmatrix";
    else if (!vm.count("modelmatrix"))
      wrong = "modelmatrix";
    else if (!vm.count("genelist"))
      wrong = "genelist";
  }

  if (wrong != "")
    std::cerr << "Missing option: " << wrong << std::endl;
  if (vm.count("help") || wrong != "")
  {
    std::cout << desc << std::endl;
    return 1;
  }

  if (!fs::is_regular(controlMatrix))
  {
    std::cout << "Control matrix file not found." << std::endl;
    return 1;
  }

  if (!fs::is_regular(modelMatrix))
  {
    std::cout << "Model matrix file not found." << std::endl;
    return 1;
  }

  if (!fs::is_regular(geneList))
  {
    std::cout << "Gene list not found." << std::endl;
  }

  SignTestFits stf(controlMatrix, modelMatrix, geneList);
}
コード例 #5
0
ファイル: LAi_follow.c プロジェクト: ekuznets/PKM2
//Процессирование шаблона персонажа
void LAi_tmpl_follow_CharacterUpdate(aref chr, float dltTime)
{
	aref tmpl;
	makearef(tmpl, chr.chr_ai.tmpl);
	int idx;
	float time, timeout;
	timeout = stf(tmpl.timeout);
	if(timeout >= 0.0)
	{
		time = stf(tmpl.time);
		if(time < timeout)
		{
			tmpl.time = time + dltTime;
		}else{
			Trace("Template <follow> -> timeout chr.id = " + chr.id);
			SetCharacterTask_Stay(chr);
			LAi_tmpl_follow_Teleport(chr);			
			tmpl.state = "stay";			
		}
	}
	if(tmpl.state == "stay")
	{
		if(timeout >= 0.0)
		{
			tmpl.timeout = "-1";
			LAi_tmpl_follow_Complite(chr);
		}
	}else{
		if(tmpl.state == "pause")
		{
			time = stf(tmpl.wait) - dltTime;
			if(time < 0)
			{
				LAi_tmpl_follow_Go(chr);
			}else{
				tmpl.wait = time;
			}
		}else{
			if(tmpl.state == "wait")
			{
				SetCharacterTask_Stay(chr);
			}
		}
	}
}
コード例 #6
0
inline void MacroAssembler::store_float_argument( FloatRegister s, Argument& a ) {
  if (a.is_float_register())
// V9 ABI has F1, F3, F5 are used to pass instead of O0, O1, O2
    fmov(FloatRegisterImpl::S, s, a.as_float_register() );
  else
    // Floats are stored in the high half of the stack entry
    // The low half is undefined per the ABI.
    stf(FloatRegisterImpl::S, s, a.as_address(), sizeof(jfloat));
}
コード例 #7
0
int main(int argc, char** argv)
{
  ros::init(argc, argv, "SparseTracker");
  ros::NodeHandle nh;
  ros::NodeHandle nh_private("~");
  ccny_rgbd::SparseTrackerF stf(nh, nh_private);
  ros::spin();
  return 0;
}
コード例 #8
0
// dopasowuje napisy do pliku z filmem
bool QNapiAbstractEngine::match()
{
	QFileInfo stf(subtitlesTmp);

	if(!stf.exists())
		return false;

	QFileInfo mf(movie);

	subtitles = mf.path() + "/" + mf.completeBaseName() + "." + stf.suffix();

	QFileInfo sf(subtitles);

	if(!QFileInfo(sf.absolutePath()).isWritable())
		return false;

	if(QFile::exists(subtitles))
	{
		if(!noBackup)
		{
			QString newName = mf.path() + QDir::separator() + mf.completeBaseName() + "_kopia." + sf.suffix();

			if(QFile::exists(newName))
				QFile::remove(newName);

			QFile::rename(subtitles, newName);			
		}
		else
			QFile::remove(subtitles);
	}

	bool r = false;

#ifdef Q_WS_WIN
	// Pod windowsem, aby "wyczyscic" atrybuty pliku, tworzymy go na nowo
	QFile f(subtitles), f2(subtitlesTmp);
	if(!f.open(QIODevice::WriteOnly) || !f2.open(QIODevice::ReadOnly))
	{
		f.close();
	}
	else
	{
		r = f.write(f2.readAll()) > 0;
		f2.close();
		f.close();
	}
#else
	// pod normalnymi OS-ami nie trzeba sie gimnastykowac z atrybutami
	r = QFile::copy(subtitlesTmp, subtitles);
#endif

	return r;
}
コード例 #9
0
ファイル: LAi_follow.c プロジェクト: ekuznets/PKM2
void LAi_tmpl_follow_updatetemplate(aref chr)
{
	bool isGo = false;
	if(chr.chr_ai.tmpl.state == "go") isGo = true;
	if(chr.chr_ai.tmpl.state == "stay") isGo = true;
	if(isGo)
	{
		int idx = sti(chr.chr_ai.tmpl.follow);
		LAi_tmpl_follow_SetFollow(chr, &Characters[idx], stf(chr.chr_ai.tmpl.timeout));
	}else{
		SetCharacterTask_Stay(chr);
	}
}
コード例 #10
0
ファイル: LAi_follow.c プロジェクト: ekuznets/PKM2
bool LAi_tmpl_follow_Teleport(aref chr)
{
	if(stf(chr.chr_ai.tmpl.timeout) >= 0)
	{
		if(chr.chr_ai.tmpl.follow == "") return false;
		int idx = sti(chr.chr_ai.tmpl.follow);
		float x, y, z;
		if(!GetCharacterPos(chr, &x, &y, &z)) return false;
		Trace("Template <follow> -> teleport chr.id = " + chr.id + " to pos(" + x + ", " + y + ", " + z + ")");
		TeleportCharacterToPos(chr, x, y, z);
		return true;
	}
	return false;
}
コード例 #11
0
inline void MacroAssembler::stf(FloatRegisterImpl::Width w, FloatRegister d, Register s1, RegisterOrConstant s2) {
  if (s2.is_register())  stf(w, d, s1, s2.as_register());
  else                   stf(w, d, s1, s2.as_constant());
}
コード例 #12
0
ファイル: RelationAgent_dialog.c プロジェクト: ekuznets/PKM2
void ProcessDialogEvent()
{
	ref NPChar, PChar, d;
	PChar = GetMainCharacter();
	aref Link, Diag;
	string NPC_Meeting, PeaceGroup;
	int Nation, Sum;
	
	DeleteAttribute(&Dialog,"Links");

	makeref(NPChar,CharacterRef);
	makearef(Link, Dialog.Links);
	makeref(d, Dialog);
	makearef(Diag, NPChar.Dialog);
	
	switch(Dialog.CurrentNode)
	{
		// -----------------------------------Диалог первый - первая встреча
		case "exit":
			Diag.CurrentNode = Diag.TempNode;
			NPChar.quest.meeting = NPC_Meeting;
			DialogExit();
		break;

		case "First time":
			Dialog.defAni = "dialog_stay2";
			Dialog.defCam = "2";
			Dialog.defSnd = "dialogs\0\017";
			Dialog.defLinkAni = "dialog_1";
			Dialog.defLinkCam = "1";
			Dialog.defLinkSnd = "dialogs\woman\024";
			Dialog.ani = "dialog_stay2";
			Dialog.cam = "1";
			
			if(Pchar.quest.RelationAgentMet == "0")
			{
				Dialog.snd = "voice\REDI\REDI001";
				d.Text = DLG_TEXT[0] + address_form.eng + DLG_TEXT[1];
				Link.l1 = DLG_TEXT[2];
				Link.l1.go = "Tutorial";
				NPC_Meeting = "1"; 
			}
			else
			{
				if(NPChar.quest.meeting == "0")
				{
					Dialog.snd = "voice\REDI\REDI002";
					d.Text = DLG_TEXT[3];
					Link.l1 = DLG_TEXT[4] + Pchar.name + DLG_TEXT[5];
					Link.l1.go = "Service";
					Link.l2 = DLG_TEXT[6];
					Link.l2.go = "Exit";					
				}
				else
				{
					Dialog.snd = "voice\REDI\REDI003";
					d.Text = DLG_TEXT[7] + Pchar.name"?" ;
					Link.l1 = DLG_TEXT[8];
					Link.l1.go = "Service";
					Link.l2 = DLG_TEXT[9];
					Link.l2.go = "exit";

				}
			}

		break;

		case "Service":
			Dialog.snd = "voice\REDI\REDI004";
			d.Text = DLG_TEXT[10];
			if(GetNationRelation2MainCharacter(ENGLAND) == RELATION_ENEMY)
			{
				Link.l1 = DLG_TEXT[11];
				Link.l1.go = "England";

			}
			if(GetNationRelation2MainCharacter(SPAIN) == RELATION_ENEMY)
			{
				Link.l2 = DLG_TEXT[12];
				Link.l2.go = "Spain";
			}
			if(GetNationRelation2MainCharacter(PORTUGAL) == RELATION_ENEMY)
			{
				Link.l3 = DLG_TEXT[13];
				Link.l3.go = "Portugal";			
			}
			if(GetNationRelation2MainCharacter(HOLLAND) == RELATION_ENEMY)
			{
				Link.l4 = DLG_TEXT[14];
				Link.l4.go = "Holland";			
			}
			if(GetNationRelation2MainCharacter(FRANCE) == RELATION_ENEMY)
			{
				Link.l5 = DLG_TEXT[15];
				Link.l5.go = "France";			
			}
			Link.l6 = DLG_TEXT[16];
			Link.l6.go = "exit";			
		break;

		case "Tutorial":
			Dialog.snd = "voice\REDI\REDI005";
			d.Text = DLG_TEXT[17];
			Link.l99 = DLG_TEXT[18];
			Link.l99.go = "Tutorial_1";
		break;

		case "Tutorial_1":
			Dialog.snd = "voice\REDI\REDI006";
			d.Text = DLG_TEXT[19];
			Link.l99 = DLG_TEXT[20];
			Link.l99.go = "Tutorial_2";
		break;

		case "Tutorial_2":
			Dialog.snd = "voice\REDI\REDI007";
			d.Text = DLG_TEXT[21];
			Link.l99 = DLG_TEXT[22];
			Link.l99.go = "Tutorial_3";
		break;

		case "Tutorial_3":
			Dialog.snd = "voice\REDI\REDI008";
			d.Text = DLG_TEXT[23];
			Link.l99 = DLG_TEXT[24];
			Link.l99.go = "Tutorial_4";
		break;

		case "Tutorial_4":
			Dialog.snd = "voice\REDI\REDI009";
			d.Text = DLG_TEXT[25];
			Link.l99 = DLG_TEXT[26];
			Link.l99.go = "Service";
		break;

		case "England":
			Pchar.quest.Relations.nation = ENGLAND;
			Pchar.quest.Relations.PeaceGroup = "ENGLAND_SOLDIERS";
			Pchar.quest.Relations.sum = makeint(stf(Pchar.rank)/stf(Pchar.reputation)*20000);	
			Dialog.snd = "voice\REDI\REDI010";
			d.Text = DLG_TEXT[27] + Pchar.quest.Relations.sum + DLG_TEXT[28];
			Link.l1 = DLG_TEXT[29];
			if(makeint(Pchar.money) < makeint(Pchar.quest.Relations.sum))
			{
				Link.l1.go = "No_money";			
			}
			else
			{
				Link.l1.go = "Agreed";			
			}
			Link.l2 = DLG_TEXT[30];
			Link.l2.go = "exit";			
		break;

		case "Spain":
			Pchar.quest.Relations.nation = SPAIN;
			Pchar.quest.Relations.PeaceGroup = "SPAIN_SOLDIERS";
			Pchar.quest.Relations.sum = makeint(stf(Pchar.rank)/stf(Pchar.reputation)*20000);	
			Dialog.snd = "voice\REDI\REDI011";
			d.Text = DLG_TEXT[31] + Pchar.quest.Relations.sum + DLG_TEXT[32];
			Link.l1 = DLG_TEXT[33];
			if(makeint(Pchar.money) < makeint(Pchar.quest.Relations.sum))
			{
				Link.l1.go = "No_money";			
			}
			else
			{
				Link.l1.go = "Agreed";			
			}
			Link.l2 = DLG_TEXT[34];
			Link.l2.go = "exit";			
		break;

		case "France":
			Pchar.quest.Relations.nation = FRANCE;
			Pchar.quest.Relations.PeaceGroup = "FRANCE_SOLDIERS";
			Pchar.quest.Relations.sum = makeint(stf(Pchar.rank)/stf(Pchar.reputation)*20000);	
			Dialog.snd = "voice\REDI\REDI012";
			d.Text = DLG_TEXT[35] + Pchar.quest.Relations.sum + DLG_TEXT[36];
			Link.l1 = DLG_TEXT[37];
			if(makeint(Pchar.money) < makeint(Pchar.quest.Relations.sum))
			{
				Link.l1.go = "No_money";			
			}
			else
			{
				Link.l1.go = "Agreed";			
			}
			Link.l2 = DLG_TEXT[38];
			Link.l2.go = "exit";			
		break;

		case "Portugal":
			Pchar.quest.Relations.nation = PORTUGAL;
			Pchar.quest.Relations.PeaceGroup = "CONCEICAO_SOLDIERS";
			Pchar.quest.Relations.sum = makeint(stf(Pchar.rank)/stf(Pchar.reputation)*20000);	
			Dialog.snd = "voice\REDI\REDI013";
			d.Text = DLG_TEXT[39] + Pchar.quest.Relations.sum + DLG_TEXT[40];
			Link.l1 = DLG_TEXT[41];
			if(makeint(Pchar.money) < makeint(Pchar.quest.Relations.sum))
			{
				Link.l1.go = "No_money";			
			}
			else
			{
				Link.l1.go = "Agreed";			
			}
			Link.l2 = DLG_TEXT[42];
			Link.l2.go = "exit";			
		break;

		case "Holland":
			Pchar.quest.Relations.nation = HOLLAND;
			Pchar.quest.Relations.PeaceGroup = "DOUWESEN_SOLDIERS";
			Pchar.quest.Relations.sum = makeint(stf(Pchar.rank)/stf(Pchar.reputation)*20000);	
			Dialog.snd = "voice\REDI\REDI014";
			d.Text = DLG_TEXT[43] + Pchar.quest.Relations.sum + DLG_TEXT[44];
			Link.l1 = DLG_TEXT[45];
			if(makeint(Pchar.money) < makeint(Pchar.quest.Relations.sum))
			{
				Link.l1.go = "No_money";			
			}
			else
			{
				Link.l1.go = "Agreed";			
			}
			Link.l2 = DLG_TEXT[46];
			Link.l2.go = "exit";			
		break;

		case "No_Money":
			Dialog.snd = "voice\REDI\REDI015";
			d.Text = DLG_TEXT[47];
			Link.l1 = DLG_TEXT[48];
			Link.l1.go = "exit";			
		break;

		case "Agreed":
			Dialog.snd = "voice\REDI\REDI016";
			SetNationRelation2MainCharacter(makeint(Pchar.quest.Relations.nation), RELATION_FRIEND);
			LAi_group_SetRelation(Pchar.quest.Relations.PeaceGroup, LAI_GROUP_PLAYER, LAI_GROUP_FRIEND);
			AddMoneyToCharacter(PChar, -(makeint(Pchar.quest.Relations.sum)));
			DeleteAttribute(Pchar, "quest.Relations");
			d.Text = DLG_TEXT[49];
			Link.l1 = DLG_TEXT[50];
			Link.l1.go = "Exit";
			Link.l2 = DLG_TEXT[51];
			Link.l2.go = "Service";
		break;
				

	}
}
コード例 #13
0
ファイル: LAi_guardian.c プロジェクト: ekuznets/PKM2
//Процессирование типа персонажа
void LAi_type_guardian_CharacterUpdate(aref chr, float dltTime)
{
	aref type;
	int trg, t;
	float time, dist;
	makearef(type, chr.chr_ai.type);
	//Режим ожидания
	if(type.wait != "") return;
	//Нормальная работа
	string tmpl = chr.chr_ai.tmpl;
	if(tmpl == LAI_TMPL_DIALOG) return;
	if(tmpl == LAI_TMPL_FIGHT)
	{
		bool isValidate = false;
		trg = LAi_tmpl_fight_GetTarget(chr);
		if(trg >= 0)
		{
			if(LAi_group_ValidateTarget(chr, &Characters[trg]))
			{
				if(!LAi_tmpl_fight_LostTarget(chr))
				{
					isValidate = true;
				}
			}
		}
		//Пробуем обновить оптимальную цель
		time = stf(type.etime) - dltTime;
		if(time <= 0.0)
		{
			type.etime = 0.0;
			t = LAi_group_GetTarget(chr);
			if(t != trg) 
				isValidate = false;
		}else{
			type.etime = time;
		}
		//Если текущая цель не действительна, получим новую
		if(!isValidate)
		{
			//Ищем новую цель
			trg = LAi_group_GetTarget(chr);
			if(trg < 0)
			{
				//Переходим в режим ожидания
				LAi_tmpl_fight_SetWaitState(chr);
				LAi_type_guardian_Return(chr);
			}else{
				//Натравливаем на новую цель
				LAi_type_guardian_CmdAttack_Now(chr, trg);
				if(rand(100) < 20)
				{
					LAi_CharacterPlaySound(chr, "warrior");
				}
			}
		}
	}else{
		if(tmpl == LAI_TMPL_STAY)
		{
			if(rand(1000) == 125)
			{
				LAi_CharacterPlaySound(chr, "guardian");
			}
			//Проверим наличие врагов
			trg = LAi_group_GetTarget(chr);
			if(trg >= 0)
			{
				chr.chr_ai.type.enemy = trg;
				LAi_type_guardian_CmdAttack(chr);
			}else{
				//Проверяем дистанцию до точки охраны
				dist = -1.0;
				if(GetCharacterDistByLoc(chr, chr.chr_ai.type.group, chr.chr_ai.type.locator, &dist))
				{
					if(dist > 1.0)
					{
						LAi_tmpl_runto_InitTemplate(chr);
						LAi_tmpl_runto_SetLocator(chr, chr.chr_ai.type.group, chr.chr_ai.type.locator, -1.0);
					}else{
						CharacterTurnByLoc(chr, chr.chr_ai.type.group, chr.chr_ai.type.locator);
					}
				}else{
					CharacterTurnByLoc(chr, chr.chr_ai.type.group, chr.chr_ai.type.locator);
				}
			}
		}else{
			//Проверим наличие врагов
			trg = LAi_group_GetTarget(chr);
			if(trg >= 0)
			{
				chr.chr_ai.type.enemy = trg;
				LAi_type_guardian_CmdAttack(chr);
			}else{
				if(tmpl != LAI_TMPL_RUNTO)
				{
					LAi_tmpl_stay_InitTemplate(chr);
				}else{
					if(LAi_tmpl_runto_IsStay(chr))
					{
						LAi_tmpl_stay_InitTemplate(chr);
					}
				}
			}
		}
	}
}
コード例 #14
0
inline void MacroAssembler::stf(FloatRegisterImpl::Width w, FloatRegister d, const Address& a, int offset) {
  relocate(a.rspec(offset));
  if (a.has_index()) { assert(offset == 0, ""); stf(w, d, a.base(), a.index()        ); }
  else               {                          stf(w, d, a.base(), a.disp() + offset); }
}
コード例 #15
0
ファイル: AIAttack.c プロジェクト: ekuznets/PKM2
// check attack task for Group
void AIAttack_CheckTask(string sGroupID)
{
	ref rG1 = Group_GetGroupByID(sGroupID);
	ref rG2 = Group_GetGroupByID(rG1.Task.Target);

	string sGroupType1 = Group_GetTypeR(rG1);

	ref rCharacter1 = Group_GetGroupCommanderR(rG1);

	// skip if group is player group
	if (sGroupID == PLAYER_GROUP) { return; }
	
	// if group task is lock, check for task complete, if not - continue task
	float fAng = frnd() * PIm2;
	if (Group_isDeadR(rG2))
	{
		switch (sGroupType1)
		{
			case "trade":
				Group_SetTaskMove(sGroupID, stf(rG1.Task.Target.Pos.x), stf(rG1.Task.Target.Pos.z));
			break;
			case "war":
				Group_SetTaskMove(sGroupID, 10000.0 * sin(fAng) , 10000.0 * cos(fAng));
			break;
			case "pirate":
				Group_SetTaskMove(sGroupID, 10000.0 * sin(fAng) , 10000.0 * cos(fAng));
			break;
		}
		// find new task
		return;
	}

	if (!Group_isTaskLockR(rG1))
	{
		float fHP1 = Group_GetPowerHP_R(rG1);
		float fHP2 = Group_GetPowerHP_R(rG2);
		float fAHP1 = Group_GetAttackHPDistance_R(rG1, 300.0);

		float fAHPRatio1 = fHP1 / (fAHP1 + 0.0001);
		float fHPRatio1 = fHP1 / (fHP2 + 0.0001);

		float fLeadership = MakeFloat(GetSummonSkillFromName(rCharacter1, SKILL_LEADERSHIP)) / SKILL_MAX;

		float fTmp = fAHPRatio1;// * Clampf(fLeadership + 0.01);

		switch (AIAttack_SelectTask(sGroupType1, fTmp))
		{
			case AITASK_RUNAWAY:
				Group_SetTaskRunaway(sGroupID);
				return;
			break;
		}
	}

	// check attack task for dead targets
	int iIndex = 0;

	int iCharactersNum2 = Group_GetCharactersNumR(rG2);
	
	// find targets for rG1
	int i = 0;
	while (true)
	{
		int iCharacterIndex = Group_GetCharacterIndexR(rG1, i); i++;
		if (iCharacterIndex < 0) { break; }
		ref rCharacter = GetCharacter(iCharacterIndex);
		if (LAi_IsDead(rCharacter)) { continue; }
		if (CheckAttribute(rCharacter, "SeaAI.Task"))
		{
			if (sti(rCharacter.SeaAI.Task) != AITASK_ATTACK) { continue; }
			if (!LAi_IsDead(&Characters[sti(rCharacter.SeaAI.Task.Target)])) { continue; }
		}

		int iCharacterVictim = -1;
		while (iCharacterVictim < 0)
		{
			iCharacterVictim = Group_GetCharacterIndexR(rG2, iIndex); 
			if (iCharacterVictim < 0) { iIndex = 0; continue; }
			if (LAi_IsDead(&Characters[iCharacterVictim])) { iCharacterVictim = -1; }
			iIndex++;
		}
    
		Ship_SetTaskAttack(SECONDARY_TASK, iCharacterIndex, iCharacterVictim);
	}		
}      	
コード例 #16
0
ファイル: LEnc_monsters.c プロジェクト: ekuznets/PKM2
//Установить модельку для монстра
bool LEnc_MonstersLoginSelectModel(ref location, aref modelInfo, string group, string locator)
{
	float type = rand(100)*0.01;
	if(LEnc_MonstersLoginObject.type == "inca_temple") type = 1.0;
	float skeleton = stf(LEnc_MonstersLoginObject.skeleton);
	float monkey = stf(LEnc_MonstersLoginObject.monkey);
	float mummy = stf(LEnc_MonstersLoginObject.mummy);
	float vagabond = stf(LEnc_MonstersLoginObject.vagabond);
	//Определимся, что выбрали
	float p = stf(LEnc_MonstersLoginObject.bandit);
	if(p > 0.0)
	{
		type = type - p;
		if(type <= 0)
		{
			//Бандита
			LEnc_MonstersLoginObject.current = "bandit";
			modelInfo.ani = "man";
			modelInfo.model = "rabwhite1";
			switch(rand(10))
			{
			case 0:
				modelInfo.model = "rabwhite1";
				break;
			case 1:
				modelInfo.model = "rabwhite";
				break;
			case 2:
				modelInfo.model = "rabblack";
				break;
			case 3:
				modelInfo.model = "fatman";
				break;
			case 4:
				modelInfo.model = "rabblack_1";
				break;
			case 5:
				modelInfo.model = "mask";
				break;
			case 6:
				modelInfo.model = "mask_2";
				break;
			case 7:
				modelInfo.model = "mask_3";
				break;
			case 8:
				modelInfo.model = "mask_4";
				break;
			case 9:
				modelInfo.model = "mask_3";
				break;
			case 10:
				modelInfo.model = "mask_4";
				break;
			}
			return true;
		}
	}
	p = stf(LEnc_MonstersLoginObject.skeleton);
	if(p > 0.0)
	{
		type = type - p;
		if(type <= 0)
		{
			//Скелета
			LEnc_MonstersLoginObject.current = "skeleton";
			modelInfo.model = "skel" + (1 + rand(3));
			modelInfo.ani = "man";
			return true;
		}
	}
	p = stf(LEnc_MonstersLoginObject.monkey);
	if(p > 0.0)
	{		
		type = type - p;
		if(type <= 0)
		{
			//Скелета-обезьяну
			LEnc_MonstersLoginObject.current = "monkey";
			modelInfo.model = "Monkey";
			modelInfo.ani = "Monkey";
			return true;
		}
	}
	p = stf(LEnc_MonstersLoginObject.mummy);
	if(p > 0.0)
	{		
		type = type - p;
		if(type <= 0)
		{
			//Скелета-обезьяну
			LEnc_MonstersLoginObject.current = "mummy";
			modelInfo.model = "mummy";
			modelInfo.ani = "man";
			return true;
		}
	}
	p = stf(LEnc_MonstersLoginObject.vagabond);
	if(p > 0.0)
	{
		type = type - p;
		if(type <= 0)
		{
			//Олуха
			if(rand(100) > 20) return false;
			LEnc_MonstersLoginObject.current = "vagabond";
			if(rand(100) < 70)
			{
				//Man
				modelInfo.ani = "man";
				LEnc_MonstersLoginObject.current.sex = "man";
				switch(rand(16))
				{
				case 0:
					modelInfo.model = "chameleon";
					break;
				case 1:
					modelInfo.model = "chelovek";
					break;
				case 2:
					modelInfo.model = "chelovek1";
					break;
				case 3:
					modelInfo.model = "brodyaga";
					break;
				case 4:
					modelInfo.model = "fisherman";
					break;
				case 5:
					modelInfo.model = "fisherman1";
					break;
				case 6:
					modelInfo.model = "man4";
					break;
				case 7:
					modelInfo.model = "man5";
					break;
				case 8:
					modelInfo.model = "man5_1";
					break;
				case 9:
					modelInfo.model = "pirat2";
					break;
				case 10:
					modelInfo.model = "pirat7";
					break;
				case 11:
					modelInfo.model = "pirat8";
					break;
				case 12:
					modelInfo.model = "old_man2";
					break;
				case 13:
					modelInfo.model = "sailor1";
					break;
				case 14:
					modelInfo.model = "sailor2";
					break;
				case 15:
					modelInfo.model = "sailor5";
					break;
				case 16:
					modelInfo.model = "sailor6";
					break;
				}
			}else{
				//Woman
				modelInfo.ani = "woman";
				LEnc_MonstersLoginObject.current.sex = "woman";
				switch(rand(8))
				{
				case 0:
					modelInfo.model = "towngirl1";
					break;
				case 1:
					modelInfo.model = "towngirl1_1";
					break;
				case 2:
					modelInfo.model = "towngirl2";
					break;
				case 3:
					modelInfo.model = "towngirl2_1";
					break;
				case 4:
					modelInfo.model = "towngirl3";
					break;
				case 5:
					modelInfo.model = "towngirl3_1";
					break;
				case 6:
					modelInfo.model = "towngirl5";
					break;
				case 7:
					modelInfo.model = "towngirl6";
					break;
				case 8:
					modelInfo.model = "towngirl7";
					break;
				}
			}
			return true;
		}
	}
	//Никого
	return false;
}
コード例 #17
0
ファイル: ScreenCalibrator.cpp プロジェクト: jrevote/Vrui
ScreenCalibrator::ScreenCalibrator(int& argc,char**& argv,char**& appDefaults)
	:Vrui::Application(argc,argv,appDefaults),
	 trackingPointsMover(0)
	{
	/* Create and register the point query tool class: */
	PointQueryToolFactory* pointQueryToolFactory=new PointQueryToolFactory("PointQueryTool","Point Query",0,*Vrui::getToolManager());
	pointQueryToolFactory->setNumButtons(1);
	pointQueryToolFactory->setButtonFunction(0,"Query Point");
	Vrui::getToolManager()->addClass(pointQueryToolFactory,Vrui::ToolManager::defaultToolFactoryDestructor);
	
	/* Parse the command line: */
	const char* optitrackFileName=0;
	bool optitrackFlipZ=false;
	const char* totalstationFileName=0;
	int screenPixelSize[2]={-1,-1};
	int screenSquareSize=200;
	double unitScale=1.0;
	for(int i=1;i<argc;++i)
		{
		if(argv[i][0]=='-')
			{
			if(strcasecmp(argv[i]+1,"screenSize")==0)
				{
				for(int j=0;j<2;++j)
					{
					++i;
					screenPixelSize[j]=atoi(argv[i]);
					}
				}
			else if(strcasecmp(argv[i]+1,"squareSize")==0)
				{
				++i;
				screenSquareSize=atoi(argv[i]);
				}
			else if(strcasecmp(argv[i]+1,"metersToInches")==0)
				unitScale=1000.0/25.4;
			else if(strcasecmp(argv[i]+1,"unitScale")==0)
				{
				++i;
				unitScale=atof(argv[i]);
				}
			else if(strcasecmp(argv[i]+1,"flipZ")==0)
				optitrackFlipZ=true;
			else
				{
				}
			}
		else if(totalstationFileName==0)
			totalstationFileName=argv[i];
		else if(optitrackFileName==0)
			optitrackFileName=argv[i];
		else
			{
			}
		}
	
	/* Read the Optitrack sample file: */
	if(optitrackFileName!=0)
		{
		readOptitrackSampleFile(optitrackFileName,optitrackFlipZ);
		std::cout<<"Read "<<trackingPoints.size()<<" ball points from Optitrack sample file"<<std::endl;
		}
	
	/* Read relevant point classes from the Totalstation survey file: */
	if(totalstationFileName!=0)
		{
		screenPoints=readTotalstationSurveyFile(totalstationFileName,"SCREEN");
		floorPoints=readTotalstationSurveyFile(totalstationFileName,"FLOOR");
		ballPoints=readTotalstationSurveyFile(totalstationFileName,"BALLS");
		std::cout<<"Read "<<ballPoints.size()<<" ball points from TotalStation survey file"<<std::endl;
		}
	
	/*********************************************************************
	Establish a normalized coordinate system with the floor at the z=0
	plane, the screen in a plane about orthogonal to the y axis, and the
	screen center above the origin.
	*********************************************************************/
	
	/* Fit a plane to the floor points: */
	Geometry::PCACalculator<3> floorPca;
	for(PointList::const_iterator fpIt=floorPoints.begin();fpIt!=floorPoints.end();++fpIt)
		floorPca.accumulatePoint(*fpIt);
	Point floorCentroid=floorPca.calcCentroid();
	floorPca.calcCovariance();
	double floorEv[3];
	floorPca.calcEigenvalues(floorEv);
	Geometry::PCACalculator<3>::Vector floorNormal=floorPca.calcEigenvector(floorEv[2]);
	
	/* Fit a plane to the screen points: */
	Geometry::PCACalculator<3> screenPca;
	for(PointList::const_iterator spIt=screenPoints.begin();spIt!=screenPoints.end();++spIt)
		screenPca.accumulatePoint(*spIt);
	Point screenCentroid=screenPca.calcCentroid();
	screenPca.calcCovariance();
	double screenEv[3];
	screenPca.calcEigenvalues(screenEv);
	Geometry::PCACalculator<3>::Vector screenNormal=screenPca.calcEigenvector(screenEv[2]);
	
	/* Flip the floor normal such that it points towards the screen points: */
	if((screenCentroid-floorCentroid)*floorNormal<Scalar(0))
		floorNormal=-floorNormal;
	
	/* Flip the screen normal such that it points away from the ball points: */
	Point::AffineCombiner ballC;
	for(PointList::const_iterator bpIt=ballPoints.begin();bpIt!=ballPoints.end();++bpIt)
		ballC.addPoint(*bpIt);
	if((ballC.getPoint()-screenCentroid)*screenNormal>Scalar(0))
		screenNormal=-screenNormal;
	
	/* Project the screen centroid onto the floor plane to get the coordinate system origin: */
	Point origin=screenCentroid-floorNormal*(((screenCentroid-floorCentroid)*floorNormal)/Geometry::sqr(floorNormal));
	
	/* Orthonormalize the screen normal against the floor normal: */
	Vector y=screenNormal-floorNormal*((screenNormal*floorNormal)/Geometry::sqr(floorNormal));
	Vector x=Geometry::cross(y,floorNormal);
	
	#if 0
	/* Calculate a rotation to align the floor normal with +z and the (horizontal) screen normal with +y: */
	ONTransform::Rotation rot=ONTransform::Rotation::fromBaseVectors(x,y);
	#endif
	
	/*********************************************************************
	Calculate a transformation to move the Totalstation survey points into
	the normalized coordinate system:
	*********************************************************************/
	
	ONTransform transform(origin-Point::origin,ONTransform::Rotation::fromBaseVectors(x,y));
	transform.doInvert();
	
	/* Transform all survey points: */
	for(PointList::iterator spIt=screenPoints.begin();spIt!=screenPoints.end();++spIt)
		*spIt=transform.transform(*spIt);
	for(PointList::iterator fpIt=floorPoints.begin();fpIt!=floorPoints.end();++fpIt)
		*fpIt=transform.transform(*fpIt);
	for(PointList::iterator bpIt=ballPoints.begin();bpIt!=ballPoints.end();++bpIt)
		*bpIt=transform.transform(*bpIt);
	
	if(screenPixelSize[0]>0&&screenPixelSize[1]>0&&screenSquareSize>0)
		{
		/*********************************************************************
		Calculate the optimal projective transformation and screen
		transformation (orthonormal transformation plus non-uniform scaling in
		x and y) from theoretical  screen points to surveyed screen points:
		*********************************************************************/
		
		/* Create a list of theoretical screen points: */
		PointList screen;
		int screenPixelOffset[2];
		for(int i=0;i<2;++i)
			screenPixelOffset[i]=((screenPixelSize[i]-1)%screenSquareSize)/2;
		for(int y=screenPixelOffset[1];y<screenPixelSize[1];y+=screenSquareSize)
			for(int x=screenPixelOffset[0];x<screenPixelSize[0];x+=screenSquareSize)
				screen.push_back(Point((Scalar(x)+Scalar(0.5))/Scalar(screenPixelSize[0]),Scalar(1)-(Scalar(y)+Scalar(0.5))/Scalar(screenPixelSize[1]),0));
		if(screen.size()!=screenPoints.size())
			Misc::throwStdErr("Wrong number of screen points, got %d instead of %d",int(screenPoints.size()),int(screen.size()));
		
		/* Find the best-fitting projective transformation for the measured screen points: */
		PTransformFitter ptf(screen.size(),&screen[0],&screenPoints[0]);
		PTransformFitter::Scalar screenResult2=LevenbergMarquardtMinimizer<PTransformFitter>::minimize(ptf);
		std::cout<<"Projective transformation fitting final distance: "<<screenResult2<<std::endl;
		pScreenTransform=ptf.getTransform();
		
		/* Print the screen transformation matrix: */
		std::cout<<"Projective transformation matrix:"<<std::endl;
		std::cout<<std::setprecision(6)<<pScreenTransform<<std::endl;
		
		/* Find the best-fitting screen transformation for the measured screen points: */
		ScreenTransformFitter stf(screen.size(),&screen[0],&screenPoints[0]);
		ScreenTransformFitter::Scalar screenResult1=LevenbergMarquardtMinimizer<ScreenTransformFitter>::minimize(stf);
		std::cout<<"Screen transformation fitting final distance: "<<screenResult1<<std::endl;
		screenTransform=stf.getTransform();
		screenSize[0]=stf.getSize(0);
		screenSize[1]=stf.getSize(1);
		std::cout<<"Optimal screen size: "<<screenSize[0]<<", "<<screenSize[1]<<std::endl;
		std::cout<<"Optimal screen origin: "<<screenTransform.getOrigin()<<std::endl;
		std::cout<<"Optimal horizontal screen axis: "<<screenTransform.getDirection(0)<<std::endl;
		std::cout<<"Optimal vertical screen axis: "<<screenTransform.getDirection(1)<<std::endl;
		
		/*********************************************************************
		Calculate a homography matrix from the optimal screen transformation
		to the optimal projective transformation to correct screen
		misalignments:
		*********************************************************************/
		
		Point sCorners[4];
		Point pCorners[4];
		for(int i=0;i<4;++i)
			{
			sCorners[i][0]=i&0x1?screenSize[0]*unitScale:0.0;
			sCorners[i][1]=i&0x2?screenSize[1]*unitScale:0.0;
			sCorners[i][2]=0.0;
			pCorners[i][0]=i&0x1?1.0:0.0;
			pCorners[i][1]=i&0x2?1.0:0.0;
			pCorners[i][2]=0.0;
			pCorners[i]=screenTransform.inverseTransform(pScreenTransform.transform(pCorners[i]));
			pCorners[i][0]*=unitScale;
			pCorners[i][1]*=unitScale;
			}
		Geometry::ProjectiveTransformation<double,2> sHom=calcHomography(sCorners);
		Geometry::ProjectiveTransformation<double,2> pHom=calcHomography(pCorners);
		Geometry::ProjectiveTransformation<double,2> hom=pHom;
		hom.leftMultiply(Geometry::invert(sHom));
		for(int i=0;i<3;++i)
			for(int j=0;j<3;++j)
				hom.getMatrix()(i,j)/=hom.getMatrix()(2,2);
		
		#if 0
		std::cout<<"Homography matrix for projective transform: "<<pHom<<std::endl;
		std::cout<<"Homography matrix for screen transform: "<<sHom<<std::endl;
		std::cout<<"Screen correction homography matrix: "<<hom<<std::endl;
		#endif
		
		#if 0
		
		/* Do some experiments: */
		Geometry::ProjectiveTransformation<double,3> hom3=Geometry::ProjectiveTransformation<double,3>::identity;
		for(int i=0;i<3;++i)
			for(int j=0;j<3;++j)
				hom3.getMatrix()(i<2?i:3,j<2?j:3)=hom.getMatrix()(i,j);
		hom3.getMatrix()(2,0)=hom3.getMatrix()(3,0);
		hom3.getMatrix()(2,1)=hom3.getMatrix()(3,1);
		
		std::cout<<hom3<<std::endl;
		std::cout<<Geometry::invert(hom3)<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>(-1.0,-1.0,-1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>( 1.0,-1.0,-1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>(-1.0, 1.0,-1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>( 1.0, 1.0,-1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>(-1.0,-1.0, 1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>( 1.0,-1.0, 1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>(-1.0, 1.0, 1.0,1.0)).toPoint()<<std::endl;
		std::cout<<hom3.transform(Geometry::HVector<double,3>( 1.0, 1.0, 1.0,1.0)).toPoint()<<std::endl;
		
		#endif
		
		/* Print a configuration file section for the screen: */
		std::cout<<std::endl<<"Configuration settings for screen:"<<std::endl;
		std::cout<<"origin "<<screenTransform.getTranslation()*unitScale<<std::endl;
		std::cout<<"horizontalAxis "<<screenTransform.getDirection(0)<<std::endl;
		std::cout<<"width "<<screenSize[0]*unitScale<<std::endl;
		std::cout<<"verticalAxis "<<screenTransform.getDirection(1)<<std::endl;
		std::cout<<"height "<<screenSize[1]*unitScale<<std::endl;
		std::cout<<"offAxis true"<<std::endl;
		std::cout<<"homography ( ";
		for(int j=0;j<3;++j)
			{
			if(j>0)
				std::cout<<", \\"<<std::endl<<"             ";
			std::cout<<"( ";
			for(int i=0;i<3;++i)
				{
				if(i>0)
					std::cout<<", ";
				std::cout<<pHom.getMatrix()(i,j);
				}
			std::cout<<" )";
			}
		std::cout<<" )"<<std::endl;
		std::cout<<std::endl;
		}
	
	if(optitrackFileName!=0&&totalstationFileName!=0)
		{
		/*********************************************************************
		Calculate the optimal orthonormal transformation from tracking system
		coordinates to the normalized coordinate system by aligning ball
		positions observed by the tracking system with ball positions measured
		using the total station:
		*********************************************************************/
		
		/* Find an orthonormal transformation to align the tracking points with the ball points: */
		size_t numPoints=trackingPoints.size();
		if(numPoints>ballPoints.size())
			numPoints=ballPoints.size();
		
		/* Calculate the centroid of the tracking points: */
		Point::AffineCombiner tpCc;
		for(size_t i=0;i<numPoints;++i)
			tpCc.addPoint(trackingPoints[i]);
		Vector tpTranslation=tpCc.getPoint()-Point::origin;
		for(size_t i=0;i<numPoints;++i)
			trackingPoints[i]-=tpTranslation;
		ONTransformFitter ontf(numPoints,&trackingPoints[0],&ballPoints[0]);
		//ontf.setTransform(ONTransformFitter::Transform::rotate(ONTransformFitter::Transform::Rotation::rotateX(Math::rad(Scalar(90)))));
		ONTransformFitter::Scalar result=LevenbergMarquardtMinimizer<ONTransformFitter>::minimize(ontf);
		ONTransform tsCal=ontf.getTransform();
		tsCal*=ONTransform::translate(-tpTranslation);
		
		std::cout<<"Final distance: "<<result<<std::endl;
		std::cout<<"Tracking system calibration transformation: "<<tsCal<<std::endl;
		
		std::cout<<"Configuration settings for tracking calibrator: "<<std::endl;
		std::cout<<"transformation translate "<<tsCal.getTranslation()*unitScale<<" \\"<<std::endl;
		std::cout<<"               * scale "<<unitScale<<" \\"<<std::endl;
		std::cout<<"               * rotate "<<tsCal.getRotation().getAxis()<<", "<<Math::deg(tsCal.getRotation().getAngle())<<std::endl;
		
		/* Transform the tracking points with the result transformation: */
		for(PointList::iterator tpIt=trackingPoints.begin();tpIt!=trackingPoints.end();++tpIt)
			*tpIt=tsCal.transform(*tpIt+tpTranslation);
		}
	
	/* Initialize the navigation transformation: */
	Geometry::Box<Scalar,3> bbox=Geometry::Box<Scalar,3>::empty;
	for(PointList::const_iterator tpIt=trackingPoints.begin();tpIt!=trackingPoints.end();++tpIt)
		bbox.addPoint(*tpIt);
	for(PointList::const_iterator spIt=screenPoints.begin();spIt!=screenPoints.end();++spIt)
		bbox.addPoint(*spIt);
	for(PointList::const_iterator fpIt=floorPoints.begin();fpIt!=floorPoints.end();++fpIt)
		bbox.addPoint(*fpIt);
	for(PointList::const_iterator bpIt=ballPoints.begin();bpIt!=ballPoints.end();++bpIt)
		bbox.addPoint(*bpIt);
	
	Vrui::setNavigationTransformation(Geometry::mid(bbox.min,bbox.max),Geometry::dist(bbox.min,bbox.max));
	
	/* Create a virtual input device to move the tracking points interactively: */
	trackingPointsMover=Vrui::addVirtualInputDevice("TrackingPointsMover",0,0);
	// Vrui::getInputGraphManager()->setNavigational(trackingPointsMover,true);
	Vrui::NavTrackerState scaledDeviceT=Vrui::getInverseNavigationTransformation();
	scaledDeviceT*=trackingPointsMover->getTransformation();
	trackingPointsTransform=Vrui::TrackerState(scaledDeviceT.getTranslation(),scaledDeviceT.getRotation());
	trackingPointsTransform.doInvert();
	}
コード例 #18
0
// dopasowuje napisy do pliku z filmem
bool QNapiAbstractEngine::match()
{
    QFileInfo stf(subtitlesTmp);

    if(!stf.exists())
        return false;

    QString targetExtension = stf.suffix();

    if(!GlobalConfig().ppSubFormat().isEmpty() && GlobalConfig().ppSubExtension().isEmpty())
    {
        targetExtension = GlobalFormatsRegistry().select(GlobalConfig().ppSubFormat())->defaultExtension();
    }
    else if(!GlobalConfig().ppSubExtension().isEmpty())
    {
        targetExtension = GlobalConfig().ppSubExtension();
    }

    QFileInfo mf(movie);

    subtitles = mf.path() + "/" + mf.completeBaseName() + "." + targetExtension;

    QFileInfo sf(subtitles);

    if(!QFileInfo(sf.absolutePath()).isWritable())
        return false;

    if(QFile::exists(subtitles))
    {
        if(!noBackup)
        {
            QString newName = mf.path() + QDir::separator() + mf.completeBaseName() + "_kopia." + sf.suffix();

            if(QFile::exists(newName))
                QFile::remove(newName);

            QFile::rename(subtitles, newName);          
        }
        else
            QFile::remove(subtitles);
    }

    bool r = false;

#ifdef Q_OS_WIN
    // Pod windowsem, aby "wyczyscic" atrybuty pliku, tworzymy go na nowo
    QFile f(subtitles), f2(subtitlesTmp);
    if(!f.open(QIODevice::WriteOnly) || !f2.open(QIODevice::ReadOnly))
    {
        f.close();
    }
    else
    {
        r = f.write(f2.readAll()) > 0;
        f2.close();
        f.close();
    }
#else
    // pod normalnymi OS-ami nie trzeba sie gimnastykowac z atrybutami
    r = QFile::copy(subtitlesTmp, subtitles);

    // Zmiana uprawnien do pliku
    if(GlobalConfig().changePermissions())
    {
        bool validPermissions;
        int permInt = GlobalConfig().changePermissionsTo().toInt(&validPermissions, 8);

        if(validPermissions)
        {
            int perm = 0;
            perm |= (permInt & 0700) << 2;
            perm |= (permInt & 0070) << 1;
            perm |= (permInt & 0007);
            changeSubtitlesPermissions(QFile::Permissions(perm));
        }
    }
#endif

    return r;
}