Esempio n. 1
0
int32_t C4Effect::Check(C4Object *pForObj, const char *szCheckEffect,
                        int32_t iPrio, int32_t iTimer, C4Value &rVal1,
                        C4Value &rVal2, C4Value &rVal3, C4Value &rVal4) {
  // priority=1: always OK; no callbacks
  if (iPrio == 1)
    return 0;
  // check this and other effects
  C4Effect *pAddToEffect = NULL;
  bool fDoTempCallsForAdd = false;
  C4Effect *pLastRemovedEffect = NULL;
  for (C4Effect *pCheck = this; pCheck; pCheck = pCheck->pNext) {
    if (!pCheck->IsDead() && pCheck->pFnEffect && pCheck->iPriority >= iPrio) {
      int32_t iResult =
          pCheck->pFnEffect->Exec(pCheck->pCommandTarget,
                                  &C4AulParSet(C4VString(szCheckEffect),
                                               C4VObj(pForObj),
                                               C4VInt(pCheck->iNumber),
                                               C4Value(), rVal1, rVal2, rVal3,
                                               rVal4)).getInt();
      if (iResult == C4Fx_Effect_Deny)
        // effect denied
        return C4Fx_Effect_Deny;
      // add to other effect
      if (iResult == C4Fx_Effect_Annul || iResult == C4Fx_Effect_AnnulCalls) {
        pAddToEffect = pCheck;
        fDoTempCallsForAdd = (iResult == C4Fx_Effect_AnnulCalls);
      }
    }
  }
  // adding to other effect?
  if (pAddToEffect) {
    // do temp remove calls if desired
    if (pAddToEffect->pNext && fDoTempCallsForAdd)
      pAddToEffect->TempRemoveUpperEffects(pForObj, false, &pLastRemovedEffect);
    C4Value Par1 = C4VString(szCheckEffect), Par2 = C4VInt(iTimer), Par8;
    int32_t iResult =
        pAddToEffect->DoCall(pForObj, PSFS_FxAdd, Par1, Par2, rVal1, rVal2,
                             rVal3, rVal4, Par8).getInt();
    // do temp readd calls if desired
    if (pAddToEffect->pNext && fDoTempCallsForAdd)
      pAddToEffect->TempReaddUpperEffects(pForObj, pLastRemovedEffect);
    // effect removed by this call?
    if (iResult == C4Fx_Start_Deny) {
      pAddToEffect->Kill(pForObj);
      return C4Fx_Effect_Annul;
    } else
      // other effect is the target effect number
      return pAddToEffect->iNumber;
  }
  // added to no effect and not denied
  return 0;
}
Esempio n. 2
0
C4ValueArray * C4Effect::GetProperties() const
{
	C4ValueArray * a = C4PropList::GetProperties();
	int i;
	i = a->GetSize();
	a->SetSize(i + 5);
	(*a)[i++] = C4VString(&::Strings.P[P_Name]);
	(*a)[i++] = C4VString(&::Strings.P[P_Priority]);
	(*a)[i++] = C4VString(&::Strings.P[P_Interval]);
	(*a)[i++] = C4VString(&::Strings.P[P_CommandTarget]);
	(*a)[i++] = C4VString(&::Strings.P[P_Time]);
	return a;
}
void C4ConsoleQtLocalizeStringDlg::done(int r)
{
	if (QDialog::Accepted == r)  // ok was pressed
	{
		C4PropList *translations_proplist = translations.getPropList();
		assert(translations_proplist);
		// Set all translations
		for (const auto & langs : edited_languages)
		{
			// Empty strings are set to nil, because that allows the user to set it to fallback
			QString text = langs.value_editor->text();
			if (text.length())
			{
				C4Value text_val = C4VString(text.toUtf8());
				translations_proplist->SetPropertyByS(::Strings.RegString(langs.language), text_val);
			}
			else
			{
				translations_proplist->ResetProperty(::Strings.RegString(langs.language));
			}
		}
	}
	// Close
	QDialog::done(r);
}
Esempio n. 4
0
C4ValueArray * C4PropList::GetProperties() const
{
	C4ValueArray * a;
	int i;
	if (GetPrototype())
	{
		a = GetPrototype()->GetProperties();
		i = a->GetSize();
		a->SetSize(i + Properties.GetSize());
	}
	else
	{
		a = new C4ValueArray(Properties.GetSize());
		i = 0;
	}
	const C4Property * p = Properties.First();
	while (p)
	{
		assert(p->Key != nullptr && "Proplist key is nullpointer");
		(*a)[i++] = C4VString(p->Key);
		assert(((*a)[i - 1].GetType() == C4V_String) && "Proplist key is non-string");
		p = Properties.Next(p);
	}
	return a;
}
Esempio n. 5
0
void C4PhysicalInfo::PromotionUpdate(int32_t iRank, bool fUpdateTrainablePhysicals, C4Def *pTrainDef)
	{
#ifdef C4ENGINE
	if (iRank>=0) { CanDig=1; CanChop=1; CanConstruct=1; }
	if (iRank>=0) { CanScale=1; }
	if (iRank>=0) { CanHangle=1; }
	Energy= Max<int32_t>( Energy, (50+5*BoundBy<int32_t>(iRank,0,10)) *C4MaxPhysical/100 );
	if (fUpdateTrainablePhysicals && pTrainDef)
		{
		// do standard training: Expect everything to be trained fully at rank 20
		int32_t iTrainRank = BoundBy<int32_t>(iRank, 0,20);
		Scale = pTrainDef->Physical.Scale + (C4MaxPhysical - pTrainDef->Physical.Scale) * iTrainRank / 20;
		Hangle = pTrainDef->Physical.Hangle + (C4MaxPhysical - pTrainDef->Physical.Hangle) * iTrainRank / 20;
		Swim = pTrainDef->Physical.Swim + (C4MaxPhysical - pTrainDef->Physical.Swim) * iTrainRank / 20;
		Fight = pTrainDef->Physical.Fight + (C4MaxPhysical - pTrainDef->Physical.Fight) * iTrainRank / 20;
		// do script updates for any physicals as required (this will train stuff like magic)
		const char *szPhysName; C4PhysicalInfo::Offset PhysOff;
		for (int32_t iPhysIdx=0; szPhysName = GetNameByIndex(iPhysIdx, &PhysOff); ++iPhysIdx)
			{
			C4Value PhysVal(this->*PhysOff, C4V_Int);
			C4AulParSet Pars(C4VString(szPhysName), C4VInt(iRank), C4VRef(&PhysVal));
			if (!!pTrainDef->Script.Call(PSF_GetFairCrewPhysical, &Pars))
				{
				this->*PhysOff = PhysVal.getInt();
				}
			}
		}
#endif
	}
