Ejemplo n.º 1
0
static int
putKeyCombination (ListGenerationData *lgd, const KeyCombination *combination) {
  wchar_t delimiter = 0;

  {
    unsigned char index;
    for (index=0; index<combination->modifierCount; index+=1) {
      if (!delimiter) {
        delimiter = WC_C('+');
      } else if (!putCharacter(lgd, delimiter)) {
        return 0;
      }

      if (!putKeyName(lgd, &combination->modifierKeys[combination->modifierPositions[index]])) return 0;
    }
  }

  if (combination->flags & KCF_IMMEDIATE_KEY) {
    if (delimiter)
      if (!putCharacter(lgd, delimiter))
        return 0;

    if (!putKeyName(lgd, &combination->immediateKey)) return 0;
  }

  return 1;
}
Ejemplo n.º 2
0
void doThings(lua_State* L)
{
    ///////// create the meta table for character class /////////
    luaL_newmetatable(L, "UnitMT");
    lua_pushvalue(L, -1);
    lua_setfield(L, -2, "__index");
    lua_pushcfunction(L, function_unit_getDamage);
    lua_setfield(L, -2, "getDamage");
    lua_pushcfunction(L, function_unit_dealtDamage);
    lua_setfield(L, -2, "dealtDamage");
    lua_pushcfunction(L, function_unit_health);
    lua_setfield(L, -2, "health");
    lua_pop(L, 1);
    //
    //
    //
    //
    // create new meta table for Character
    luaL_newmetatable(L, "CharacterMT");
    // set the meta table of the character meta table to be itself
    // lua_pushvalue(L, -1);
    // instead of referencing itself, we reference the unit mt as "parent"
    luaL_getmetatable(L, "UnitMT");
    lua_setfield(L, -2, "__index");
    // pop the meta table from the stack
    lua_pop(L, 1);

    // create the 2 character
    Character attacker("Attacker", 3, 10);
    Unit defender(1, 20);


    // print the state before the call
    std::cout << "[C++] [Before damage] Attacker Hp : " << attacker.health << " Defender Hp : " << defender.health << std::endl;
    std::cout << "[C++] Calling damage function from lua" << std::endl;

    // manually do it here, to test the polymorphism
    // put the function on the stack
    lua_getglobal(L, "applyDamage");
    // create a new user data on the stack, and assign the attacker pointer to it
    putCharacter(L, attacker);
    // create a new user data on the stack, and assign the defender pointer to it
    putUnit(L, defender);
    // call the function
    lua_call(L, 2, 0);
    // shouldn't have anything to pop
    assert(lua_gettop(L) == 0);


    // print the state after the call
    std::cout << "[C++] [After damage]  Attacker Hp : " << attacker.health << " Defender Hp : " << defender.health << std::endl;


    lua_getglobal(L, "testcharacter");
    putCharacter(L, attacker);
    lua_call(L, 1, 0);
    lua_getglobal(L, "testcharacter");
    putUnit(L, defender);
    lua_call(L, 1, 0);
}
Ejemplo n.º 3
0
static int
putKeyName (ListGenerationData *lgd, const KeyValue *value) {
  const KeyNameEntry *kne = findKeyNameEntry(lgd, value);
  if (kne) return putUtf8String(lgd, kne->name);

  if (value->key != KTB_KEY_ANY) {
    const KeyValue anyKey = {
      .set = value->set,
      .key = KTB_KEY_ANY
    };

    if ((kne = findKeyNameEntry(lgd, &anyKey))) {
      if (!putUtf8String(lgd, kne->name)) return 0;
      if (!putCharacter(lgd, WC_C('.'))) return 0;
      if (!putNumber(lgd, value->key+1)) return 0;
      return 1;
    }
  }

  return putUtf8String(lgd, "?");
}

