Example #1
0
/**
**	@brief	Process data provided by a configuration file
**
**	@param	config_data	The configuration data
*/
void CUpgradeModifier::ProcessConfigData(const CConfigData *config_data)
{
	for (size_t i = 0; i < config_data->Properties.size(); ++i) {
		std::string key = config_data->Properties[i].first;
		std::string value = config_data->Properties[i].second;
		
		if (key == "apply_to") {
			value = FindAndReplaceString(value, "_", "-");
			const int unit_type_id = UnitTypeIdByIdent(value.c_str());
			if (unit_type_id != -1) {
				this->ApplyTo[unit_type_id] = 'X';
			} else {
				fprintf(stderr, "Invalid unit type: \"%s\".\n", value.c_str());
			}
		} else if (key == "remove_upgrade") {
			value = FindAndReplaceString(value, "_", "-");
			CUpgrade *removed_upgrade = CUpgrade::Get(value);
			if (removed_upgrade) {
				this->RemoveUpgrades.push_back(removed_upgrade);
			} else {
				fprintf(stderr, "Invalid upgrade: \"%s\".\n", value.c_str());
			}
		} else {
			key = SnakeCaseToPascalCase(key);
			
			int index = UnitTypeVar.VariableNameLookup[key.c_str()]; // variable index
			if (index != -1) { // valid index
				if (IsStringNumber(value)) {
					this->Modifier.Variables[index].Enable = 1;
					this->Modifier.Variables[index].Value = std::stoi(value);
					this->Modifier.Variables[index].Max = std::stoi(value);
				} else { // error
					fprintf(stderr, "Invalid value (\"%s\") for variable \"%s\" when defining modifier for upgrade \"%s\".\n", value.c_str(), key.c_str(), AllUpgrades[this->UpgradeId]->Ident.c_str());
				}
			} else {
				fprintf(stderr, "Invalid upgrade modifier property: \"%s\".\n", key.c_str());
			}
		}
	}
}
Example #2
0
  // returns a named wildcard
string t_regexp::GetWildcard (const string& sName) const
  {
  int iNumber = PCRE_ERROR_NOSUBSTRING;
  if (IsStringNumber (sName))
    iNumber = atoi (sName.c_str ());
  else
    {
    if (m_program == NULL)
      iNumber = PCRE_ERROR_NOSUBSTRING;
    else
      {
      /* now do named subpatterns  */
      int namecount;
      pcre_fullinfo(m_program, m_extra, PCRE_INFO_NAMECOUNT, &namecount);


      if (namecount > 0)
        {
        int name_entry_size;
        unsigned char *tabptr;
        int ncapt;
        int jchanged;
        pcre_fullinfo(m_program, m_extra, PCRE_INFO_CAPTURECOUNT, &ncapt);
        pcre_fullinfo(m_program, m_extra, PCRE_INFO_NAMETABLE, &tabptr);
        pcre_fullinfo(m_program, m_extra, PCRE_INFO_NAMEENTRYSIZE, &name_entry_size);
        pcre_fullinfo(m_program, m_extra, PCRE_INFO_JCHANGED, &jchanged);
        set<string> found_strings;
        for (int i = 0; i < namecount; i++, tabptr += name_entry_size) 
          {
          int n = (tabptr[0] << 8) | tabptr[1];
          const unsigned char * name = tabptr + 2;
          if (strcmp (sName.c_str (), (LPCTSTR) name) != 0)  // skip if wrong name
             continue;
          // if duplicates were possible then ...
          if (jchanged)
            {
            // this code is to ensure that we don't find a match (eg. mob = Kobold)
            // and then if duplicates were allowed, replace Kobold with false.

            string sName = (LPCTSTR) name;

            // for duplicate names, see if we already added this name
            if (found_strings.find (sName) != found_strings.end ())
              {
              // do not replace if this one is out of range or empty
              if (n < 0 || n > m_iCount || GetWildcard (n) == "")
                continue;
              } // end of duplicate
            else
              found_strings.insert (sName);
            }

          if (n >= 0 && n <= m_iCount) 
            iNumber = n;
      
          }   // end of wildcard loop
        } // end of having named wildcards

      } // end of program not NULL

    }   // end of wanting a named wildcard
  return GetWildcard (iNumber);
  } // end of t_regexp::GetWildcard