Esempio n. 6
0
void C4PropList::SetName(const char* NewName)
{
	if (!NewName)
		ResetProperty(&Strings.P[P_Name]);
	else
	{
		SetProperty(P_Name, C4VString(NewName));
	}
}
Esempio n. 7
0
C4Effect::C4Effect(C4Effect **ppEffectList, C4PropList * prototype, int32_t iPrio, int32_t iTimerInterval):
		C4PropListNumbered(prototype)
{
	// assign values
	iPriority = 0; // effect is not yet valid; some callbacks to other effects are done before
	iInterval = iTimerInterval;
	iTime = 0;
	CommandTarget.Set0();
	AcquireNumber();
	Register(ppEffectList, iPrio);
	SetProperty(P_Name, C4VString(prototype->GetName()));
}
Esempio n. 8
0
C4Effect::C4Effect(C4Effect **ppEffectList, C4String *szName, int32_t iPrio, int32_t iTimerInterval, C4PropList *pCmdTarget)
{
	// assign values
	iPriority = 0; // effect is not yet valid; some callbacks to other effects are done before
	iInterval = iTimerInterval;
	iTime = 0;
	CommandTarget.SetPropList(pCmdTarget);
	AcquireNumber();
	Register(ppEffectList, iPrio);
	// Set name and callback functions
	SetProperty(P_Name, C4VString(szName));
}
Esempio n. 9
0
C4Effect::C4Effect(C4Object *pForObj, C4String *szName, int32_t iPrio, int32_t iTimerInterval, C4Object *pCmdTarget, C4ID idCmdTarget, const C4Value &rVal1, const C4Value &rVal2, const C4Value &rVal3, const C4Value &rVal4)
{
	// assign values
	iPriority = 0; // effect is not yet valid; some callbacks to other effects are done before
	iInterval = iTimerInterval;
	iTime = 0;
	CommandTarget = pCmdTarget;
	idCommandTarget = idCmdTarget;
	AcquireNumber();
	Register(pForObj, iPrio);
	// Set name and callback functions
	SetProperty(P_Name, C4VString(szName));
}
Esempio n. 10
0
TEST_F(AulTest, ValueReturn)
{
	// Make sure primitive value returns work.
	EXPECT_EQ(C4VNull, RunCode("return;"));
	EXPECT_EQ(C4VNull, RunExpr("nil"));
	EXPECT_EQ(C4Value(true), RunExpr("true"));
	EXPECT_EQ(C4Value(false), RunExpr("false"));
	EXPECT_EQ(C4VInt(42), RunExpr("42"));
	EXPECT_EQ(C4VString("Hello World!"), RunExpr("\"Hello World!\""));

	// Make sure array returns work.
	EXPECT_EQ(C4VArray(), RunExpr("[]"));
	EXPECT_EQ(
		C4VArray(C4VInt(0), C4VNull, C4VArray(C4VInt(1)), C4VString("Hi")),
		RunExpr("[0, nil, [1], \"Hi\"]"));

	// Make sure proplist returns work.
	EXPECT_EQ(C4VPropList(), RunExpr("{}"));
	EXPECT_EQ(
		C4VPropList("a", C4VInt(1), "b", C4VArray()),
		RunExpr("{\"a\": 1, \"b\"=[]}"));
}