static int
putKeyCombination (ListGenerationData *lgd, const KeyCombination *combination) {
  wchar_t delimiter = 0;

  {
    unsigned char index;
    for (index=0; index<combination->modifierCount; index+=1) {
      if (!delimiter) {
        delimiter = WC_C('+');
      } else if (!putCharacter(lgd, delimiter)) {
        return 0;
      }

      if (!putKeyName(lgd, &combination->modifierKeys[combination->modifierPositions[index]])) return 0;
    }
  }

  if (combination->flags & KCF_IMMEDIATE_KEY) {
    if (delimiter)
      if (!putCharacter(lgd, delimiter))
        return 0;

    if (!putKeyName(lgd, &combination->immediateKey)) return 0;
  }

  return 1;
}
Ejemplo n.º 4
0
static int
processCharacters (const wchar_t *characters, size_t count, wchar_t end, void *data) {
  if (opt_reformatText && count) {
    if (iswspace(characters[0]))
      if (!flushCharacters('\n', data))
        return 0;

    {
      unsigned int spaces = !inputLength? 0: 1;
      size_t newLength = inputLength + spaces + count;

      if (newLength > inputSize) {
        size_t newSize = newLength | 0XFF;
        wchar_t *newBuffer = calloc(newSize, sizeof(*newBuffer));

        if (!newBuffer) {
          noMemory(data);
          return 0;
        }

        wmemcpy(newBuffer, inputBuffer, inputLength);
        free(inputBuffer);

        inputBuffer = newBuffer;
        inputSize = newSize;
      }

      while (spaces) {
        inputBuffer[inputLength++] = WC_C(' ');
        spaces -= 1;
      }

      wmemcpy(&inputBuffer[inputLength], characters, count);
      inputLength += count;
    }

    if (end != '\n') {
      if (!flushCharacters(0, data)) return 0;
      if (!putCharacter(end, data)) return 0;
    }
  } else {
    if (!flushCharacters('\n', data)) return 0;
    if (!writeCharacters(characters, count, data)) return 0;
    if (!putCharacter(end, data)) return 0;
  }

  return 1;
}
Ejemplo n.º 5
0
static int
endLine (ListGenerationData *lgd) {
  if (!putCharacter(lgd, 0)) return 0;
  if (!handleLine(lgd, lgd->lineCharacters)) return 0;

  lgd->lineLength = 0;
  return 1;
}
Ejemplo n.º 6
0
static int
endLine (ListGenerationData *lgd) {
  if (!putCharacter(lgd, 0)) return 0;
  if (!listLine(lgd, lgd->line.characters)) return 0;

  lgd->line.length = 0;
  return 1;
}
Ejemplo n.º 7
0
static int
putCharacters (const widechar * characters, int count)
{
  int k;
  for (k = 0; k < count; k++)
    if (!putCharacter (characters[k]))
      return 0;
  return 1;
}
Ejemplo n.º 8
0
 /**
  * This method mirrors the function in the lua script.
  */
 void applyDamage(Character& attacker, Character& defender)
 {
     // put the function on the stack
     lua_getglobal(L, name.c_str());
     int type = lua_type(L, -1);
     if(type == LUA_TFUNCTION)
     {
         // create a new user data on the stack, and assign the attacker pointer to it
         putCharacter(L, attacker);
         // create a new user data on the stack, and assign the defender pointer to it
         putCharacter(L, defender);
         // call the function
         lua_call(L, 2, 0);
         // shouldn't have anything to pop
         assert(lua_gettop(L) == 0);
     }
     else
     {
         std::cout << "Cannot find " << name << "function" << std::endl;
     }
 }
