Exemple #1
0
//---------------------------------------------------------------------------
void __fastcall TForm21::TntButton1Click(TObject *Sender)
{
  TTextValue xPos;
  TTextValue yPos;
  xPos.Value = MakeFloat(Edit1);
  yPos.Value = MakeFloat(Edit2);
  xPos.Text = ToWString(Edit1->Text);
  yPos.Text = ToWString(Edit2->Text);

  int Index = ComboBox1->ItemIndex;
  if(Index == -1)
    Index = 0;

  boost::shared_ptr<TTextLabel> NewLabel(new TTextLabel(
    Label->GetText(),
    IndexToPlacement[Index],
    xPos,
    yPos,
    Label->GetBackgroundColor(),
    Label->GetRotation(),
    Label->GetOleLink()
  ));
  UndoList.Push(TUndoChange(Label, NewLabel));
  Data.Replace(Label, NewLabel);
  NewLabel->Update();
  ModalResult = mrOk;
}
Exemple #2
0
// Make a vector constant, which is a struct containing a float array.
// Note: this must agree with the definition of OpVec3.
llvm::Constant* 
CgConst::MakeVector(const float* data, unsigned int length) const
{
    std::vector<llvm::Constant*> members(3);
    members[0] = MakeFloat(data[0]);
    members[1] = MakeFloat(data[1]);
    members[2] = MakeFloat(data[2]);
    llvm::StructType* vecTy = llvm::dyn_cast<llvm::StructType>(mTypes->GetVecTy());
    assert(vecTy != NULL && "Expected vector type to be an llvm::StructType");
    return llvm::ConstantStruct::get(vecTy, llvm::ArrayRef<llvm::Constant*>(members));
}
Exemple #3
0
static LispObject ToDeg(LispObject args)
{
    double r;
    
    CHECK_NUMBER(args);
    r = GET_NUMBER(args);
    r = 180.0 / M_PI * r;
    return MakeFloat(r);
}
Exemple #4
0
static LispObject ToRad(LispObject args)
{
    double r;
    
    CHECK_NUMBER(args);
    r = GET_NUMBER(args);
    r = M_PI / 180.0 * r;
    return MakeFloat(r);
}
Exemple #5
0
/* New time medition functions */
static CBOOL__PROTO(generic_tick,
		    inttime_t (*time_function)(void),
		    inttime_t starttick,
		    inttime_t *lasttick)
{
  /*int st,lt; */
  inttime_t st,lt;
  inttime_t t;
  tagged_t x;
  
  t = time_function();
  st = t - starttick;
  lt = t - *lasttick;
  *lasttick = t;
  /* while ciao does not support inttime_t, lt and st must be cast to
    flt64_t */
  MakeLST(x,MakeFloat(Arg,(flt64_t)lt),atom_nil);
  MakeLST(x,MakeFloat(Arg,(flt64_t)st),x);
  return cunify(Arg,x,X(0));  
}
Exemple #6
0
static LispObject Abs(LispObject args)
{
    CHECK_NUMBER(args);
    if (FLOATP(args)) {
	double r = fabs(LFLOAT(args)->value);
	return MakeFloat(r);
    }
    if (INTEGERP(args)) {
	int r = abs(LINTEGER(args));
	return MakeInteger(r);
    }
    return Qnil;
}
Exemple #7
0
Type* Type::Read(Buffer *buf)
{
  uint32_t kind = 0;
  uint32_t width = 0;
  uint32_t count = 0;
  bool sign = false;
  bool varargs = false;
  String *name = NULL;
  Type *target_type = NULL;
  TypeCSU *csu_type = NULL;
  Vector<Type*> argument_types;

  Try(ReadOpenTag(buf, TAG_Type));
  while (!ReadCloseTag(buf, TAG_Type)) {
    switch (PeekOpenTag(buf)) {
    case TAG_Kind: {
      Try(!kind);
      Try(ReadTagUInt32(buf, TAG_Kind, &kind));
      break;
    }
    case TAG_Width: {
      Try(ReadTagUInt32(buf, TAG_Width, &width));
      break;
    }
    case TAG_Sign: {
      Try(ReadTagEmpty(buf, TAG_Sign));
      sign = true;
      break;
    }
    case TAG_Name: {
      Try(!name);
      Try(kind == YK_CSU);
      name = String::ReadWithTag(buf, TAG_Name);
      break;
    }
    case TAG_Type: {
      Try(!target_type);
      Try(kind == YK_Pointer || kind == YK_Array || kind == YK_Function);
      target_type = Type::Read(buf);
      break;
    }
    case TAG_Count: {
      Try(kind == YK_Array);
      Try(ReadTagUInt32(buf, TAG_Count, &count));
      break;
    }
    case TAG_TypeFunctionCSU: {
      Try(!csu_type);
      Try(ReadOpenTag(buf, TAG_TypeFunctionCSU));
      csu_type = Type::Read(buf)->AsCSU();
      Try(ReadCloseTag(buf, TAG_TypeFunctionCSU));
      break;
    }
    case TAG_TypeFunctionVarArgs: {
      Try(kind == YK_Function);
      Try(ReadTagEmpty(buf, TAG_TypeFunctionVarArgs));
      varargs = true;
      break;
    }
    case TAG_TypeFunctionArguments: {
      Try(kind == YK_Function);
      Try(argument_types.Empty());
      Try(ReadOpenTag(buf, TAG_TypeFunctionArguments));
      while (!ReadCloseTag(buf, TAG_TypeFunctionArguments)) {
        Type *ntype = Type::Read(buf);
        argument_types.PushBack(ntype);
      }
      break;
    }
    default:
      Try(false);
    }
  }

  switch ((TypeKind)kind) {
  case YK_Error:
    return MakeError();
  case YK_Void:
    return MakeVoid();
  case YK_Int:
    return MakeInt(width, sign);
  case YK_Float:
    return MakeFloat(width);
  case YK_Pointer:
    Try(target_type);
    return MakePointer(target_type, width);
  case YK_Array:
    Try(target_type);
    return MakeArray(target_type, count);
  case YK_CSU:
    Try(name);
    return MakeCSU(name);
  case YK_Function:
    Try(target_type);
    return MakeFunction(target_type, csu_type, varargs, argument_types);
  default:
    Try(false);
  }
}
Exemple #8
0
// 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);
	}		
}      	
Exemple #9
0
// Set task attack for SeaAI 
void AIAttack_GroupAttack(string sGroupAttacker, string sGroupAttacked, bool bAttackedTask)
{
	ref rG1 = Group_GetGroupByID(sGroupAttacker);
	ref rG2 = Group_GetGroupByID(sGroupAttacked);

	float fHP1 = Group_GetPowerHP_R(rG1);
	float fHP2 = Group_GetPowerHP_R(rG2);

	float fHPRatio1 = fHP1 / (fHP2 + 0.0001);
	float fHPRatio2 = fHP2 / (fHP1 + 0.0001);

	ref rCharacter1 = Group_GetGroupCommanderR(rG1);
	ref rCharacter2 = Group_GetGroupCommanderR(rG2);

	string sGroupType1 = Group_GetTypeR(rG1);
	string sGroupType2 = Group_GetTypeR(rG2);

	int iNation1 = sti(rCharacter1.nation);
	int iNation2 = sti(rCharacter2.nation);

	SetCharacterRelationBoth(sti(rCharacter1.index), sti(rCharacter2.index), RELATION_ENEMY);

	// check for already attack
	if (sti(rG1.Task) == AITASK_ATTACK)
	{
		if (rG1.Task.Target != sGroupAttacked) { return; }
		//return;
	}

	// ====================================================== set attack task to ships
	if (sGroupAttacker != PLAYER_GROUP)
	{
		int iIndex = 0;

		int iCharactersNum2 = Group_GetCharactersNumR(rG2);
		int iDeadCharactersNum2 = Group_GetDeadCharactersNumR(rG2);
		
		// find targets for rG1
		if (iCharactersNum2 != iDeadCharactersNum2 && iCharactersNum2 > 0)
		{
			int i = 0;
			while (true)
			{
				int iCharacterIndex = Group_GetCharacterIndexR(rG1, i); i++;
				if (iCharacterIndex < 0) { break; }
				SetCharacterRelationBoth(sti(rCharacter2.index), iCharacterIndex, RELATION_ENEMY);
				if (LAi_IsDead(&Characters[iCharacterIndex])) { 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);
			}	
		}
	}
	// ====================================================== set attack task to ships
	bool bTaskLock = false;

	if (sGroupAttacked == PLAYER_GROUP) { return; }
	if (!bAttackedTask) { return; } 
	if (Group_isTaskLockR(rG2)) 
	{ 
		if (sti(rG2.Task) != AITASK_ATTACK) { return; }
		if (rG2.Task.Target != sGroupAttacker) { return; }

		bTaskLock = true;
	}

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

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

	int iTask = AITASK_ATTACK;
	if (!bTaskLock) iTask = AIAttack_SelectTask(sGroupType2, fTmp);
	switch (iTask)
	{
		case AITASK_ATTACK:
			Group_SetTaskAttackEx(sGroupAttacked, sGroupAttacker, false);
		break;
		case AITASK_RUNAWAY:
			Group_SetTaskRunaway(sGroupAttacked);
		break;
	}
}
Exemple #10
0
/* New time medition functions */
inline static CBOOL__PROTO(generic_clockfreq, inttime_t clockfreq)
{
  /* while ciao not support inttime_t, return value must be cast to
    flt64_t */
  return cunify(Arg,MakeFloat(Arg,(flt64_t)clockfreq),X(0));
}