Esempio n. 1
0
int DarkMoonEngine::charSelectDialogue() {
	int cnt = 0;
	const char *namesList[7];
	memset(namesList, 0, 7 * sizeof(const char *));

	for (int i = 0; i < 6; i++) {
		if (!testCharacter(i, 3))
			continue;
		namesList[cnt++] = _characters[i].name;
	}

	namesList[cnt++] = _abortStrings[0];

	int r = runDialogue(-1, 7, namesList[0], namesList[1], namesList[2], namesList[3], namesList[4], namesList[5], namesList[6]) - 1;
	if (r == cnt - 1)
		return 99;

	for (cnt = 0; cnt < 6; cnt++) {
		if (!testCharacter(cnt, 3))
			continue;
		if (--r < 0)
			break;
	}
	return cnt;
}
Esempio n. 2
0
static int
isBeginning (void) {
  const wchar_t *ptr = src;

  while (ptr > srcmin) {
    if (!testCharacter(*--ptr, CTC_Punctuation)) {
      if (!testCharacter(*ptr, CTC_Space)) return 0;
      break;
    }
  }

  return 1;
}
Esempio n. 3
0
static int
isEnding (void) {
  const wchar_t *ptr = src + currentFindLength;

  while (ptr < srcmax) {
    if (!testCharacter(*ptr, CTC_Punctuation)) {
      if (!testCharacter(*ptr, CTC_Space)) return 0;
      break;
    }

    ptr += 1;
  }

  return 1;
}
Esempio n. 4
0
void CAdvancedLineEditWidget::update()
{
	const QString _text = text();
	m_currentLength = _text.size();

	bool oldValid = m_valid;
	m_valid = true;

	if (m_currentLength < m_minLength)
	{
		m_valid = false;
	}

	if (m_valid && !_text.isEmpty())
	{
        for (int i = 0; i < m_currentLength; ++i)
		{
            if (!testCharacter(_text[i]))
			{
				m_valid = false;
				break;
			}
		}
	}

	refreshColor();

	if (oldValid != m_valid)
		Q_EMIT validityChanged(m_valid);
}
Esempio n. 5
0
bool TestLua::testWrapper()
{
    LuaState lua;

    Engine::getEngine()->setCurrentGame(new Game());
    Handle<Character> testCharacter(new Character());
    testCharacter->setGameId("testId");
    testCharacter->setName("Test Name");

    lua.loadString("Character = import(\"Character\")\n"
                   "name = \"none\"\n"
                   "function testFunc()\n"
                   "	obj = Character.new(\"testId\")\n"
                   "	name = obj:name()\n"
                   "	obj:name(name..\" changed\")\n"
                   "end");

    string name = lua.getGlobalString("name");
    am_equalsStr("none", name.c_str());

    assert(lua.hasGlobalFunction("testFunc"));
    lua_acall(lua, 0, 0);

    name = lua.getGlobalString("name");
    am_equalsStr("Test Name", name.c_str());

    am_equalsStr("Test Name changed", testCharacter->getName().c_str());

    lua.close();
    return true;
}
Esempio n. 6
0
int main(int argc, char *argv[])
{
    srand(time(NULL));
    testCharacter();
    testString();
    //char *s = inputString();
    //printf("%s\n",s );
    //testme();
    return 0;
}
Esempio n. 7
0
void EoBCoreEngine::removeCharacterEffect(int spell, int charIndex, int showWarning) {
	assert(spell >= 0);
	EoBCharacter *c = &_characters[charIndex];
	EoBSpell *s = &_spells[spell];

	if (showWarning) {
		int od = _screen->curDimIndex();
		Screen::FontId of = _screen->setFont(Screen::FID_6_FNT);
		_screen->setScreenDim(7);
		printWarning(Common::String::format(_magicStrings3[_flags.gameID == GI_EOB1 ? 3 : 2], c->name, s->name).c_str());
		_screen->setScreenDim(od);
		_screen->setFont(of);
	}

	if (s->endCallback)
		(this->*s->endCallback)(c);

	if (s->flags & 1)
		c->effectFlags &= ~s->effectFlags;

	if (s->flags & 4)
		_partyEffectFlags &= ~s->effectFlags;

	if (s->flags & 0x200) {
		for (int i = 0; i < 6; i++) {
			if (!testCharacter(i, 1))
				continue;
			if (!testCharacter(i, 2) && !(s->flags & 0x800))
				continue;
			_characters[i].effectFlags &= ~s->effectFlags;
		}
	}

	if (s->flags & 0x2)
		recalcArmorClass(_activeSpellCharId);

	if (showWarning) {
		if (s->flags & 0x20A0)
			gui_drawCharPortraitWithStats(charIndex);
		else if (s->flags & 0x40)
			gui_drawAllCharPortraitsWithStats();
	}
}
Esempio n. 8
0
static int
putReplace (const ContractionTableRule *rule, wchar_t character) {
  const BYTE *cells = (BYTE *)&rule->findrep[rule->findlen];
  int count = rule->replen;

  if ((prefs.capitalizationMode == CTB_CAP_DOT7) &&
      testCharacter(character, CTC_UpperCase)) {
    if (!putCell(*cells++ | BRL_DOT7)) return 0;
    if (!(count -= 1)) return 1;
  }

  return putCells(cells, count);
}
Esempio n. 9
0
void DarkMoonEngine::restParty_npc() {
	int insalId = -1;
	int numChar = 0;

	for (int i = 0; i < 6; i++) {
		if (!testCharacter(i, 1))
			continue;
		if (testCharacter(i, 2) && _characters[i].portrait == -1)
			insalId = i;
		numChar++;
	}

	if (insalId == -1 || numChar < 5)
		return;

	removeCharacterFromParty(insalId);
	if (insalId < 4)
		exchangeCharacters(insalId, testCharacter(5, 1) ? 5 : 4);

	clearScriptFlags(6);

	if (!stripPartyItems(1, 1, 1, 1))
		stripPartyItems(2, 1, 1, 1);
	stripPartyItems(31, 0, 1, 3);
	stripPartyItems(39, 1, 0, 3);
	stripPartyItems(47, 0, 1, 2);

	_items[createItemOnCurrentBlock(28)].value = 26;

	gui_drawPlayField(false);
	gui_drawAllCharPortraitsWithStats();

	_screen->setClearScreenDim(10);
	_gui->messageDialogue2(11, 63, 6);
	_gui->messageDialogue2(11, 64, 6);
}
Esempio n. 10
0
void CAdvancedLineEditWidget::keyPressEvent(QKeyEvent * pEvent)
{
    if (!pEvent->text().isEmpty() &&
        pEvent->key() != Qt::Key_Backspace &&
        pEvent->key() != Qt::Key_Delete)
	{
        if (!testCharacter(pEvent->text().at(0)) && m_lockDisallowedChars)
			return;
	}

    QLineEdit::keyPressEvent(pEvent);

	testBorders();

	update();
}
Esempio n. 11
0
void EoBCoreEngine::sparkEffectDefensive(int charIndex) {
	int first = charIndex;
	int last = charIndex;
	if (charIndex == -1) {
		first = 0;
		last = 5;
	}

	for (int i = 0; i < 8; i++) {
		for (int ii = first; ii <= last; ii++) {
			if (!testCharacter(ii, 1) || (_currentControlMode && ii != _updateCharNum))
				continue;

			gui_drawCharPortraitWithStats(ii);

			for (int iii = 0; iii < 4; iii++) {
				int shpIndex = ((_sparkEffectDefSteps[i] & _sparkEffectDefSubSteps[iii]) >> _sparkEffectDefShift[iii]);
				if (!shpIndex)
					continue;
				int x = _sparkEffectDefAdd[iii * 2] - 8;
				int y = _sparkEffectDefAdd[iii * 2 + 1];
				if (_currentControlMode) {
					x += 181;
					y += 3;
				} else {
					x += (_sparkEffectDefX[ii] << 3);
					y += _sparkEffectDefY[ii];
				}
				_screen->drawShape(0, _sparkShapes[shpIndex - 1], x, y, 0);
				_screen->updateScreen();
			}
		}
		delay(2 * _tickLength);
	}

	for (int i = first; i < last; i++)
		gui_drawCharPortraitWithStats(i);
}
Esempio n. 12
0
static int
selectRule (int length) {
  int ruleOffset;
  int maximumLength;

  if (length < 1) return 0;
  if (length == 1) {
    const ContractionTableCharacter *ctc = getContractionTableCharacter(toLowerCase(*src));
    if (!ctc) return 0;
    ruleOffset = ctc->rules;
    maximumLength = 1;
  } else {
    wchar_t characters[2];
    characters[0] = toLowerCase(src[0]);
    characters[1] = toLowerCase(src[1]);
    ruleOffset = getContractionTableHeader()->rules[CTH(characters)];
    maximumLength = 0;
  }

  while (ruleOffset) {
    currentRule = getContractionTableItem(ruleOffset);
    currentOpcode = currentRule->opcode;
    currentFindLength = currentRule->findlen;

    if ((length == 1) ||
        ((currentFindLength <= length) &&
         checkCurrentRule(src))) {
      setAfter(currentFindLength);

      if (!maximumLength) {
        maximumLength = currentFindLength;

        if (prefs.capitalizationMode != CTB_CAP_NONE) {
          typedef enum {CS_Any, CS_Lower, CS_UpperSingle, CS_UpperMultiple} CapitalizationState;
#define STATE(c) (testCharacter((c), CTC_UpperCase)? CS_UpperSingle: testCharacter((c), CTC_LowerCase)? CS_Lower: CS_Any)

          CapitalizationState current = STATE(before);
          int i;

          for (i=0; i<currentFindLength; i+=1) {
            wchar_t character = src[i];
            CapitalizationState next = STATE(character);

            if (i > 0) {
              if (((current == CS_Lower) && (next == CS_UpperSingle)) ||
                  ((current == CS_UpperMultiple) && (next == CS_Lower))) {
                maximumLength = i;
                break;
              }

              if ((prefs.capitalizationMode != CTB_CAP_SIGN) &&
                  (next == CS_UpperSingle)) {
                maximumLength = i;
                break;
              }
            }

            if ((prefs.capitalizationMode == CTB_CAP_SIGN) && (current > CS_Lower) && (next == CS_UpperSingle)) {
              current = CS_UpperMultiple;
            } else if (next != CS_Any) {
              current = next;
            } else if (current == CS_Any) {
              current = CS_Lower;
            }
          }

#undef STATE
        }
      }

      if ((currentFindLength <= maximumLength) &&
          (!currentRule->after || testCharacter(before, currentRule->after)) &&
          (!currentRule->before || testCharacter(after, currentRule->before))) {
        switch (currentOpcode) {
          case CTO_Always:
          case CTO_Repeatable:
          case CTO_Literal:
            return 1;

          case CTO_LargeSign:
          case CTO_LastLargeSign:
            if (!isBeginning() || !isEnding()) currentOpcode = CTO_Always;
            return 1;

          case CTO_WholeWord:
          case CTO_Contraction:
            if (testCharacter(before, CTC_Space|CTC_Punctuation) &&
                testCharacter(after, CTC_Space|CTC_Punctuation))
              return 1;
            break;

          case CTO_LowWord:
            if (testCharacter(before, CTC_Space) && testCharacter(after, CTC_Space) &&
                (previousOpcode != CTO_JoinedWord) &&
                ((dest == destmin) || !dest[-1]))
              return 1;
            break;

          case CTO_JoinedWord:
            if (testCharacter(before, CTC_Space|CTC_Punctuation) &&
                (before != '-') &&
                (dest + currentRule->replen < destmax)) {
              const wchar_t *end = src + currentFindLength;
              const wchar_t *ptr = end;

              while (ptr < srcmax) {
                if (!testCharacter(*ptr, CTC_Space)) {
                  if (!testCharacter(*ptr, CTC_Letter)) break;
                  if (ptr == end) break;
                  return 1;
                }

                if (ptr++ == cursor) break;
              }
            }
            break;

          case CTO_SuffixableWord:
            if (testCharacter(before, CTC_Space|CTC_Punctuation) &&
                testCharacter(after, CTC_Space|CTC_Letter|CTC_Punctuation))
              return 1;
            break;

          case CTO_PrefixableWord:
            if (testCharacter(before, CTC_Space|CTC_Letter|CTC_Punctuation) &&
                testCharacter(after, CTC_Space|CTC_Punctuation))
              return 1;
            break;

          case CTO_BegWord:
            if (testCharacter(before, CTC_Space|CTC_Punctuation) &&
                testCharacter(after, CTC_Letter))
              return 1;
            break;

          case CTO_BegMidWord:
            if (testCharacter(before, CTC_Letter|CTC_Space|CTC_Punctuation) &&
                testCharacter(after, CTC_Letter))
              return 1;
            break;

          case CTO_MidWord:
            if (testCharacter(before, CTC_Letter) && testCharacter(after, CTC_Letter))
              return 1;
            break;

          case CTO_MidEndWord:
            if (testCharacter(before, CTC_Letter) &&
                testCharacter(after, CTC_Letter|CTC_Space|CTC_Punctuation))
              return 1;
            break;

          case CTO_EndWord:
            if (testCharacter(before, CTC_Letter) &&
                testCharacter(after, CTC_Space|CTC_Punctuation))
              return 1;
            break;

          case CTO_BegNum:
            if (testCharacter(before, CTC_Space|CTC_Punctuation) &&
                testCharacter(after, CTC_Digit))
              return 1;
            break;

          case CTO_MidNum:
            if (testCharacter(before, CTC_Digit) && testCharacter(after, CTC_Digit))
              return 1;
            break;

          case CTO_EndNum:
            if (testCharacter(before, CTC_Digit) &&
                testCharacter(after, CTC_Space|CTC_Punctuation))
              return 1;
            break;

          case CTO_PrePunc:
            if (testCharacter(*src, CTC_Punctuation) && isBeginning() && !isEnding()) return 1;
            break;

          case CTO_PostPunc:
            if (testCharacter(*src, CTC_Punctuation) && !isBeginning() && isEnding()) return 1;
            break;

          default:
            break;
        }
      }
    }

    ruleOffset = currentRule->next;
  }

  return 0;
}
Esempio n. 13
0
bool EoBCoreEngine::magicObjectDamageHit(EoBFlyingObject *fo, int dcTimes, int dcPips, int dcOffs, int level) {
	int ignoreAttackerId = fo->flags & 0x10;
	int singleTargetCheckAdjacent = fo->flags & 1;
	int blockDamage = fo->flags & 2;
	int hitTest = fo->flags & 4;

	int savingThrowType = 5;
	int savingThrowEffect = 3;
	if (fo->flags & 8) {
		savingThrowType = 4;
		savingThrowEffect = 0;
	}

	int dmgFlag = _spells[fo->callBackIndex].damageFlags;
	if (fo->attackerId >= 0)
		dmgFlag |= 0x800;

	bool res = false;
	if (!level)
		level = 1;

	if ((_levelBlockProperties[fo->curBlock].flags & 7) && (fo->attackerId >= 0 || ignoreAttackerId)) {
		_preventMonsterFlash = true;

		for (const int16 *m = findBlockMonsters(fo->curBlock, fo->curPos, fo->direction, blockDamage, singleTargetCheckAdjacent); *m != -1; m++) {
			int dmg = rollDice(dcTimes, dcPips, dcOffs) * level;

			if (hitTest) {
				if (!characterAttackHitTest(fo->attackerId, *m, 0, 0))
					continue;
			}

			calcAndInflictMonsterDamage(&_monsters[*m], 0, 0, dmg, dmgFlag, savingThrowType, savingThrowEffect);
			res = true;
		}
		updateAllMonsterShapes();

	} else if (fo->curBlock == _currentBlock && (fo->attackerId < 0 || ignoreAttackerId)) {
		if (blockDamage) {
			for (int i = 0; i < 6; i++) {
				if (!testCharacter(i, 1))
					continue;
				if (hitTest && !monsterAttackHitTest(&_monsters[0], i))
					continue;

				int dmg = rollDice(dcTimes, dcPips, dcOffs) * level;
				res = true;

				calcAndInflictCharacterDamage(i, 0, 0, dmg, dmgFlag, savingThrowType, savingThrowEffect);
			}
		} else {
			int c = _dscItemPosIndex[(_currentDirection << 2) + (fo->curPos & 3)];
			if ((c > 2) && (testCharacter(4, 1) || testCharacter(5, 1)) && rollDice(1, 2, -1))
				c += 2;

			if (!fo->item && (_characters[c].effectFlags & 8)) {
				res = true;
			} else {
				if ((_characters[c].flags & 1) && (!hitTest || monsterAttackHitTest(&_monsters[0], c))) {
					int dmg = rollDice(dcTimes, dcPips, dcOffs) * level;
					res = true;
					calcAndInflictCharacterDamage(c, 0, 0, dmg, dmgFlag, savingThrowType, savingThrowEffect);
				}
			}
		}
	}

	if (res && (fo->flags & 0x40))
		explodeObject(fo, fo->curBlock, fo->item);
	else if ((_flags.gameID == GI_EOB1 && fo->item == 5) || (_flags.gameID == GI_EOB2 && fo->item == 4))
		res = false;

	return res;
}
Esempio n. 14
0
void EoBCoreEngine::startSpell(int spell) {
	EoBSpell *s = &_spells[spell];
	EoBCharacter *c = &_characters[_activeSpellCharId];
	snd_playSoundEffect(s->sound);

	if (s->flags & 0xA0)
		sparkEffectDefensive(_activeSpellCharId);
	else if (s->flags & 0x40)
		sparkEffectDefensive(-1);
	else if (s->flags & 0x1000)
		sparkEffectOffensive();

	if (s->flags & 0x20) {
		_txt->printMessage(c->name);
		_txt->printMessage(_flags.gameID == GI_EOB1 ? _magicStrings3[1] : _magicStrings1[5]);
	}

	if ((s->flags & 0x30) && (s->effectFlags & c->effectFlags)) {
		if (_flags.gameID == GI_EOB2)
			printWarning(Common::String::format(_magicStrings7[0], c->name, s->name).c_str());
	} else if ((s->flags & 0x50) && (s->effectFlags & _partyEffectFlags)) {
		if (_flags.gameID == GI_EOB1 && s->effectFlags == 0x400)
			// EOB 1 only warns in case of a bless spell
			printWarning(_magicStrings8[1]);
		else
			printWarning(Common::String::format(_magicStrings7[1], s->name).c_str());
	} else {
		if (s->flags & 8)
			setSpellEventTimer(spell, s->timingPara[0], s->timingPara[1], s->timingPara[2], s->timingPara[3]);

		_returnAfterSpellCallback = false;
		if (s->startCallback)
			(this->*s->startCallback)();
		if (_returnAfterSpellCallback)
			return;

		if (s->flags & 1)
			c->effectFlags |= s->effectFlags;
		if (s->flags & 4)
			_partyEffectFlags |= s->effectFlags;

		if (s->flags & 0x200) {
			for (int i = 0; i < 6; i++) {
				if (!testCharacter(i, 1))
					continue;
				if (!testCharacter(i, 2) && !(s->flags & 0x800))
					continue;
				_characters[i].effectFlags |= s->effectFlags;
			}
		}

		if (s->flags & 2)
			recalcArmorClass(_activeSpellCharId);

		if (s->flags & 0x20A0)
			gui_drawCharPortraitWithStats(_activeSpellCharId);
		if (s->flags & 0x40)
			gui_drawAllCharPortraitsWithStats();
	}

	if (_castScrollSlot) {
		gui_updateSlotAfterScrollUse();
	} else {
		_characters[_openBookChar].disabledSlots |= 4;
		setCharEventTimer(_openBookChar, 72, 11, 1);
		gui_toggleButtons();
		gui_drawSpellbook();
	}

	if (_flags.gameID == GI_EOB2) {
		//_castSpellWd1 = spell;
		runLevelScript(_currentBlock, 0x800);
		//_castSpellWd1 = 0;
	}
}