Ejemplo n.º 9
0
static int
flushCharacters (wchar_t end, void *data) {
  if (inputLength) {
    if (!writeCharacters(inputBuffer, inputLength, data)) return 0;
    inputLength = 0;

    if (end)
      if (!putCharacter(end, data))
        return 0;
  }

  return 1;
}
Ejemplo n.º 10
0
static int
writeCharacters (const wchar_t *inputLine, size_t inputLength, void *data) {
  const wchar_t *inputBuffer = inputLine;

  while (inputLength) {
    int inputCount = inputLength;
    int outputCount = outputWidth;

    if (!outputBuffer) {
      if (!(outputBuffer = malloc(outputWidth))) {
        noMemory(data);
        return 0;
      }
    }

    contractText(contractionTable,
                 inputBuffer, &inputCount,
                 outputBuffer, &outputCount,
                 NULL, CTB_NO_CURSOR);

    if ((inputCount < inputLength) && outputExtend) {
      free(outputBuffer);
      outputBuffer = NULL;
      outputWidth <<= 1;
    } else {
      {
        int index;

        for (index=0; index<outputCount; index+=1)
          if (!putCell(outputBuffer[index], data))
            return 0;
      }

      inputBuffer += inputCount;
      inputLength -= inputCount;

      if (inputLength)
        if (!putCharacter('\n', data))
          return 0;
    }
  }

  return 1;
}
Ejemplo n.º 11
0
static int
listHotkeyEvent (ListGenerationData *lgd, const KeyValue *keyValue, const char *event, int command) {
  if (command != BRL_CMD_NOOP) {
    if ((command & BRL_MSK_BLK) == BRL_BLK_CONTEXT) {
      const KeyContext *c = getKeyContext(lgd->keyTable, (KTB_CTX_DEFAULT + (command & BRL_MSK_ARG)));
      if (!c) return 0;
      if (!putUtf8String(lgd, "switch to ")) return 0;
      if (!putCharacterString(lgd, c->title)) return 0;
    } else {
      if (!putCommandDescription(lgd, command, (keyValue->key != KTB_KEY_ANY))) return 0;
    }

    if (!putCharacterString(lgd, WS_C(": "))) return 0;
    if (!putUtf8String(lgd, event)) return 0;
    if (!putCharacter(lgd, WC_C(' '))) return 0;
    if (!putKeyName(lgd, keyValue)) return 0;
    if (!endLine(lgd)) return 0;
  }

  return 1;
}
Ejemplo n.º 12
0
void RedWhite::sendMessageSelf()
{
    for(int i = 0;i < 4;i++)
    {
        if(magicGroup[i]->isClicked)
        {
            informationKind = 200 + i;
        }
    }
    std::vector<int> tempMes;
    if(cancel->isClicked && informationKind < 100)
    {
        if(informationKind == 7)
        {
            tempMes.push_back(-1);
            emit sendMessageSelfSig(tempMes);
            return;
        }
        tempMes.push_back(0);
        emit sendMessageSelfSig(tempMes);
        return;
    }
    if(cancel->isClicked && informationKind > 99 && !ensure->canBeClicked)
    {
        tempMes.push_back(-1);
        emit sendMessageSelfSig(tempMes);
        return;
    }
    if(cancel->isClicked && informationKind > 99 && ensure->canBeClicked)
    {
        tempMes.push_back(0);
        emit sendMessageSelfSig(tempMes);
        return;
    }
    switch(informationKind)
    {
        case 6://血之哀伤
        {
            putCharacter(tempMes);
            emit sendMessageSelfSig(tempMes);
            return;
        }
        case 200://同生共死
        {
            tempMes.push_back(1);
            tempMes.push_back(1);
            putCharacter(tempMes);
            lifeLink = true;
            for(int i = 0;i < 6;i++)
            {
                if(paintStructX->gameCharacter[i]->characterPic->isClicked)
                {
                    lifeLinkCha = i;
                }
            }
            emit sendMessageSelfSig(tempMes);
            return;
        }
        case 201://逆流
        {
            tempMes.push_back(1);
            tempMes.push_back(2);
            putCardCount(tempMes);
            putCard(tempMes);
            emit sendMessageSelfSig(tempMes);
            return;
        }
        case 202://血之悲鸣响应阶段
        {
        //system("pause");
            if(!bloodAsk)
            {
                tempMes.push_back(1);
                tempMes.push_back(3);
                putCharacter(tempMes);
                putCard(tempMes);
                emit sendMessageSelfSig(tempMes);
                return;
            }
            else
            {
                for(int i = 0;i < 5;i++)
                {
                    if(blood->number[i]->isClicked)
                    {
                        tempMes.push_back(i + 1);
                        emit sendMessageSelfSig(tempMes);
                        return;
                    }
                }
            }

        }
        case 203://血之诅咒响应阶段
        {
            tempMes.push_back(1);
            tempMes.push_back(4);
            putCharacter(tempMes);
            putCardCount(tempMes);
            putCard(tempMes);
            emit sendMessageSelfSig(tempMes);
            return;
        }
        default:
        {
            sendMessageIn();
        }
    }
}
Ejemplo n.º 13
0
static int
backTranslateString ()
{
  /*Back translation */
  int srcword = 0;
  int destword = 0;		/* last word translated */
  translation_direction = 0;
  nextUpper = allUpper = allUpperPhrase = itsANumber = itsALetter = itsCompbrl = 0;
  previousOpcode = CTO_None;
  src = dest = 0;
  while (src < srcmax)
    {
/*the main translation loop */
      back_setBefore ();
      back_selectRule ();
      if (appliedRules != NULL && appliedRulesCount < maxAppliedRules)
	appliedRules[appliedRulesCount++] = currentRule;
      /* processing before replacement */
      switch (currentOpcode)
	{
	case CTO_Hyphen:
	    itsANumber = 0;
	  break;
	case CTO_LargeSign:
	  if (previousOpcode == CTO_LargeSign)
	    if (!insertSpace ())
	      goto failure;
	  break;
	case CTO_CapsLetterRule:
	  nextUpper = 1;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_BegCapsWordRule:
	  allUpper = 1;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_BegCapsRule:
	  allUpperPhrase = 1;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_EndCapsWordRule:
	  allUpper = 0;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_EndCapsRule:
	  allUpperPhrase = 0;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_LetterRule:
	  itsALetter = 1;
	  itsANumber = 0;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_NumberRule:
	  itsANumber = 1;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_BegEmph1Rule:
	  currentTypeform = italic;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_BegEmph2Rule:
	  currentTypeform = underline;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_BegEmph3Rule:
	  currentTypeform = bold;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_EndEmph1Rule:
	case CTO_EndEmph2Rule:
	case CTO_EndEmph3Rule:
	  currentTypeform = plain_text;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_BegCompRule:
	  itsCompbrl = 1;
	  currentTypeform = computer_braille;
	  src += currentDotslen;
	  continue;
	  break;
	case CTO_EndCompRule:
	  itsCompbrl = 0;
	  currentTypeform = plain_text;
	  src += currentDotslen;
	  continue;
	  break;

	default:
	  break;
	}

      /* replacement processing */
      switch (currentOpcode)
	{
	case CTO_Replace:
	  src += currentDotslen;
	  if (!putCharacters
	      (&currentRule->charsdots[0], currentRule->charslen))
	    goto failure;
	  break;
	case CTO_None:
	  if (!undefinedDots (currentInput[src]))
	    goto failure;
	  src++;
	  break;
	case CTO_BegNum:
	  itsANumber = 1;
	  goto insertChars;
	case CTO_EndNum:
	  itsANumber = 0;
	  goto insertChars;
	case CTO_Space:
	  itsALetter = itsANumber = allUpper = nextUpper = 0;
	default:
	insertChars:
	  if (currentRule->charslen)
	    {
	      if (!back_updatePositions
		  (&currentRule->charsdots[0],
		   currentRule->dotslen, currentRule->charslen))
		goto failure;
	      src += currentDotslen;
	    }
	  else
	    {
	      int srclim = src + currentDotslen;
	      while (1)
		{
		  if (!putCharacter (currentInput[src]))
		    goto failure;
		  if (++src == srclim)
		    break;
		}
	    }
	}

      /* processing after replacement */
      switch (currentOpcode)
	{
	case CTO_JoinNum:
	case CTO_JoinableWord:
	  if (!insertSpace ())
	    goto failure;
	  break;
	default:
	  break;
	}
      if (((src > 0) && checkAttr (currentInput[src - 1], CTC_Space, 1)
	   && (currentOpcode != CTO_JoinableWord)))
	{
	  srcword = src;
	  destword = dest;
	}
      if ((currentOpcode >= CTO_Always && currentOpcode <= CTO_None) ||
	  (currentOpcode >= CTO_Digit && currentOpcode <= CTO_LitDigit))
	previousOpcode = currentOpcode;
    }				/*end of translation loop */
failure:

  if (destword != 0 && src < srcmax && !checkAttr (currentInput[src],
						   CTC_Space, 1))
    {
      src = srcword;
      dest = destword;
    }
  if (src < srcmax)
    {
      while (checkAttr (currentInput[src], CTC_Space, 1))
	if (++src == srcmax)
	  break;
    }
  return 1;
}				/*translation completed */