Esempio n. 1
0
void GenericTreeModel::Change(INT32 index, BOOL sorting_might_have_changed)
{
	if (IsItem(index) && SetChangeType(ITEMS_CHANGED))
	{
		BroadcastItemChanged(index, sorting_might_have_changed);
	}
}
Esempio n. 2
0
PGraph TAmazonItemBs::GetGraph() const {
  // create graph
  PGraph Graph=TGGraph::New();
  // vertices
  for (int ItemIdN=0; ItemIdN<GetItems(); ItemIdN++){
    PAmazonItem Item=GetItem(ItemIdN);
    TStr VrtxNm=Item->GetStr();
    PVrtx Vrtx=PVrtx(new TGVrtx(ItemIdN, VrtxNm));
    Graph->AddVrtx(Vrtx);
  }
  // edges
  for (int SrcItemIdN=0; SrcItemIdN<GetItems(); SrcItemIdN++){
    PVrtx SrcVrtx=Graph->GetVrtx(SrcItemIdN);
    PAmazonItem SrcItem=GetItem(SrcItemIdN);
    for (int NextItemIdN=0; NextItemIdN<SrcItem->GetNextItemIds(); NextItemIdN++){
      TStr DstItemId=SrcItem->GetNextItemId(NextItemIdN);
      if (IsItem(DstItemId)){
        int DstItemIdN=GetItemIdN(DstItemId);
        PVrtx DstVrtx=Graph->GetVrtx(DstItemIdN);
        PEdge Edge=PEdge(new TGEdge(SrcVrtx, DstVrtx));
        Graph->AddEdge(Edge);
      }
    }
    if (SrcItemIdN%1000==0){printf("%d items converted\r", SrcItemIdN);}
  }
  printf("%d items converted\n", GetItems());
  // return graph
  return Graph;
}
Esempio n. 3
0
void CItem::ItemFall ( void )
{
	SetNextThink( 0.1 );

	if ( pev->flags & FL_ONGROUND )
	{
		// clatter if we have an owner (i.e., dropped by someone)
		// don't clatter if the item is waiting to respawn (if it's waiting, it is invisible!)
		if ( !FNullEnt( pev->owner )) 
		{
			EMIT_SOUND( ENT( pev ), CHAN_ITEM, (char *)FallSound(), 1, ATTN_NORM);
                    	ItemOnGround(); //do somewhat if needed
		}
		
		// lie flat
		pev->angles.x = 0;
		pev->angles.z = 0;

		pev->solid = SOLID_TRIGGER;

		if( IsAmmo( )) UTIL_SetSize( pev, Vector( -8, -8, -8 ), Vector( 8, 8, 8 ));
		if( IsItem( )) UTIL_SetSize( pev, Vector( -8, -8, -8 ), Vector( 8, 8, 8 ));
		else UTIL_AutoSetSize();
		
		UTIL_SetOrigin( this, pev->origin ); // link into world.

		SetTouch( ItemTouch );
		SetThink( NULL ); 
	}
}
Esempio n. 4
0
void CItem::ItemTouch( CBaseEntity *pOther )
{
	//removed this limitation for monsters
	if ( !pOther->IsPlayer() ) return;
	CBasePlayer *pPlayer = (CBasePlayer *)pOther;
	if (!UTIL_IsMasterTriggered(m_sMaster, pPlayer)) return;
	if (pPlayer->pev->deadflag != DEAD_NO) return;

	if (AddItem( pPlayer ) != -1 )
	{
		UTIL_FireTargets( pev->target, pOther, this, USE_TOGGLE );
		SetTouch( NULL );
                  
		if( IsItem() && gmsg.ItemPickup )
		{
			//show icon for item
			MESSAGE_BEGIN( MSG_ONE, gmsg.ItemPickup, NULL, pPlayer->pev );
				WRITE_STRING( STRING(pev->classname) );
			MESSAGE_END();
		}
		
		// play pickup sound
		EMIT_SOUND( pPlayer->edict(), CHAN_ITEM, (char *)PickSound(), 1, ATTN_NORM );
		
		// tell the owner item was taken
 		if (!FNullEnt( pev->owner )) pev->owner->v.impulse = 0;
		
		// enable respawn in multiplayer
		if ( g_pGameRules->IsMultiplayer() && !FBitSet( pev->spawnflags, SF_NORESPAWN ))
			Respawn(); 
		else UTIL_Remove( this );
	}
	else if ( gEvilImpulse101 ) UTIL_Remove( this );
}
Esempio n. 5
0
float CItem::ItemRespawnTime( CItem *pItem )
{
	//makes different time to respawn for weapons and items
	float flRespawnTime;

	if (IsAmmo()) flRespawnTime = RESPAWN_TIME_30SEC;
	if (IsItem()) flRespawnTime = RESPAWN_TIME_120SEC;
	return gpGlobals->time + flRespawnTime;
}
Esempio n. 6
0
/***********************************************************************************
**
**	GenericTreeModel::Remove
**
***********************************************************************************/
GenericTreeModelItem* GenericTreeModel::Remove(INT32 index, BOOL all_children)
{
	GenericTreeModelItem* removed_item = 0;
	if (IsItem(index))
	{
		removed_item = GetGenericItemByIndex(index);
		Remove(index, all_children, FALSE);
	}
	return removed_item;
}
Esempio n. 7
0
void TAmazonItemBs::GetVoidItemIdV(TStrV& VoidItemIdV) const {
  VoidItemIdV.Clr();
  for (int ItemIdN=0; ItemIdN<GetItems(); ItemIdN++){
    PAmazonItem Item=GetItem(ItemIdN);
    for (int NextItemIdN=0; NextItemIdN<Item->GetNextItemIds(); NextItemIdN++){
      TStr NextItemId=Item->GetNextItemId(NextItemIdN);
      if (!IsItem(NextItemId)){VoidItemIdV.AddUnique(NextItemId);}
    }
  }
}
Esempio n. 8
0
	UObject *find_toplevel_object( u32 serial )
	{
	  if ( IsItem( serial ) )
	  {
		return find_toplevel_item( serial );
	  }
	  else
	  {
		return find_character( serial );
	  }
	}
Esempio n. 9
0
// 选择列表框中的所有行
BOOL CMyListCtrl::SelectAll()
{
   BOOL bReturn(TRUE);

   for (int nItem = 0; IsItem(nItem); nItem++) 
      if (! SetItemState(nItem, LVIS_SELECTED, LVIS_SELECTED)) {
         bReturn = FALSE;
         break;
      }

   return bReturn;
}
Esempio n. 10
0
Item ToItem(const std::string& item_name)
{

  assert(IsItem(item_name));

  using Pair = std::pair<Item,std::string>;
  const auto m = CreateItemBimap();
  return std::find_if(
    std::begin(m),
    std::end(m),
    [item_name](const Pair& p) { return p.second == item_name; }
  )->first;
}
PawnShopChapter ParsePawnShopChapter(std::stringstream& s, Chapter * const chapter)
{
  const Helper h;
  PawnShopChapter c(chapter);
  while (1)
  {
    const std::string what{h.ReadString(s)};
    if (what == "@") break;
    assert(IsItem(what));
    const Item item{ToItem(what)};
    const int price{h.ReadInt(s)};
    c.AddItem(item,price);
  }
  return c;
}
Esempio n. 12
0
void ConfigParser::ParseConfigFile()
{
   ifstream ifsConfigFile(ConfigFile.c_str()); // Opening Configuration file
   if (!ifsConfigFile.is_open())
   {
   	debug << "ConifgParser Error: Could not open " << ConfigFile << endb;
   	exit(0);
   }

   unsigned int intCurrentLine = 0;
   string strCurrentLine;
   while(getline(ifsConfigFile, strCurrentLine))
   {    
   	intCurrentLine++; // start with line 1.

   	if (strCurrentLine == "")
   	   continue;

   	// replace this with a strip function.
   	while(strCurrentLine[0] == ' ')
   	{
   	   strCurrentLine = strCurrentLine.substr(1);
   	}

   	// Comment line. Ignore.
   	if (strCurrentLine[0] == '#')
   	   continue;

   	if (!IsItem(strCurrentLine.substr(0, strCurrentLine.find(" "))))
   	{
   	   // handle error "Unrecognizable configuration"
   	   debug << "Line " << intCurrentLine << ": Unrecognizable configuration." << endb;
   	   continue;
   	}

   	string strItem = strCurrentLine.substr(0, strCurrentLine.find(" "));
   	strCurrentLine = strCurrentLine.substr(strItem.length()+1);

   	// replace this with a strip function.
        while(strCurrentLine[0] == ' ')
        {
           strCurrentLine = strCurrentLine.substr(1);
        }

   	if (strCurrentLine[0] != '=')
   	{
   	   // handle error "Expected '=' Token."
   	   debug << "Line " << intCurrentLine << ": Expected \'=\' Token." << endb;
   	   continue;
   	}
   	strCurrentLine = strCurrentLine.substr(1);

        // replace this with a strip function.
        while(strCurrentLine[0] == ' ')
        {
           strCurrentLine = strCurrentLine.substr(1);
        }
   	
   	if (strCurrentLine[0] != '\"')
   	{
   	   // handle error "Expected '\"' Token."
   	   debug << "Line " << intCurrentLine << ": Expected \'\"\' Token (0x01)." << endb;
   	   continue;
   	}

   	// Format is ITEM = "CONFIGURATION"
   	string strConfiguration = strCurrentLine.substr(1);
   	if (strConfiguration.find('\"') != string::npos)
   	{
   	   for (unsigned int i = 0; i < strConfiguration.length(); i++)
   	   {
   	   	if ('\"' == strConfiguration[i] && '\\' != strConfiguration[i-1])
   	   	   strConfiguration = strConfiguration.substr(0, i);
   	   }
   	}
   	else
  	{
   	   // handle error "Expected '\"' Token"
   	   debug << "Line " << intCurrentLine << ": Expected \'\"\' Token (0x02)." << endb;
   	   continue;
   	}
   	SetConfiguration(strItem, strConfiguration);
   }
 
   ifsConfigFile.close();
   M_parsed = true;
}
Esempio n. 13
0
Chapter::Chapter(const int chapter_number)
  :
    m_ball_game_chapter{*this},
    m_bye_text{},
    m_consequence{},
    m_chapter_number{chapter_number},
    m_chapter_type{ChapterType::normal},
    m_dice_game_chapter{*this},
    m_fighting_chapter{FightingChapter(*this)},
    m_game_lost_chapter{this},
    m_game_won_chapter{this},
    m_luck_chapter(*this),
    m_observer{nullptr},
    m_options_chapter{},
    m_pawn_shop_chapter(this),
    m_pill_game_chapter{*this},
    m_shop_chapter{this},
    m_skill_chapter{*this},
    m_text{},
    m_verbose{false}
{
  if (m_verbose) { std::clog << __func__ << std::endl; }
  Helper h;

  if (m_verbose) { std::clog << __func__ << std::endl; }

  #ifdef USE_TEXT_FILES_FOR_INPUT
  const std::string filename{h.GetFilesFolder() + h.ToStr(chapter_number) + ".txt"};
  if (!h.IsRegularFile(filename))
  {
    std::stringstream msg;
    msg << __func__ << ": ERROR: File " << filename << " does not exist";
    Helper().Cout(msg.str());
    throw std::runtime_error(msg.str());
  }
  const std::vector<std::string> lines{h.FileToVector(filename)};
  #else
  const std::vector<std::string> lines(1,GetFile(h.ToStr(chapter_number)));
  #endif
  std::stringstream s;
  std::copy(std::begin(lines),std::end(lines),std::ostream_iterator<std::string>(s," "));

  m_text = h.ReadText(s);

  m_chapter_type = ReadChapterType(s);

  switch (m_chapter_type)
  {
    case ChapterType::game_lost: return;
    case ChapterType::game_won: return;
    default: break;
  }

  while (!s.eof())
  {
    const std::string str{h.ReadString(s)};
    if (str.empty())
    {
      break;
    }
    else if (str == "Bye" || str == "bye")
    {
      m_bye_text = h.ReadText(s);
    }
    else if (str == "Change" || str == "change")
    {
      m_consequence.Add(ParseConsequence(s));
    }
    else if (str == "Escape" || str == "escape")
    {
      GetFighting().SetRoundsToEscape(h.ReadInt(s));
      GetFighting().SetEscapeToChapter(h.ReadInt(s));
    }
    else if (str == "Fight_both" || str == "fight_both")
    {
      GetFighting().SetFightSequentially(false);
    }
    else if (str == "Luck" || str == "luck")
    {
      assert(this->m_chapter_type == ChapterType::test_your_luck);
      const std::string luck_text{h.ReadText(s)};
      assert(!luck_text.empty());
      GetLuck().SetLuckText(luck_text);
      const std::string goto_str{h.ReadString(s)};
      assert(goto_str == "goto");
      const int luck_chapter{h.ReadInt(s)};
      assert(luck_chapter > 1);
      GetLuck().SetLuckChapter(luck_chapter);
    }
    else if (str == "Monster" || str == "monster")
    {
      this->m_chapter_type = ChapterType::fight;
      const Monster monster{ParseMonster(s)};
      GetFighting().AddMonster(monster);
    }
    else if (str == "Next_chapter" || str == "goto")
    {
      m_consequence.SetNextChapter(h.ReadInt(s));
    }
    else if (str == "No_luck" || str == "no_luck")
    {
      assert(this->m_chapter_type == ChapterType::test_your_luck);
      //s << std::noskipws; //Obligatory
      //Parse(s,' '); //You expect a space after a word
      const std::string no_luck_text{h.ReadText(s)};
      assert(!no_luck_text.empty());
      GetLuck().SetNoLuckText(no_luck_text);
      const std::string then{h.ReadString(s)};
      if (then == "change")
      {
        const Consequence no_luck_consequence{ParseConsequence(s)};
        GetLuck().SetNoLuckConsequence(no_luck_consequence);
        const std::string goto_str{h.ReadString(s)};
        assert(goto_str == "goto");
      }
      else
      {
        assert(then == "goto");
      }
      const int no_luck_chapter{h.ReadInt(s)};
      assert(no_luck_chapter > 1);
      GetLuck().SetNoLuckChapter(no_luck_chapter);
    }
    else if (str == "No_skill" || str == "no_skill")
    {
      assert(this->m_chapter_type == ChapterType::test_your_skill);
      //Parse(s,' '); //You expect a space after a word
      const std::string no_skill_text{h.ReadText(s)};
      assert(!no_skill_text.empty());
      GetSkill().SetNoSkillText(no_skill_text);
      const std::string then_str{h.ReadString(s)};
      Consequence consequence;
      if (then_str == "goto")
      {
        consequence.SetNextChapter(h.ReadInt(s));
      }
      else if (then_str == "change")
      {
        consequence = ParseConsequence(s);
        //Also read goto
        const std::string goto_str{h.ReadString(s)};
        assert(goto_str == "goto");
        consequence.SetNextChapter(h.ReadInt(s));
      }
      else
      {
        assert(!"Should not get here");
      }
      GetSkill().SetNoSkillConsequence(consequence);
    }
    else if (str == "Option" || str == "option")
    {
      const std::string option_text{h.ReadText(s)};
      const std::string t{h.ReadString(s)};
      if (t == "if")
      {
        const Condition condition{ParseCondition(s)};

        const std::string then_str{h.ReadString(s)};
        Consequence consequence;
        if (then_str == "goto")
        {
          consequence.SetNextChapter(h.ReadInt(s));
        }
        else if (then_str == "change")
        {
          consequence = ParseConsequence(s);
          //Also read goto
          const std::string goto_str{h.ReadString(s)};
          assert(goto_str == "goto");
          consequence.SetNextChapter(h.ReadInt(s));
        }
        else
        {
          assert(!"Should not get here");
        }
        Option option(option_text,consequence);
        option.SetCondition(condition);
        GetOptions().AddOption(option);
      }
      else if (t == "ifnot")
      {
        Condition condition;
        const std::string what{h.ReadString(s)};
        if (IsItem(what))
        {
          const Item item_not_needed{ToItem(what)};
          condition.AddItemNotNeeded(item_not_needed);
        }
        else
        {
          std::cerr << "Unknown item " << what << " in chapter " << chapter_number << std::endl;
          assert(!"Should not get here");
        }
        const std::string str_goto{h.ReadString(s)};
        assert(str_goto == "goto");
        Consequence consequence;
        consequence.SetNextChapter(h.ReadInt(s));
        Option option(option_text,consequence);
        option.SetCondition(condition);
        GetOptions().AddOption(option);
      }
      else if (t == "goto")
      {
        Consequence consequence;
        consequence.SetNextChapter(h.ReadInt(s));
        const Option option(option_text,consequence);
        GetOptions().AddOption(option);
      }
      else if (h.IsInt(t))
      {
        std::clog << "WARNING: goto omitted in chapter " << chapter_number << std::endl;
        //If no goto, just parse the number
        Consequence consequence;
        consequence.SetNextChapter(h.ToInt(t));
        const Option option(option_text,consequence);
        GetOptions().AddOption(option);
      }
      else
      {
        std::cerr << "Unknown option " << t << " in chapter " << chapter_number <<std::endl;
        assert(!"Should not get here");
      }
    }
    else if (str == "Random_monsters" || str == "random_monsters")
    {
      std::vector<Monster> monsters{ParseMonsters(s)};
      m_chapter_type = ChapterType::fight;
      const int which_monster_index{Dice::Get()->Throw() - 1};
      assert(which_monster_index >= 0);
      assert(which_monster_index < static_cast<int>(monsters.size()));
      const Monster monster{monsters[which_monster_index]};
      m_fighting_chapter.AddMonster(monster);
    }
    else if (str == "Sell_items" || str == "sell_items")
    {
      assert(this->m_chapter_type == ChapterType::pawn_shop);
      //m_chapter_type = ChapterType::pawn_shop;
      m_pawn_shop_chapter = ParsePawnShopChapter(s,this);
    }
    else if (str == "Shop_items" || str == "shop_items")
    {
      assert(this->m_chapter_type == ChapterType::shop);
      //m_chapter_type = ChapterType::shop;
      m_shop_chapter = ParseShopChapter(s,this);
    }
    else if (str == "Skill" || str == "skill")
    {
      assert(this->m_chapter_type == ChapterType::test_your_skill);
      this->m_chapter_type = ChapterType::test_your_skill;
      //Parse(s,' '); //You expect a space after a word
      const std::string skill_text{h.ReadText(s)};
      assert(!skill_text.empty());
      GetSkill().SetSkillText(skill_text);
      const std::string then_str{h.ReadString(s)};
      Consequence consequence;
      if (then_str == "goto")
      {
        consequence.SetNextChapter(h.ReadInt(s));
      }
      else if (then_str == "change")
      {
        consequence = ParseConsequence(s);
        //Also read goto
        const std::string goto_str{h.ReadString(s)};
        assert(goto_str == "goto");
        consequence.SetNextChapter(h.ReadInt(s));
      }
      else
      {
        assert(!"Should not get here");
      }
      GetSkill().SetSkillConsequence(consequence);

    }

    else
    {
      std::cerr
        << "Chapter cannot parse chapter " << chapter_number  << '\n'
        << "Unknown string: " << str << '\n'
      ;
      assert(!"Should not get here");
    }
  }

}