⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inventory.cpp

📁 S.C.O.U.R.G.E.是一款类似Rogue的游戏
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  case SPELL:    for(int t = 0; t < MagicSchool::getMagicSchoolCount(); t++) {      MagicSchool *school = MagicSchool::getMagicSchool(t);         sprintf(schoolText[t], "%s (%s)", school->getName(), school->getDeity());      if(t == 0) {        showMemorizedSpellsInSchool(scourge->getParty()->getParty(selected), school);      }    }    schoolList->setLines(MagicSchool::getMagicSchoolCount(),                          (const char**)schoolText);    break;  case LOG:    break;  case MISSION:    int objectiveCount = 0;    if(scourge->getCurrentMission()) {      sprintf(missionText, "%s: %s",               scourge->getCurrentMission()->getName(),               scourge->getCurrentMission()->getStory());      objectiveCount =       scourge->getCurrentMission()->getObjective()->itemCount +      scourge->getCurrentMission()->getObjective()->monsterCount;         for(int t = 0; t < scourge->getCurrentMission()->getObjective()->itemCount; t++) {        sprintf(objectiveText[t], "Find %s. %s",                 scourge->getCurrentMission()->getObjective()->item[t]->getName(),                (scourge->getCurrentMission()->getObjective()->itemHandled[t] ?                  "(completed)" : "(not yet found)"));        if(scourge->getCurrentMission()->getObjective()->itemHandled[t]) {          missionColor[t].r = 0.2f;          missionColor[t].g = 0.7f;          missionColor[t].b = 0.2f;        } else {          missionColor[t].r = 0.7f;          missionColor[t].g = 0.2f;          missionColor[t].b = 0.2f;        }      }      int start = scourge->getCurrentMission()->getObjective()->itemCount;      for(int t = 0; t < scourge->getCurrentMission()->getObjective()->monsterCount; t++) {        sprintf(objectiveText[start + t], "Vanquish %s. %s",                 scourge->getCurrentMission()->getObjective()->monster[t]->getType(),                (scourge->getCurrentMission()->getObjective()->monsterHandled[t] ?                  "(completed)" : "(not yet done)"));        if(scourge->getCurrentMission()->getObjective()->monsterHandled[t]) {          missionColor[start + t].r = 0.2f;          missionColor[start + t].g = 0.7f;          missionColor[start + t].b = 0.2f;        } else {          missionColor[start + t].r = 0.7f;          missionColor[start + t].g = 0.2f;          missionColor[start + t].b = 0.2f;        }      }      start += scourge->getCurrentMission()->getObjective()->monsterCount;      for(int t = objectiveCount; t < MAX_INVENTORY_SIZE; t++) {        strcpy(objectiveText[t], "");      }    } else {      strcpy(missionText, "");      for(int t = 0; t < MAX_INVENTORY_SIZE; t++) {        strcpy(objectiveText[t], "");      }    }    missionDescriptionLabel->setText(missionText);    objectiveList->setLines(objectiveCount,                             (const char **)objectiveText,                            missionColor);    break;  }}// FIXME: this doesn't work: I can't get it to draw above the windowvoid Inventory::drawInventory() {  // draw the characters on top of the UI  glColor4f(1.0f, 1.0f, 0.4f, 1.0f);  int h = 120;//  int y;    for(int i = 0; i < 4; i++) {    // why do I need these 2 lines? Otherwise the models go behind the window    //	glDisable(GL_DEPTH_TEST);    //glEnable(GL_DEPTH_TEST);    glPushMatrix();    glLoadIdentity();//	cerr << "z=" << mainWin->getZ() << endl;    glTranslatef( mainWin->getX(), mainWin->getY() + Window::TOP_HEIGHT, mainWin->getZ() + 200 );    glTranslatef( 20, 10 + i * h + 90, 300);    glRotatef(90, 1, 0, 0);    glScalef(0.8, 0.8, 0.8);      glEnable( GL_TEXTURE_2D );    glColor4f( 1, 1, 1, 1 );    mainWin->scissorToWindow();    scourge->getParty()->getParty(i)->draw();    glDisable( GL_SCISSOR_TEST );    glDisable( GL_TEXTURE_2D );    glPopMatrix();  }}void Inventory::receive(Widget *widget) {  if(widget == invList) {    putItem();  } else if(widget == paperDoll) {    if(putItem() != -1) equipItem();  }}bool Inventory::startDrag(Widget *widget, int x, int y) {  if(widget == invList) {    dropItem();    return true;  } else if(widget == paperDoll) {    if(y > 0 && y < Character::INVENTORY_COUNT * 16) {      // what's equiped at this inventory slot?      Item *item = scourge->getParty()->getParty(selected)->getItemAtLocation((1 << (y / 16)));      if(item) {        // find its index in the inventory        int index = scourge->getParty()->getParty(selected)->findInInventory(item);        // select it        invList->setSelectedLine(index);        // drop it        dropItem();        return true;      }    }  }  return false;}int Inventory::putItem() {  Item *item = scourge->getMovingItem();  if(item) {    if(scourge->getParty()->getParty(selected)->addInventory(item)) {      // message: the player accepted the item      char message[120];      sprintf(message, "%s picks up %s.",               scourge->getParty()->getParty(selected)->getName(),              item->getItemName());      scourge->getMap()->addDescription(message);      scourge->endItemDrag();      int index = scourge->getParty()->getParty(selected)->findInInventory(item);      setSelectedPlayerAndMode(selected, INVENTORY);      invList->setSelectedLine(index);      return index;    } else {      // message: the player's inventory is full    }  }  return -1;}void Inventory::equipItem() {  int itemIndex = invList->getSelectedLine();    if(itemIndex > -1 &&      scourge->getParty()->getParty(selected)->getInventoryCount() > itemIndex) {    Item *item = scourge->getParty()->getParty(selected)->getInventory(itemIndex);    Character *character = scourge->getParty()->getParty(selected)->getCharacter();/*    cerr << "RA=" << Character::getCharacterIndexByShortName("RA") <<      " KN=" << Character::getCharacterIndexByShortName("KN") <<      " TI=" << Character::getCharacterIndexByShortName("TI") <<       " AS=" << Character::getCharacterIndexByShortName("AS") <<       " AR=" << Character::getCharacterIndexByShortName("AR") <<       " LO=" << Character::getCharacterIndexByShortName("LO") <<       " CO=" << Character::getCharacterIndexByShortName("CO") <<       " SU=" << Character::getCharacterIndexByShortName("SU") <<       " NA=" << Character::getCharacterIndexByShortName("NA") <<       " MO=" << Character::getCharacterIndexByShortName("MO") <<       " this=" << character->getShortName() << "=" << Character::getCharacterIndexByShortName(character->getShortName()) <<      " item=" << item->getRpgItem()->getName() <<       " acl=" << item->getRpgItem()->getAcl(Character::getCharacterIndexByShortName(character->getShortName())) <<       " all acl=" << item->getRpgItem()->getAllAcl() << endl;*/    if(!item->getRpgItem()->getAcl(Character::getCharacterIndexByShortName(character->getShortName()))) {      scourge->showMessageDialog(Constants::getMessage(Constants::ITEM_ACL_VIOLATION));      return;    }    scourge->getParty()->getParty(selected)->equipInventory(itemIndex);    // recreate list strings    int oldLine = invList->getSelectedLine();    setSelectedPlayerAndMode(selected, selectedMode);    invList->setSelectedLine(oldLine);  }}void Inventory::dropItem() {  int itemIndex = invList->getSelectedLine();    if(itemIndex > -1 &&      scourge->getParty()->getParty(selected)->getInventoryCount() > itemIndex) {    Item *item = scourge->getParty()->getParty(selected)->removeInventory(itemIndex);    scourge->setMovingItem(item,                            scourge->getParty()->getParty(selected)->getX(),                            scourge->getParty()->getParty(selected)->getY(),                            scourge->getParty()->getParty(selected)->getZ());    char message[120];    sprintf(message, "%s drops %s.",             scourge->getParty()->getParty(selected)->getName(),            item->getItemName());    scourge->getMap()->addDescription(message);    setSelectedPlayerAndMode(selected, INVENTORY);  }}void Inventory::refresh() {  setSelectedPlayerAndMode(selected, INVENTORY);}void Inventory::show() {   mainWin->setVisible(true);   // find selected player. FIXME: this is inefficient  int n = selected;  for(int i = 0; i < scourge->getParty()->getPartySize(); i++) {    if(scourge->getParty()->getPlayer() == scourge->getParty()->getParty(i)) {      n = i;      break;    }  }  setSelectedPlayerAndMode(n, selectedMode); }Spell *Inventory::getSelectedSpell() {  Creature *creature = scourge->getParty()->getParty(selected);  MagicSchool *school = NULL;  int n = schoolList->getSelectedLine();  if(n != -1 && n < MagicSchool::getMagicSchoolCount()) {    school = MagicSchool::getMagicSchool(n);  }  if(!school) return NULL;  n = spellList->getSelectedLine();  if(n != -1 && n < spellList->getLineCount()) {    int spellCount = 0;    for(int r = 0; r < school->getSpellCount(); r++) {      Spell *spell = school->getSpell(r);      if(creature->isSpellMemorized(spell)) {        if(n == spellCount) return spell;        spellCount++;      }    }  }  return NULL;}void Inventory::showMemorizedSpellsInSchool(Creature *creature, MagicSchool *school) {  int spellCount = 0;  for(int r = 0; r < school->getSpellCount(); r++) {    Spell *spell = school->getSpell(r);    if(creature->isSpellMemorized(spell)) {      spell->describe(spellText[spellCount]);      if(spellCount == 0) {        showSpellDescription(spell);      }      spellCount++;    }  }  if(spellCount == 0) spellDescriptionLabel->setText("");  spellList->setLines(spellCount,                       (const char**)spellText);}void Inventory::showSpellDescription(Spell *spell) {  spellDescriptionLabel->setText((char*)(spell->getNotes() ? spell->getNotes() : ""));}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -