/** * @brief Parse Windows version data to string. * See info about how to determine Windows versions from URL: * http://msdn.microsoft.com/en-us/library/ms724833(VS.85).aspx * @return String describing Windows version. */ String CConfigLog::GetWindowsVer() { OSVERSIONINFOEX osvi; String sVersion; // Try calling GetVersionEx using the OSVERSIONINFOEX structure. // If that fails, try using the OSVERSIONINFO structure. ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); if( !GetVersionEx ((OSVERSIONINFO *) &osvi) ) { osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) return _T(""); } switch (osvi.dwPlatformId) { // Test for the Windows NT product family. case VER_PLATFORM_WIN32_NT: // Test for the specific product family. if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2 ) sVersion = _T("Microsoft Windows Server 2003 family, "); else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 ) sVersion = _T("Microsoft Windows XP "); else if ( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 ) sVersion = _T("Microsoft Windows 2000 "); else if ( osvi.dwMajorVersion <= 4 ) sVersion = _T("Microsoft Windows NT "); else if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 0 ) { if (osvi.wProductType == VER_NT_WORKSTATION) sVersion = _T("Microsoft Windows Vista "); else sVersion = _T("Microsoft Windows Server 2008 "); } else if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 1 ) { if (osvi.wProductType == VER_NT_WORKSTATION) sVersion = _T("Microsoft Windows 7 "); else sVersion = _T("Microsoft Windows Server 2008 R2 "); } else if ( osvi.dwMajorVersion == 6 && osvi.dwMinorVersion == 2 ) { if (osvi.wProductType == VER_NT_WORKSTATION) sVersion = _T("Microsoft Windows 8 "); else sVersion = _T("Microsoft Windows Server 2012 "); } else sVersion = string_format(_T("[? WindowsNT %d.%d] "), osvi.dwMajorVersion, osvi.dwMinorVersion); if (osvi.dwOSVersionInfoSize == sizeof(OSVERSIONINFOEX)) { // Test for specific product on Windows NT 4.0 SP6 and later. String sProduct = GetProductFromOsvi(osvi); sVersion += sProduct; } else { // Test for specific product on Windows NT 4.0 SP5 and earlier String sProduct = GetNtProductFromRegistry(osvi); sVersion += sProduct; } // Display service pack (if any) and build number. if( osvi.dwMajorVersion == 4 && _tcsicmp( osvi.szCSDVersion, _T("Service Pack 6") ) == 0 ) { HKEY hKey; LONG lRet; // Test for SP6 versus SP6a. lRet = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Hotfix\\Q246009"), 0, KEY_QUERY_VALUE, &hKey ); String ver; if( lRet == ERROR_SUCCESS ) ver = string_format(_T("Service Pack 6a (Build %d)"), osvi.dwBuildNumber & 0xFFFF ); else // Windows NT 4.0 prior to SP6a { ver = string_format(_T("%s (Build %d)"), osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); } sVersion += ver; RegCloseKey( hKey ); } else // Windows NT 3.51 and earlier or Windows 2000 and later { String ver = string_format( _T("%s (Build %d)"), osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF); sVersion += ver; } break; // Test for the Windows 95 product family. case VER_PLATFORM_WIN32_WINDOWS: if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0) { sVersion = _T("Microsoft Windows 95 "); if ( osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B' ) sVersion += _T("OSR2 " ); } else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10) { sVersion = _T("Microsoft Windows 98 "); if ( osvi.szCSDVersion[1] == 'A' ) sVersion += _T("SE " ); } else if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90) { sVersion = _T("Microsoft Windows Millennium Edition"); } else { sVersion = string_format(_T("[? Windows9x %d.%d] "), osvi.dwMajorVersion, osvi.dwMinorVersion); } break; case VER_PLATFORM_WIN32s: sVersion = _T("Microsoft Win32s\r\n"); break; default: sVersion = string_format(_T(" [? Windows? %d.%d] "), osvi.dwMajorVersion, osvi.dwMinorVersion); } return sVersion; }
void GL1TextureProvider::to_opengl_textureformat(TextureFormat format, GLint &gl_internal_format, GLenum &gl_pixel_format) { switch (format) { // base internal format // sized internal format // TODO: Should this really be here? case tf_stencil_index1: gl_internal_format = GL_STENCIL_INDEX1; gl_pixel_format = GL_STENCIL_INDEX; break; case tf_stencil_index4: gl_internal_format = GL_STENCIL_INDEX4; gl_pixel_format = GL_STENCIL_INDEX; break; case tf_stencil_index8: gl_internal_format = GL_STENCIL_INDEX8; gl_pixel_format = GL_STENCIL_INDEX; break; case tf_stencil_index16: gl_internal_format = GL_STENCIL_INDEX16; gl_pixel_format = GL_STENCIL_INDEX; break; //case tf_r8: gl_internal_format = GL_R8; gl_pixel_format = GL_RED; break; //case tf_r8_snorm: gl_internal_format = GL_R8_SNORM; gl_pixel_format = GL_RED; break; //case tf_r16: gl_internal_format = GL_R16; gl_pixel_format = GL_RED; break; //case tf_r16_snorm: gl_internal_format = GL_R16_SNORM; gl_pixel_format = GL_RED; break; //case tf_rg8: gl_internal_format = GL_RG8; gl_pixel_format = GL_RG; break; //case tf_rg8_snorm: gl_internal_format = GL_RG8_SNORM; gl_pixel_format = GL_RG; break; //case tf_rg16: gl_internal_format = GL_RG16; gl_pixel_format = GL_RG; break; //case tf_rg16_snorm: gl_internal_format = GL_RG16_SNORM; gl_pixel_format = GL_RG; break; case tf_r3_g3_b2: gl_internal_format = GL_R3_G3_B2; gl_pixel_format = GL_RGB; break; case tf_rgb4: gl_internal_format = GL_RGB4; gl_pixel_format = GL_RGB; break; case tf_rgb5: gl_internal_format = GL_RGB5; gl_pixel_format = GL_RGB; break; case tf_rgb8: gl_internal_format = GL_RGB8; gl_pixel_format = GL_RGB; break; case tf_rgb10: gl_internal_format = GL_RGB10; gl_pixel_format = GL_RGB; break; case tf_rgb12: gl_internal_format = GL_RGB12; gl_pixel_format = GL_RGB; break; case tf_rgb16: gl_internal_format = GL_RGB16; gl_pixel_format = GL_RGB; break; //case tf_rgb16_snorm: gl_internal_format = GL_RGB16_SNORM; gl_pixel_format = GL_RGB; break; case tf_rgba2: gl_internal_format = GL_RGBA2; gl_pixel_format = GL_RGBA; break; case tf_rgba4: gl_internal_format = GL_RGBA4; gl_pixel_format = GL_RGBA; break; case tf_rgb5_a1: gl_internal_format = GL_RGB5_A1; gl_pixel_format = GL_RGBA; break; case tf_rgba8: gl_internal_format = GL_RGBA8; gl_pixel_format = GL_RGBA; break; case tf_bgra8: gl_internal_format = GL_RGBA8; gl_pixel_format = GL_BGRA; break; case tf_bgr8: gl_internal_format = GL_RGB8; gl_pixel_format = GL_BGR; break; //case tf_rgba8_snorm: gl_internal_format = GL_RGBA8_SNORM; gl_pixel_format = GL_RGBA; break; case tf_rgb10_a2: gl_internal_format = GL_RGB10_A2; gl_pixel_format = GL_RGBA; break; case tf_rgba12: gl_internal_format = GL_RGBA12; gl_pixel_format = GL_RGBA; break; case tf_rgba16: gl_internal_format = GL_RGBA16; gl_pixel_format = GL_RGBA; break; //case tf_rgba16_snorm: gl_internal_format = GL_RGBA16_SNORM; gl_pixel_format = GL_RGBA; break; //case tf_srgb8: gl_internal_format = GL_SRGB8; gl_pixel_format = GL_RGB; break; //case tf_srgb8_alpha8: gl_internal_format = GL_SRGB8_ALPHA8; gl_pixel_format = GL_RGBA; break; //case tf_r16f: gl_internal_format = GL_R16F; gl_pixel_format = GL_RED; break; //case tf_rg16f: gl_internal_format = GL_RG16F; gl_pixel_format = GL_RG; break; //case tf_rgb16f: gl_internal_format = GL_RGB16F; gl_pixel_format = GL_RGB; break; //case tf_rgba16f: gl_internal_format = GL_RGBA16F; gl_pixel_format = GL_RGBA; break; //case tf_r32f: gl_internal_format = GL_R32F; gl_pixel_format = GL_RED; break; //case tf_rg32f: gl_internal_format = GL_RG32F; gl_pixel_format = GL_RG; break; //case tf_rgb32f: gl_internal_format = GL_RGB32F; gl_pixel_format = GL_RGB; break; //case tf_rgba32f: gl_internal_format = GL_RGBA32F; gl_pixel_format = GL_RGBA; break; //case tf_r11f_g11f_b10f: gl_internal_format = GL_R11F_G11F_B10F; gl_pixel_format = GL_RGB; break; //case tf_rgb9_e5: gl_internal_format = GL_RGB9_E5; gl_pixel_format = GL_RGB; break; //case tf_r8i: gl_internal_format = GL_R8I; gl_pixel_format = GL_RED; break; //case tf_r8ui: gl_internal_format = GL_R8UI; gl_pixel_format = GL_RED; break; //case tf_r16i: gl_internal_format = GL_R16I; gl_pixel_format = GL_RED; break; //case tf_r16ui: gl_internal_format = GL_R16UI; gl_pixel_format = GL_RED; break; //case tf_r32i: gl_internal_format = GL_R32I; gl_pixel_format = GL_RED; break; //case tf_r32ui: gl_internal_format = GL_R32UI; gl_pixel_format = GL_RED; break; //case tf_rg8i: gl_internal_format = GL_RG8I; gl_pixel_format = GL_RG; break; //case tf_rg8ui: gl_internal_format = GL_RG8UI; gl_pixel_format = GL_RG; break; //case tf_rg16i: gl_internal_format = GL_RG16I; gl_pixel_format = GL_RG; break; //case tf_rg16ui: gl_internal_format = GL_RG16UI; gl_pixel_format = GL_RG; break; //case tf_rg32i: gl_internal_format = GL_RG32I; gl_pixel_format = GL_RG; break; //case tf_rg32ui: gl_internal_format = GL_RG32UI; gl_pixel_format = GL_RG; break; //case tf_rgb8i: gl_internal_format = GL_RGB8I; gl_pixel_format = GL_RGB; break; //case tf_rgb8ui: gl_internal_format = GL_RGB8UI; gl_pixel_format = GL_RGB; break; //case tf_rgb16i: gl_internal_format = GL_RGB16I; gl_pixel_format = GL_RGB; break; //case tf_rgb16ui: gl_internal_format = GL_RGB16UI; gl_pixel_format = GL_RGB; break; //case tf_rgb32i: gl_internal_format = GL_RGB32I; gl_pixel_format = GL_RGB; break; //case tf_rgb32ui: gl_internal_format = GL_RGB32UI; gl_pixel_format = GL_RGB; break; //case tf_rgba8i: gl_internal_format = GL_RGBA8I; gl_pixel_format = GL_RGBA; break; //case tf_rgba8ui: gl_internal_format = GL_RGBA8UI; gl_pixel_format = GL_RGBA; break; //case tf_rgba16i: gl_internal_format = GL_RGBA16I; gl_pixel_format = GL_RGBA; break; //case tf_rgba16ui: gl_internal_format = GL_RGBA16UI; gl_pixel_format = GL_RGBA; break; //case tf_rgba32i: gl_internal_format = GL_RGBA32I; gl_pixel_format = GL_RGBA; break; //case tf_rgba32ui: gl_internal_format = GL_RGBA32UI; gl_pixel_format = GL_RGBA; break; case tf_depth_component16: gl_internal_format = GL_DEPTH_COMPONENT16; gl_pixel_format = GL_DEPTH_COMPONENT; break; case tf_depth_component24: gl_internal_format = GL_DEPTH_COMPONENT24; gl_pixel_format = GL_DEPTH_COMPONENT; break; case tf_depth_component32: gl_internal_format = GL_DEPTH_COMPONENT32; gl_pixel_format = GL_DEPTH_COMPONENT; break; //case tf_depth_component32f: gl_internal_format = GL_DEPTH_COMPONENT32F; gl_pixel_format = GL_DEPTH_COMPONENT; break; //case tf_depth24_stencil8: gl_internal_format = GL_DEPTH24_STENCIL8; gl_pixel_format = GL_DEPTH_STENCIL; break; //case tf_depth32f_stencil8: gl_internal_format = GL_DEPTH32F_STENCIL8; gl_pixel_format = GL_DEPTH_STENCIL; break; //case tf_compressed_red: gl_internal_format = GL_COMPRESSED_RED; gl_pixel_format = GL_RED; break; //case tf_compressed_rg: gl_internal_format = GL_COMPRESSED_RG; gl_pixel_format = GL_RG; break; case tf_compressed_rgb: gl_internal_format = GL_COMPRESSED_RGB; gl_pixel_format = GL_RGB; break; case tf_compressed_rgba: gl_internal_format = GL_COMPRESSED_RGBA; gl_pixel_format = GL_RGBA; break; //case tf_compressed_srgb: gl_internal_format = GL_COMPRESSED_SRGB; gl_pixel_format = GL_RGB; break; //case tf_compressed_srgb_alpha: gl_internal_format = GL_COMPRESSED_SRGB_ALPHA; gl_pixel_format = GL_RGBA; break; //case tf_compressed_red_rgtc1: gl_internal_format = GL_COMPRESSED_RED_RGTC1; gl_pixel_format = GL_RED; break; //case tf_compressed_signed_red_rgtc1: gl_internal_format = GL_COMPRESSED_SIGNED_RED_RGTC1; gl_pixel_format = GL_RED; break; //case tf_compressed_rg_rgtc2: gl_internal_format = GL_COMPRESSED_RG_RGTC2; gl_pixel_format = GL_RG; break; //case tf_compressed_signed_rg_rgtc2: gl_internal_format = GL_COMPRESSED_SIGNED_RG_RGTC2; gl_pixel_format = GL_RG; break; case tf_compressed_rgb_s3tc_dxt1: gl_internal_format = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; gl_pixel_format = GL_RGB; break; case tf_compressed_rgba_s3tc_dxt1: gl_internal_format = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; gl_pixel_format = GL_RGBA; break; case tf_compressed_rgba_s3tc_dxt3: gl_internal_format = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; gl_pixel_format = GL_RGBA; break; case tf_compressed_rgba_s3tc_dxt5: gl_internal_format = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; gl_pixel_format = GL_RGBA; break; //case tf_compressed_srgb_s3tc_dxt1: gl_internal_format = GL_COMPRESSED_SRGB_S3TC_DXT1_EXT; gl_pixel_format = GL_RGB; break; //case tf_compressed_srgb_alpha_s3tc_dxt1: gl_internal_format = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; gl_pixel_format = GL_RGBA; break; //case tf_compressed_srgb_alpha_s3tc_dxt3: gl_internal_format = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; gl_pixel_format = GL_RGBA; break; //case tf_compressed_srgb_alpha_s3tc_dxt5: gl_internal_format = GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; gl_pixel_format = GL_RGBA; break; default: throw Exception(string_format("Unsupported TextureFormat (%1)", format)); } }
BodyDescription::BodyDescription(const PhysicsContext &pc, const std::string &resource_id, const XMLResourceDocument &resources) : impl(new BodyDescription_Impl(pc.impl->get_owner())) { /* example resource entry with all parameters: <body2d name="TestBody" type="static"> <position x="0" y="0"/> <rotation angle="180"/> <velocity x="0" y="0" angular="0"/> <damping linear="0" angular="0"/> <parameters awake="true" can_sleep="true" bullet="false" active="true" /> </body2d> */ XMLResourceNode resource = resources.get_resource(resource_id); if (resource.get_type() != "body2d" && resource.get_type() != "body2d_description") throw Exception(string_format("Resource '%1' is not of type 'body2d' or 'body2d_description'", resource_id)); DomNode cur_node = resource.get_element().get_first_child(); //Body type std::string body_type = resource.get_element().get_attribute("type","static"); if(body_type == "kinematic") set_type(body_kinematic); else if(body_type == "dynamic") set_type(body_dynamic); else set_type(body_static); while(!cur_node.is_null()) { if (!cur_node.is_element()) continue; DomElement cur_element = cur_node.to_element(); std::string tag_name = cur_element.get_tag_name(); //<position x="0" y="0"/> if(tag_name == "position") { float pos_x = 0.0f; float pos_y = 0.0f; if(cur_element.has_attribute("x")) { pos_x = StringHelp::text_to_float(cur_element.get_attribute("x")); } if(cur_element.has_attribute("y")) { pos_y = StringHelp::text_to_float(cur_element.get_attribute("y")); } set_position(pos_x, pos_y); } //<rotation angle="180"/> else if(tag_name == "rotation") { Angle angle(0.0f, angle_degrees); if(cur_element.has_attribute("angle")) { angle = Angle(StringHelp::text_to_float(cur_element.get_attribute("angle")), angle_degrees); } set_angle(angle); } //<velocity x="0" y="0" angular="0"/> else if(tag_name == "velocity") { Vec2f velocity(0.0f, 0.0f); Angle angular_velocity(0.0f, angle_degrees); if(cur_element.has_attribute("x")) { velocity.x = StringHelp::text_to_float(cur_element.get_attribute("x")); } if(cur_element.has_attribute("y")) { velocity.y = StringHelp::text_to_float(cur_element.get_attribute("y")); } if(cur_element.has_attribute("angular")) { angular_velocity = Angle(StringHelp::text_to_float(cur_element.get_attribute("angular")), angle_degrees); } set_linear_velocity(velocity); set_angular_velocity(angular_velocity); } //<damping linear="0" angular="0"/> else if(tag_name == "damping") { float linear; float angular; if(cur_element.has_attribute("linear")) { linear = StringHelp::text_to_float(cur_element.get_attribute("linear")); } if(cur_element.has_attribute("angular")) { angular = StringHelp::text_to_float(cur_element.get_attribute("angular")); } set_linear_damping(linear); set_angular_damping(angular); } //<parameters awake="true" can_sleep="true" bullet="false" active="true" /> else if(tag_name == "parameters") { bool value; if(cur_element.has_attribute("awake")) { value = true; value = StringHelp::text_to_bool(cur_element.get_attribute("awake")); set_awake(value); } if(cur_element.has_attribute("active")) { value = true; value = StringHelp::text_to_bool(cur_element.get_attribute("active")); set_active(value); } if(cur_element.has_attribute("bullet")) { value = false; value = StringHelp::text_to_bool(cur_element.get_attribute("bullet")); set_as_bullet(value); } if(cur_element.has_attribute("can_sleep")) { value = true; value = StringHelp::text_to_bool(cur_element.get_attribute("can_sleep")); allow_sleep(value); } } cur_node = cur_node.get_next_sibling(); } }
void CBasicBlock::Compile() { #ifndef AOT_USE_CACHE Framework::CMemStream stream; { static __declspec(thread) CMipsJitter* jitter = NULL; if(jitter == NULL) { Jitter::CCodeGen* codeGen = Jitter::CreateCodeGen(); jitter = new CMipsJitter(codeGen); for(unsigned int i = 0; i < 4; i++) { jitter->SetVariableAsConstant( offsetof(CMIPS, m_State.nGPR[CMIPS::R0].nV[i]), 0 ); } } jitter->SetStream(&stream); jitter->Begin(); CompileRange(jitter); // codeGen.DumpVariables(0); // codeGen.EndQuota(); jitter->End(); } m_function = CMemoryFunction(stream.GetBuffer(), stream.GetSize()); #ifdef VTUNE_ENABLED if(iJIT_IsProfilingActive() == iJIT_SAMPLING_ON) { iJIT_Method_Load jmethod = {}; jmethod.method_id = iJIT_GetNewMethodID(); jmethod.class_file_name = ""; jmethod.source_file_name = __FILE__; jmethod.method_load_address = m_function.GetCode(); jmethod.method_size = m_function.GetSize(); jmethod.line_number_size = 0; auto functionName = string_format("BasicBlock_0x%0.8X_0x%0.8X", m_begin, m_end); jmethod.method_name = const_cast<char*>(functionName.c_str()); iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, reinterpret_cast<void*>(&jmethod)); } #endif #endif #ifdef AOT_ENABLED size_t blockSize = ((m_end - m_begin) / 4) + 1; auto blockData = new uint32[blockSize]; for(uint32 i = 0; i < blockSize; i++) { blockData[i] = m_context.m_pMemoryMap->GetWord(m_begin + (i * 4)); } uint32 blockChecksum = crc32(0, reinterpret_cast<Bytef*>(blockData), blockSize * 4); #endif #ifdef AOT_USE_CACHE AOT_BLOCK* blocksBegin = &_aot_firstBlock; AOT_BLOCK* blocksEnd = blocksBegin + _aot_blockCount; AOT_BLOCK blockRef = { blockChecksum, m_begin, m_end, nullptr }; static const auto blockComparer = [] (const AOT_BLOCK& item1, const AOT_BLOCK& item2) { return item1.key < item2.key; }; // assert(std::is_sorted(blocksBegin, blocksEnd, blockComparer)); bool blockExists = std::binary_search(blocksBegin, blocksEnd, blockRef, blockComparer); auto blockIterator = std::lower_bound(blocksBegin, blocksEnd, blockRef, blockComparer); assert(blockExists); assert(blockIterator != blocksEnd); assert(blockIterator->key.crc == blockChecksum); assert(blockIterator->key.begin == m_begin); assert(blockIterator->key.end == m_end); m_function = reinterpret_cast<void (*)(void*)>(blockIterator->fct); #endif #ifdef AOT_BUILD_CACHE { std::lock_guard<std::mutex> lock(m_aotBlockOutputStreamMutex); m_aotBlockOutputStream->Write32(blockChecksum); m_aotBlockOutputStream->Write32(m_begin); m_aotBlockOutputStream->Write32(m_end); m_aotBlockOutputStream->Write(blockData, blockSize * 4); } #endif }
Font &CSSResourceCache::get_font(Canvas &canvas, const CSSComputedValues &properties) { const CSSComputedFont &font_values = properties.get_font(); int font_size = used_to_actual(font_values.font_size.length.value); std::string font_name; for (size_t i = 0; i < font_values.font_family.names.size(); i++) { bool matched = false; std::string search_name; switch (font_values.font_family.names[i].type) { case CSSValueFontFamilyName::type_family_name: search_name = StringHelp::text_to_lower(font_values.font_family.names[i].name); if (font_families.find(search_name) != font_families.end()) { font_name = font_values.font_family.names[i].name; matched = true; } break; default: case CSSValueFontFamilyName::type_serif: case CSSValueFontFamilyName::type_cursive: case CSSValueFontFamilyName::type_fantasy: font_name = "Times New Roman"; // Ugliest font on the planet. matched = true; break; case CSSValueFontFamilyName::type_sans_serif: font_name = "Arial"; matched = true; break; case CSSValueFontFamilyName::type_monospace: font_name = "Courier New"; matched = true; break; } if (matched) break; } if (font_name.empty()) font_name = "Times New Roman"; int font_weight = 400; switch (font_values.font_weight.type) { case CSSValueFontWeight::type_100: font_weight = 100; break; case CSSValueFontWeight::type_200: font_weight = 200; break; case CSSValueFontWeight::type_300: font_weight = 300; break; case CSSValueFontWeight::type_400: font_weight = 400; break; case CSSValueFontWeight::type_500: font_weight = 500; break; case CSSValueFontWeight::type_600: font_weight = 600; break; case CSSValueFontWeight::type_700: font_weight = 700; break; case CSSValueFontWeight::type_800: font_weight = 800; break; case CSSValueFontWeight::type_900: font_weight = 900; break; case CSSValueFontWeight::type_normal: font_weight = 400; break; case CSSValueFontWeight::type_bold: font_weight = 700; break; case CSSValueFontWeight::type_bolder: font_weight = 900; break; case CSSValueFontWeight::type_lighter: font_weight = 300; break; } bool italic = false; switch (font_values.font_style.type) { case CSSValueFontStyle::type_normal: italic = false; break; case CSSValueFontStyle::type_italic: italic = true; break; case CSSValueFontStyle::type_oblique: italic = true; break; } std::string font_cache_name = string_format("%1+++%2+%3", font_name, font_size, font_weight); if (italic) font_cache_name += "i"; std::map<std::string, Font>::iterator it = font_cache.find(font_cache_name); if (it == font_cache.end()) { FontDescription font_desc; font_desc.set_typeface_name(font_name); font_desc.set_height(-font_size); font_desc.set_weight(font_weight); font_desc.set_italic(italic); font_cache[font_cache_name] = Font(canvas, font_desc); return font_cache[font_cache_name]; } else { return it->second; } }
bool game::dump_stats( const std::string& what, dump_mode mode, const std::vector<std::string> &opts ) { try { load_core_data(); } catch( const std::exception &err ) { std::cerr << "Error loading data from json: " << err.what() << std::endl; return false; } DynamicDataLoader::get_instance().finalize_loaded_data(); std::vector<std::string> header; std::vector<std::vector<std::string>> rows; int scol = 0; // sorting column std::map<std::string, standard_npc> test_npcs; test_npcs[ "S1" ] = standard_npc( "S1", { "gloves_survivor", "mask_lsurvivor" }, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ ); test_npcs[ "S2" ] = standard_npc( "S2", { "gloves_fingerless", "sunglasses" }, 4, 8, 8, 8, 10 /* PER 10 */ ); test_npcs[ "S3" ] = standard_npc( "S3", { "gloves_plate", "helmet_plate" }, 4, 10, 8, 8, 8 /* STAT 10 */ ); test_npcs[ "S4" ] = standard_npc( "S4", {}, 0, 8, 10, 8, 10 /* DEX 10, PER 10 */ ); test_npcs[ "S5" ] = standard_npc( "S5", {}, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ ); test_npcs[ "S6" ] = standard_npc( "S6", { "gloves_hsurvivor", "mask_hsurvivor" }, 4, 8, 10, 8, 10 /* DEX 10, PER 10 */ ); std::map<std::string, item> test_items; test_items[ "G1" ] = item( "glock_19" ).ammo_set( "9mm" ); test_items[ "G2" ] = item( "hk_mp5" ).ammo_set( "9mm" ); test_items[ "G3" ] = item( "ar15" ).ammo_set( "223" ); test_items[ "G4" ] = item( "remington_700" ).ammo_set( "270" ); test_items[ "G4" ].emplace_back( "rifle_scope" ); if( what == "AMMO" ) { header = { "Name", "Ammo", "Volume", "Weight", "Stack", "Range", "Dispersion", "Recoil", "Damage", "Pierce" }; auto dump = [&rows]( const item& obj ) { std::vector<std::string> r; r.push_back( obj.tname( 1, false ) ); r.push_back( obj.type->ammo->type.str() ); r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) ); r.push_back( to_string( obj.weight() ) ); r.push_back( to_string( obj.type->stack_size ) ); r.push_back( to_string( obj.type->ammo->range ) ); r.push_back( to_string( obj.type->ammo->dispersion ) ); r.push_back( to_string( obj.type->ammo->recoil ) ); r.push_back( to_string( obj.type->ammo->damage ) ); r.push_back( to_string( obj.type->ammo->pierce ) ); rows.push_back( r ); }; for( auto& e : item_controller->get_all_itypes() ) { if( e.second->ammo ) { dump( item( e.first, calendar::turn, item::solitary_tag {} ) ); } } } else if( what == "ARMOR" ) { header = { "Name", "Encumber (fit)", "Warmth", "Weight", "Storage", "Coverage", "Bash", "Cut", "Acid", "Fire" }; auto dump = [&rows]( const item& obj ) { std::vector<std::string> r; r.push_back( obj.tname( 1, false ) ); r.push_back( to_string( obj.get_encumber() ) ); r.push_back( to_string( obj.get_warmth() ) ); r.push_back( to_string( obj.weight() ) ); r.push_back( to_string( obj.get_storage() / units::legacy_volume_factor ) ); r.push_back( to_string( obj.get_coverage() ) ); r.push_back( to_string( obj.bash_resist() ) ); r.push_back( to_string( obj.cut_resist() ) ); r.push_back( to_string( obj.acid_resist() ) ); r.push_back( to_string( obj.fire_resist() ) ); rows.push_back( r ); }; body_part bp = opts.empty() ? num_bp : get_body_part_token( opts.front() ); for( auto& e : item_controller->get_all_itypes() ) { if( e.second->armor ) { item obj( e.first ); if( bp == num_bp || obj.covers( bp ) ) { if( obj.has_flag( "VARSIZE" ) ) { obj.item_tags.insert( "FIT" ); } dump( obj ); } } } } else if( what == "EDIBLE" ) { header = { "Name", "Volume", "Weight", "Stack", "Calories", "Quench", "Healthy" }; for( const auto& v : vitamin::all() ) { header.push_back( v.second.name() ); } auto dump = [&rows,&test_npcs]( const item& obj ) { std::vector<std::string> r; r.push_back( obj.tname( false ) ); r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) ); r.push_back( to_string( obj.weight() ) ); r.push_back( to_string( obj.type->stack_size ) ); r.push_back( to_string( obj.type->comestible->get_calories() ) ); r.push_back( to_string( obj.type->comestible->quench ) ); r.push_back( to_string( obj.type->comestible->healthy ) ); auto vits = g->u.vitamins_from( obj ); for( const auto& v : vitamin::all() ) { r.push_back( to_string( vits[ v.first ] ) ); } rows.push_back( r ); }; for( auto& e : item_controller->get_all_itypes() ) { if( e.second->comestible && ( e.second->comestible->comesttype == "FOOD" || e.second->comestible->comesttype == "DRINK" ) ) { item food( e.first, calendar::turn, item::solitary_tag {} ); if( g->u.can_eat( food, false, true ) == EDIBLE ) { dump( food ); } } } } else if( what == "GUN" ) { header = { "Name", "Ammo", "Volume", "Weight", "Capacity", "Range", "Dispersion", "Effective recoil", "Damage", "Pierce", "Aim time", "Effective range", "Snapshot range", "Max range" }; std::set<std::string> locations; for( const auto& e : item_controller->get_all_itypes() ) { if( e.second->gun ) { std::transform( e.second->gun->valid_mod_locations.begin(), e.second->gun->valid_mod_locations.end(), std::inserter( locations, locations.begin() ), []( const std::pair<std::string, int>& e ) { return e.first; } ); } } for( const auto &e : locations ) { header.push_back( e ); } auto dump = [&rows,&locations]( const standard_npc &who, const item& obj ) { std::vector<std::string> r; r.push_back( obj.tname( 1, false ) ); r.push_back( obj.ammo_type() ? obj.ammo_type().str() : "" ); r.push_back( to_string( obj.volume() / units::legacy_volume_factor ) ); r.push_back( to_string( obj.weight() ) ); r.push_back( to_string( obj.ammo_capacity() ) ); r.push_back( to_string( obj.gun_range() ) ); r.push_back( to_string( obj.gun_dispersion() ) ); r.push_back( to_string( obj.gun_recoil( who ) ) ); r.push_back( to_string( obj.gun_damage() ) ); r.push_back( to_string( obj.gun_pierce() ) ); r.push_back( to_string( who.gun_engagement_moves( obj ) ) ); r.push_back( string_format( "%.1f", who.gun_engagement_range( obj, player::engagement::effective ) ) ); r.push_back( string_format( "%.1f", who.gun_engagement_range( obj, player::engagement::snapshot ) ) ); r.push_back( string_format( "%.1f", who.gun_engagement_range( obj, player::engagement::maximum ) ) ); for( const auto &e : locations ) { r.push_back( to_string( obj.type->gun->valid_mod_locations[ e ] ) ); } rows.push_back( r ); }; for( const auto& e : item_controller->get_all_itypes() ) { if( e.second->gun ) { item gun( e.first ); if( !gun.magazine_integral() ) { gun.emplace_back( gun.magazine_default() ); } gun.ammo_set( default_ammo( gun.ammo_type() ), gun.ammo_capacity() ); dump( test_npcs[ "S1" ], gun ); if( gun.type->gun->barrel_length > 0 ) { gun.emplace_back( "barrel_small" ); dump( test_npcs[ "S1" ], gun ); } } } } else if( what == "VEHICLE" ) { header = { "Name", "Weight (empty)", "Weight (fueled)", "Max velocity (mph)", "Safe velocity (mph)", "Acceleration (mph/turn)", "Mass coeff %", "Aerodynamics coeff %", "Friction coeff %", "Traction coeff % (grass)" }; auto dump = [&rows]( const vproto_id& obj ) { auto veh_empty = vehicle( obj, 0, 0 ); auto veh_fueled = vehicle( obj, 100, 0 ); std::vector<std::string> r; r.push_back( veh_empty.name ); r.push_back( to_string( veh_empty.total_mass() ) ); r.push_back( to_string( veh_fueled.total_mass() ) ); r.push_back( to_string( veh_fueled.max_velocity() / 100 ) ); r.push_back( to_string( veh_fueled.safe_velocity() / 100 ) ); r.push_back( to_string( veh_fueled.acceleration() / 100 ) ); r.push_back( to_string( (int)( 100 * veh_fueled.k_mass() ) ) ); r.push_back( to_string( (int)( 100 * veh_fueled.k_aerodynamics() ) ) ); r.push_back( to_string( (int)( 100 * veh_fueled.k_friction() ) ) ); r.push_back( to_string( (int)( 100 * veh_fueled.k_traction( veh_fueled.wheel_area( false ) / 2.0f ) ) ) ); rows.push_back( r ); }; for( auto& e : vehicle_prototype::get_all() ) { dump( e ); } } else if( what == "VPART" ) { header = { "Name", "Location", "Weight", "Size" }; auto dump = [&rows]( const vpart_info *obj ) { std::vector<std::string> r; r.push_back( obj->name() ); r.push_back( obj->location ); r.push_back( to_string( int( ceil( item( obj->item ).weight() / 1000.0 ) ) ) ); r.push_back( to_string( obj->size / units::legacy_volume_factor ) ); rows.push_back( r ); }; for( const auto e : vpart_info::get_all() ) { dump( e ); } } else if( what == "AIMING" ) { scol = -1; // unsorted output so graph columns have predictable ordering const int cycles = 1400; header = { "Name" }; for( int i = 0; i <= cycles; ++i ) { header.push_back( to_string( i ) ); } auto dump = [&rows]( const standard_npc &who, const item &gun) { std::vector<std::string> r( 1, string_format( "%s %s", who.get_name().c_str(), gun.tname().c_str() ) ); double penalty = MIN_RECOIL; for( int i = 0; i <= cycles; ++i ) { penalty -= who.aim_per_move( gun, penalty ); r.push_back( string_format( "%.2f", who.gun_current_range( gun, penalty ) ) ); } rows.push_back( r ); }; if( opts.empty() ) { dump( test_npcs[ "S1" ], test_items[ "G1" ] ); dump( test_npcs[ "S1" ], test_items[ "G2" ] ); dump( test_npcs[ "S1" ], test_items[ "G3" ] ); dump( test_npcs[ "S1" ], test_items[ "G4" ] ); } else { for( const auto &str : opts ) { auto idx = str.find( ':' ); if( idx == std::string::npos ) { std::cerr << "cannot parse test case: " << str << std::endl; return false; } auto test = std::make_pair( test_npcs.find( str.substr( 0, idx ) ), test_items.find( str.substr( idx + 1 ) ) ); if( test.first == test_npcs.end() || test.second == test_items.end() ) { std::cerr << "invalid test case: " << str << std::endl; return false; } dump( test.first->second, test.second->second ); } } } else if( what == "EXPLOSIVE" ) { header = { // @todo Should display more useful data: shrapnel damage, safe range "Name", "Power", "Power at 5 tiles", "Power halves at", "Shrapnel count", "Shrapnel mass" }; auto dump = [&rows]( const std::string &name, const explosion_data &ex ) { std::vector<std::string> r; r.push_back( name ); r.push_back( to_string( ex.power ) ); r.push_back( string_format( "%.1f", ex.power_at_range( 5.0f ) ) ); r.push_back( string_format( "%.1f", ex.expected_range( 0.5f ) ) ); r.push_back( to_string( ex.shrapnel.count ) ); r.push_back( to_string( ex.shrapnel.mass ) ); rows.push_back( r ); }; for( const auto& e : item_controller->get_all_itypes() ) { const auto &itt = *e.second; const auto use = itt.get_use( "explosion" ); if( use != nullptr && use->get_actor_ptr() != nullptr ) { const auto actor = dynamic_cast<const explosion_iuse *>( use->get_actor_ptr() ); if( actor != nullptr ) { dump( itt.nname( 1 ), actor->explosion ); } } auto c_ex = dynamic_cast<const explosion_iuse *>( itt.countdown_action.get_actor_ptr() ); if( c_ex != nullptr ) { dump( itt.nname( 1 ), c_ex->explosion ); } } } else { std::cerr << "unknown argument: " << what << std::endl; return false; } rows.erase( std::remove_if( rows.begin(), rows.end(), []( const std::vector<std::string>& e ) { return e.empty(); } ), rows.end() ); if( scol >= 0 ) { std::sort( rows.begin(), rows.end(), [&scol]( const std::vector<std::string>& lhs, const std::vector<std::string>& rhs ) { return lhs[ scol ] < rhs[ scol ]; } ); } rows.erase( std::unique( rows.begin(), rows.end() ), rows.end() ); switch( mode ) { case dump_mode::TSV: rows.insert( rows.begin(), header ); for( const auto& r : rows ) { std::copy( r.begin(), r.end() - 1, std::ostream_iterator<std::string>( std::cout, "\t" ) ); std::cout << r.back() << "\n"; } break; case dump_mode::HTML: std::cout << "<table>"; std::cout << "<thead>"; std::cout << "<tr>"; for( const auto& col : header ) { std::cout << "<th>" << col << "</th>"; } std::cout << "</tr>"; std::cout << "</thead>"; std::cout << "<tdata>"; for( const auto& r : rows ) { std::cout << "<tr>"; for( const auto& col : r ) { std::cout << "<td>" << col << "</td>"; } std::cout << "</tr>"; } std::cout << "</tdata>"; std::cout << "</table>"; break; } return true; }
/* * Set skill on any player object; player character or NPC */ void game::wishskill(player * p) { const int skoffset = 1; uimenu skmenu; skmenu.text = "Select a skill to modify"; skmenu.return_invalid = true; skmenu.addentry(0, true, '1', "Set all skills to..."); int *origskills = new int[Skill::skills.size()] ; for (std::vector<Skill*>::iterator aSkill = Skill::skills.begin(); aSkill != Skill::skills.end(); ++aSkill) { int skill_id = (*aSkill)->id(); skmenu.addentry( skill_id + skoffset, true, -2, "@ %d: %s ", (int)p->skillLevel(*aSkill), (*aSkill)->ident().c_str() ); origskills[skill_id] = (int)p->skillLevel(*aSkill); } do { skmenu.query(); int skill_id = -1; int skset = -1; int sksel = skmenu.selected - skoffset; if ( skmenu.ret == -1 && ( skmenu.keypress == KEY_LEFT || skmenu.keypress == KEY_RIGHT ) ) { if ( sksel >= 0 && sksel < Skill::skills.size() ) { skill_id = sksel; skset = (int)p->skillLevel( Skill::skills[skill_id]) + ( skmenu.keypress == KEY_LEFT ? -1 : 1 ); } skmenu.ret = -2; } else if ( skmenu.selected == skmenu.ret && sksel >= 0 && sksel < Skill::skills.size() ) { skill_id = sksel; uimenu sksetmenu; sksetmenu.w_x = skmenu.w_x + skmenu.w_width + 1; sksetmenu.w_y = skmenu.w_y + 2; sksetmenu.w_height = skmenu.w_height - 4; sksetmenu.return_invalid = true; sksetmenu.settext( "Set '%s' to..", Skill::skills[skill_id]->ident().c_str() ); int skcur = (int)p->skillLevel(Skill::skills[skill_id]); sksetmenu.selected = skcur; for ( int i = 0; i < 21; i++ ) { sksetmenu.addentry( i, true, i + 48, "%d%s", i, (skcur == i ? " (current)" : "") ); } sksetmenu.query(); skset = sksetmenu.ret; } if ( skset != UIMENU_INVALID && skset != -1 && skill_id != -1 ) { p->skillLevel( Skill::skills[skill_id] ).level(skset); skmenu.textformatted[0] = string_format("%s set to %d ", Skill::skills[skill_id]->ident().c_str(), (int)p->skillLevel(Skill::skills[skill_id])).substr(0,skmenu.w_width - 4); skmenu.entries[skill_id + skoffset].txt = string_format("@ %d: %s ", (int)p->skillLevel( Skill::skills[skill_id]), Skill::skills[skill_id]->ident().c_str() ); skmenu.entries[skill_id + skoffset].text_color = ( (int)p->skillLevel(Skill::skills[skill_id]) == origskills[skill_id] ? skmenu.text_color : c_yellow ); } else if ( skmenu.ret == 0 && sksel == -1 ) { int ret = menu(true, "Set all skills...", "+3","+1","-1","-3","To 0","To 5","To 10","(Reset changes)",NULL); if ( ret > 0 ) { int skmod = 0; int skset = -1; if (ret < 5 ) { skmod=( ret < 3 ? ( ret == 1 ? 3 : 1 ) : ( ret == 3 ? -1 : -3 ) ); } else if ( ret < 8 ) { skset=( ( ret - 5 ) * 5 ); } for (int skill_id = 0; skill_id < Skill::skills.size(); skill_id++ ) { int changeto = ( skmod != 0 ? p->skillLevel( Skill::skills[skill_id] ) + skmod : ( skset != -1 ? skset : origskills[skill_id] ) ); p->skillLevel( Skill::skills[skill_id] ).level( changeto ); skmenu.entries[skill_id + skoffset].txt = string_format("@ %d: %s ", (int)p->skillLevel(Skill::skills[skill_id]), Skill::skills[skill_id]->ident().c_str() ); skmenu.entries[skill_id + skoffset].text_color = ( (int)p->skillLevel(Skill::skills[skill_id]) == origskills[skill_id] ? skmenu.text_color : c_yellow ); } } } } while ( skmenu.ret != -1 && ( skmenu.keypress != 'q' && skmenu.keypress != ' ' && skmenu.keypress != KEY_ESCAPE ) ); delete[] origskills; }
int game::inv_for_tools_powered_by( const ammotype &battery_id, const std::string &title ) { return inv_for_filter( title, [ &battery_id ]( const item & it ) { return it.is_tool() && it.ammo_type() == battery_id; }, string_format( _( "You don't have %s-powered tools." ), ammo_name( battery_id ).c_str() ) ); }
void player::power_mutations() { std::vector <std::string> passive; std::vector <std::string> active; for( auto &mut : my_mutations ) { if (!mutation_branch::get( mut.first ).activated) { passive.push_back(mut.first); } else { active.push_back(mut.first); } // New mutations are initialized with no key at all, so we have to do this here. if( mut.second.key == ' ' ) { for( const auto &letter : inv_chars ) { if( trait_by_invlet( letter ).empty() ) { mut.second.key = letter; break; } } } } // maximal number of rows in both columns const int mutations_count = std::max(passive.size(), active.size()); int TITLE_HEIGHT = 2; int DESCRIPTION_HEIGHT = 5; // Main window /** Total required height is: * top frame line: + 1 * height of title window: + TITLE_HEIGHT * line after the title: + 1 * line with active/passive mutation captions: + 1 * height of the biggest list of active/passive mutations: + mutations_count * line before mutation description: + 1 * height of description window: + DESCRIPTION_HEIGHT * bottom frame line: + 1 * TOTAL: TITLE_HEIGHT + mutations_count + DESCRIPTION_HEIGHT + 5 */ int HEIGHT = std::min(TERMY, std::max(FULL_SCREEN_HEIGHT, TITLE_HEIGHT + mutations_count + DESCRIPTION_HEIGHT + 5)); int WIDTH = FULL_SCREEN_WIDTH + (TERMX - FULL_SCREEN_WIDTH) / 2; int START_X = (TERMX - WIDTH) / 2; int START_Y = (TERMY - HEIGHT) / 2; WINDOW *wBio = newwin(HEIGHT, WIDTH, START_Y, START_X); // Description window @ the bottom of the bio window int DESCRIPTION_START_Y = START_Y + HEIGHT - DESCRIPTION_HEIGHT - 1; int DESCRIPTION_LINE_Y = DESCRIPTION_START_Y - START_Y - 1; WINDOW *w_description = newwin(DESCRIPTION_HEIGHT, WIDTH - 2, DESCRIPTION_START_Y, START_X + 1); // Title window int TITLE_START_Y = START_Y + 1; int HEADER_LINE_Y = TITLE_HEIGHT + 1; // + lines with text in titlebar, local WINDOW *w_title = newwin(TITLE_HEIGHT, WIDTH - 2, TITLE_START_Y, START_X + 1); int scroll_position = 0; int second_column = 32 + (TERMX - FULL_SCREEN_WIDTH) / 4; // X-coordinate of the list of active mutations input_context ctxt("MUTATIONS"); ctxt.register_updown(); ctxt.register_action("ANY_INPUT"); ctxt.register_action("TOGGLE_EXAMINE"); ctxt.register_action("REASSIGN"); ctxt.register_action("HELP_KEYBINDINGS"); bool redraw = true; std::string menu_mode = "activating"; while(true) { // offset for display: mutation with index i is drawn at y=list_start_y+i // drawing the mutation starts with mutation[scroll_position] const int list_start_y = HEADER_LINE_Y + 2 - scroll_position; int max_scroll_position = HEADER_LINE_Y + 2 + mutations_count - ((menu_mode == "examining") ? DESCRIPTION_LINE_Y : (HEIGHT - 1)); if(redraw) { redraw = false; werase(wBio); draw_border(wBio); // Draw line under title mvwhline(wBio, HEADER_LINE_Y, 1, LINE_OXOX, WIDTH - 2); // Draw symbols to connect additional lines to border mvwputch(wBio, HEADER_LINE_Y, 0, BORDER_COLOR, LINE_XXXO); // |- mvwputch(wBio, HEADER_LINE_Y, WIDTH - 1, BORDER_COLOR, LINE_XOXX); // -| // Captions mvwprintz(wBio, HEADER_LINE_Y + 1, 2, c_ltblue, _("Passive:")); mvwprintz(wBio, HEADER_LINE_Y + 1, second_column, c_ltblue, _("Active:")); draw_exam_window(wBio, DESCRIPTION_LINE_Y, menu_mode == "examining"); nc_color type; if (passive.empty()) { mvwprintz(wBio, list_start_y, 2, c_ltgray, _("None")); } else { for (size_t i = scroll_position; i < passive.size(); i++) { const auto &md = mutation_branch::get( passive[i] ); const auto &td = my_mutations[passive[i]]; if (list_start_y + static_cast<int>(i) == (menu_mode == "examining" ? DESCRIPTION_LINE_Y : HEIGHT - 1)) { break; } type = c_cyan; mvwprintz(wBio, list_start_y + i, 2, type, "%c %s", td.key, md.name.c_str()); } } if (active.empty()) { mvwprintz(wBio, list_start_y, second_column, c_ltgray, _("None")); } else { for (size_t i = scroll_position; i < active.size(); i++) { const auto &md = mutation_branch::get( active[i] ); const auto &td = my_mutations[active[i]]; if (list_start_y + static_cast<int>(i) == (menu_mode == "examining" ? DESCRIPTION_LINE_Y : HEIGHT - 1)) { break; } if (!td.powered) { type = c_red; }else if (td.powered) { type = c_ltgreen; } else { type = c_ltred; } // TODO: track resource(s) used and specify mvwputch( wBio, list_start_y + i, second_column, type, td.key ); std::stringstream mut_desc; mut_desc << md.name; if ( md.cost > 0 && md.cooldown > 0 ) { mut_desc << string_format( _(" - %d RU / %d turns"), md.cost, md.cooldown ); } else if ( md.cost > 0 ) { mut_desc << string_format( _(" - %d RU"), md.cost ); } else if ( md.cooldown > 0 ) { mut_desc << string_format( _(" - %d turns"), md.cooldown ); } if ( td.powered ) { mut_desc << _(" - Active"); } mvwprintz( wBio, list_start_y + i, second_column + 2, type, mut_desc.str().c_str() ); } } // Scrollbar if(scroll_position > 0) { mvwputch(wBio, HEADER_LINE_Y + 2, 0, c_ltgreen, '^'); } if(scroll_position < max_scroll_position && max_scroll_position > 0) { mvwputch(wBio, (menu_mode == "examining" ? DESCRIPTION_LINE_Y : HEIGHT - 1) - 1, 0, c_ltgreen, 'v'); } } wrefresh(wBio); show_mutations_titlebar(w_title, this, menu_mode); const std::string action = ctxt.handle_input(); const long ch = ctxt.get_raw_input().get_first_input(); if (menu_mode == "reassigning") { menu_mode = "activating"; const auto mut_id = trait_by_invlet( ch ); if( mut_id.empty() ) { // Selected an non-existing mutation (or escape, or ...) continue; } redraw = true; const char newch = popup_getkey(_("%s; enter new letter."), mutation_branch::get_name( mut_id ).c_str()); wrefresh(wBio); if(newch == ch || newch == ' ' || newch == KEY_ESCAPE) { continue; } const auto other_mut_id = trait_by_invlet( newch ); // if there is already a mutation with the new key, the key // is considered valid. if( other_mut_id.empty() && inv_chars.find(newch) == std::string::npos ) { // TODO separate list of letters for mutations popup(_("%c is not a valid inventory letter."), newch); continue; } if( !other_mut_id.empty() ) { std::swap(my_mutations[mut_id].key, my_mutations[other_mut_id].key); } else { my_mutations[mut_id].key = newch; } // TODO: show a message like when reassigning a key to an item? } else if (action == "DOWN") { if(scroll_position < max_scroll_position) { scroll_position++; redraw = true; } } else if (action == "UP") { if(scroll_position > 0) { scroll_position--; redraw = true; } } else if (action == "REASSIGN") { menu_mode = "reassigning"; } else if (action == "TOGGLE_EXAMINE") { // switches between activation and examination menu_mode = menu_mode == "activating" ? "examining" : "activating"; werase(w_description); draw_exam_window(wBio, DESCRIPTION_LINE_Y, false); redraw = true; }else if (action == "HELP_KEYBINDINGS") { redraw = true; } else { const auto mut_id = trait_by_invlet( ch ); if( mut_id.empty() ) { // entered a key that is not mapped to any mutation, // -> leave screen break; } const auto &mut_data = mutation_branch::get( mut_id ); if (menu_mode == "activating") { if (mut_data.activated) { if (my_mutations[mut_id].powered) { add_msg(m_neutral, _("You stop using your %s."), mut_data.name.c_str()); deactivate_mutation( mut_id ); delwin(w_title); delwin(w_description); delwin(wBio); // Action done, leave screen break; } else if( (!mut_data.hunger || hunger <= 400) && (!mut_data.thirst || thirst <= 400) && (!mut_data.fatigue || fatigue <= 400) ) { // this will clear the mutations menu for targeting purposes werase(wBio); wrefresh(wBio); delwin(w_title); delwin(w_description); delwin(wBio); g->draw(); add_msg( m_neutral, _("You activate your %s."), mut_data.name.c_str() ); activate_mutation( mut_id ); // Action done, leave screen break; } else { popup( _( "You don't have enough in you to activate your %s!" ), mut_data.name.c_str() ); redraw = true; continue; } } else { popup(_("\ You cannot activate %s! To read a description of \ %s, press '!', then '%c'."), mut_data.name.c_str(), mut_data.name.c_str(), my_mutations[mut_id].key ); redraw = true; } } if (menu_mode == "examining") { // Describing mutations, not activating them! draw_exam_window(wBio, DESCRIPTION_LINE_Y, true); // Clear the lines first werase(w_description); fold_and_print(w_description, 0, 0, WIDTH - 2, c_ltblue, mut_data.description); wrefresh(w_description); } } } //if we activated a mutation, already killed the windows if(!(menu_mode == "activating")) { werase(wBio); wrefresh(wBio); delwin(w_title); delwin(w_description); delwin(wBio); } }
void sam6883_device::sam_space<_addrstart, _addrend>::point_specific_bank(const sam_bank *bank, uint32_t offset, uint32_t length, memory_bank *&memory_bank, uint32_t addrstart, uint32_t addrend, bool is_write) { if (bank->m_memory != nullptr) { // this bank is a memory bank - first lets adjust the length as per the offset; as // passed to this method, the length is from offset zero if (length != ~0) length -= std::min(offset, length); // do we even have a bank? and if so, have legit changes occured? if (!memory_bank || !memory_bank->matches_exactly(addrstart, addrend) || (length != m_length)) { // name the bank auto tag = string_format("bank%04X_%c", addrstart, is_write ? 'w' : 'r'); // determine "nop_addrstart" - where the bank ends, and above which is AM_NOP uint32_t nop_addrstart = (length != ~0) ? std::min(addrend + 1, addrstart + length) : addrend + 1; // install the bank if (is_write) { if (addrstart < nop_addrstart) cpu_space().install_write_bank(addrstart, nop_addrstart - 1, 0, tag.c_str()); if (nop_addrstart <= addrend) cpu_space().nop_write(nop_addrstart, addrend); } else { if (addrstart < nop_addrstart) cpu_space().install_read_bank(addrstart, nop_addrstart - 1, 0, tag.c_str()); if (nop_addrstart <= addrend) cpu_space().nop_read(nop_addrstart, addrend); } m_length = length; // and get it memory_bank = cpu_space().device().owner()->membank(tag.c_str()); } // point the bank if (memory_bank != nullptr) { if (is_write && bank->m_memory_read_only) memory_bank->set_base(m_owner.m_dummy); else memory_bank->set_base(bank->m_memory + offset); } } else { // this bank uses handlers - first thing's first, assert that we are not doing // any weird stuff with offfsets and lengths - that isn't supported in this path assert((offset == 0) && (length == (uint32_t)~0)); if (is_write) { if (!bank->m_whandler.isnull()) cpu_space().install_write_handler(addrstart, addrend, bank->m_whandler); } else { if (!bank->m_rhandler.isnull()) cpu_space().install_read_handler(addrstart, addrend, bank->m_rhandler); } } }
int game::inv_for_id( const itype_id &id, const std::string &title ) { return inv_for_filter( title, [ &id ]( const item &it ) { return it.typeId() == id; }, string_format( _( "You don't have a %s." ), item::nname( id ).c_str() ) ); }
std::string item_comp::to_string( int batch ) const { const int c = std::abs( count ) * batch; //~ <item-count> <item-name> return string_format( ngettext( "%d %s", "%d %s", c ), c, item::nname( type, c ).c_str() ); }
std::string quality_requirement::to_string( int ) const { return string_format( ngettext( "%d tool with %s of %d or more.", "%d tools with %s of %d or more.", count ), count, type.obj().name.c_str(), level ); }
Font Font::load(Canvas &canvas, const std::string &family_name, const FontDescription &reference_desc, FontFamily &font_family, const XMLResourceDocument &doc, std::function<Resource<Sprite>(Canvas &, const std::string &)> cb_get_sprite) { DomElement font_element; XMLResourceNode resource; resource = doc.get_resource(family_name); font_element = resource.get_element(); DomElement sprite_element = font_element.named_item("sprite").to_element(); if (!sprite_element.is_null()) { if (!sprite_element.has_attribute("glyphs")) throw Exception(string_format("Font resource %1 has no 'glyphs' attribute.", resource.get_name())); if (!sprite_element.has_attribute("letters")) throw Exception(string_format("Font resource %1 has no 'letters' attribute.", resource.get_name())); if (!cb_get_sprite) throw Exception(string_format("Font resource %1 requires a sprite loader callback specified.", resource.get_name())); Resource<Sprite> spr_glyphs = cb_get_sprite(canvas, sprite_element.get_attribute("glyphs")); const std::string &letters = sprite_element.get_attribute("letters"); int spacelen = StringHelp::text_to_int(sprite_element.get_attribute("spacelen", "-1")); bool monospace = StringHelp::text_to_bool(sprite_element.get_attribute("monospace", "false")); // Modify the default font metrics, if specified float height = 0.0f; float line_height = 0.0f; float ascent = 0.0f; float descent = 0.0f; float internal_leading = 0.0f; float external_leading = 0.0f; if (sprite_element.has_attribute("height")) height = StringHelp::text_to_float(sprite_element.get_attribute("height", "0")); if (sprite_element.has_attribute("line_height")) line_height = StringHelp::text_to_float(sprite_element.get_attribute("line_height", "0")); if (sprite_element.has_attribute("ascent")) ascent = StringHelp::text_to_float(sprite_element.get_attribute("ascent", "0")); if (sprite_element.has_attribute("descent")) descent = StringHelp::text_to_float(sprite_element.get_attribute("descent", "0")); if (sprite_element.has_attribute("internal_leading")) internal_leading = StringHelp::text_to_float(sprite_element.get_attribute("internal_leading", "0")); if (sprite_element.has_attribute("external_leading")) external_leading = StringHelp::text_to_float(sprite_element.get_attribute("external_leading", "0")); FontMetrics font_metrics(height, ascent, descent, internal_leading, external_leading, line_height, canvas.get_pixel_ratio()); font_family.add(canvas, spr_glyphs.get(), letters, spacelen, monospace, font_metrics); FontDescription desc = reference_desc.clone(); return Font(font_family, desc); } DomElement ttf_element = font_element.named_item("ttf").to_element(); if (ttf_element.is_null()) ttf_element = font_element.named_item("freetype").to_element(); if (!ttf_element.is_null()) { FontDescription desc = reference_desc.clone(); std::string filename; if (ttf_element.has_attribute("file")) { filename = PathHelp::combine(resource.get_base_path(), ttf_element.get_attribute("file")); } if (!ttf_element.has_attribute("typeface")) throw Exception(string_format("Font resource %1 has no 'typeface' attribute.", resource.get_name())); std::string font_typeface_name = ttf_element.get_attribute("typeface"); if (ttf_element.has_attribute("height")) desc.set_height(ttf_element.get_attribute_int("height", 0)); if (ttf_element.has_attribute("average_width")) desc.set_average_width(ttf_element.get_attribute_int("average_width", 0)); if (ttf_element.has_attribute("anti_alias")) desc.set_anti_alias(ttf_element.get_attribute_bool("anti_alias", true)); if (ttf_element.has_attribute("subpixel")) desc.set_subpixel(ttf_element.get_attribute_bool("subpixel", true)); if (filename.empty()) { font_family.add(font_typeface_name, desc); return Font(font_family, desc); } else { font_family.add(desc, filename, resource.get_file_system()); return Font(font_family, desc); } } throw Exception(string_format("Font resource %1 did not have a <sprite> or <ttf> child element", resource.get_name())); }
void recipe_dictionary::load( JsonObject &jo, const std::string &src, bool uncraft ) { bool strict = src == "core"; recipe r; // defer entries dependent upon as-yet unparsed definitions if( jo.has_string( "copy-from" ) ) { auto base = jo.get_string( "copy-from" ); if( uncraft ) { if( !recipe_dict.uncraft.count( base ) ) { deferred.emplace_back( jo.str(), src ); return; } r = recipe_dict.uncraft[ base ]; } else { if( !recipe_dict.recipes.count( base ) ) { deferred.emplace_back( jo.str(), src ); return; } r = recipe_dict.recipes[ base ]; } } if( jo.has_string( "abstract" ) ) { r.ident_ = jo.get_string( "abstract" ); r.abstract = true; } else { r.ident_ = r.result = jo.get_string( "result" ); r.abstract = false; } if( !uncraft ) { if( jo.has_string( "id_suffix" ) ) { if( r.abstract ) { jo.throw_error( "abstract recipe cannot specify id_suffix", "id_suffix" ); } r.ident_ += "_" + jo.get_string( "id_suffix" ); } assign( jo, "category", r.category, strict ); assign( jo, "subcategory", r.subcategory, strict ); assign( jo, "reversible", r.reversible, strict ); } else { r.reversible = true; } assign( jo, "time", r.time, strict, 0 ); assign( jo, "difficulty", r.difficulty, strict, 0, MAX_SKILL ); assign( jo, "flags", r.flags ); // automatically set contained if we specify as container assign( jo, "contained", r.contained, strict ); r.contained |= assign( jo, "container", r.container, strict ); if( jo.has_array( "batch_time_factors" ) ) { auto batch = jo.get_array( "batch_time_factors" ); r.batch_rscale = batch.get_int( 0 ) / 100.0; r.batch_rsize = batch.get_int( 1 ); } assign( jo, "charges", r.charges ); assign( jo, "result_mult", r.result_mult ); assign( jo, "skill_used", r.skill_used, strict ); if( jo.has_member( "skills_required" ) ) { auto sk = jo.get_array( "skills_required" ); r.required_skills.clear(); if( sk.empty() ) { // clear all requirements } else if( sk.has_array( 0 ) ) { // multiple requirements while( sk.has_more() ) { auto arr = sk.next_array(); r.required_skills[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 ); } } else { // single requirement r.required_skills[skill_id( sk.get_string( 0 ) )] = sk.get_int( 1 ); } } // simplified autolearn sets requirements equal to required skills at finalization if( jo.has_bool( "autolearn" ) ) { assign( jo, "autolearn", r.autolearn ); } else if( jo.has_array( "autolearn" ) ) { r.autolearn = false; auto sk = jo.get_array( "autolearn" ); while( sk.has_more() ) { auto arr = sk.next_array(); r.autolearn_requirements[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 ); } } if( jo.has_member( "decomp_learn" ) ) { r.learn_by_disassembly.clear(); if( jo.has_int( "decomp_learn" ) ) { if( !r.skill_used ) { jo.throw_error( "decomp_learn specified with no skill_used" ); } assign( jo, "decomp_learn", r.learn_by_disassembly[r.skill_used] ); } else if( jo.has_array( "decomp_learn" ) ) { auto sk = jo.get_array( "decomp_learn" ); while( sk.has_more() ) { auto arr = sk.next_array(); r.learn_by_disassembly[skill_id( arr.get_string( 0 ) )] = arr.get_int( 1 ); } } } if( !uncraft && jo.has_member( "byproducts" ) ) { auto bp = jo.get_array( "byproducts" ); r.byproducts.clear(); while( bp.has_more() ) { auto arr = bp.next_array(); r.byproducts[ arr.get_string( 0 ) ] += arr.size() == 2 ? arr.get_int( 1 ) : 1; } } if( jo.has_member( "book_learn" ) ) { auto bk = jo.get_array( "book_learn" ); r.booksets.clear(); while( bk.has_more() ) { auto arr = bk.next_array(); r.booksets.emplace( arr.get_string( 0 ), arr.get_int( 1 ) ); } } // recipes not specifying any external requirements inherit from their parent recipe (if any) if( jo.has_string( "using" ) ) { r.reqs_external = { { requirement_id( jo.get_string( "using" ) ), 1 } }; } else if( jo.has_array( "using" ) ) { auto arr = jo.get_array( "using" ); r.reqs_external.clear(); while( arr.has_more() ) { auto cur = arr.next_array(); r.reqs_external.emplace_back( requirement_id( cur.get_string( 0 ) ), cur.get_int( 1 ) ); } } // inline requirements are always replaced (cannot be inherited) auto req_id = string_format( "inline_%s_%s", uncraft ? "uncraft" : "recipe", r.ident_.c_str() ); requirement_data::load_requirement( jo, req_id ); r.reqs_internal = { { requirement_id( req_id ), 1 } }; if( uncraft ) { recipe_dict.uncraft[ r.ident_ ] = r; } else { recipe_dict.recipes[ r.ident_ ] = r; } }
void game::wishmutate( player *p ) { uimenu wmenu; int c = 0; for( auto &traits_iter : mutation_branch::get_all() ) { wmenu.addentry( -1, true, -2, "%s", traits_iter.second.name.c_str() ); wmenu.entries[ c ].extratxt.left = 1; wmenu.entries[ c ].extratxt.txt = ""; wmenu.entries[ c ].extratxt.color = c_ltgreen; if( p->has_trait( traits_iter.first ) ) { wmenu.entries[ c ].text_color = c_green; if( p->has_base_trait( traits_iter.first ) ) { wmenu.entries[ c ].extratxt.txt = "T"; } } c++; } wmenu.w_x = 0; wmenu.w_width = TERMX; // disabled due to foldstring crash // ( TERMX - getmaxx(w_terrain) - 30 > 24 ? getmaxx(w_terrain) : TERMX ); wmenu.pad_right = ( wmenu.w_width - 40 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishmutate_selected; wish_mutate_callback *cb = new wish_mutate_callback(); cb->p = p; wmenu.callback = cb; do { wmenu.query(); if ( wmenu.ret >= 0 ) { int rc = 0; std::string mstr = cb->vTraits[ wmenu.ret ]; const auto &mdata = mutation_branch::get( mstr ); bool threshold = mdata.threshold; bool profession = mdata.profession; //Manual override for the threshold-gaining if (threshold || profession) { if ( p->has_trait( mstr ) ) { do { p->remove_mutation(mstr ); rc++; } while (p->has_trait( mstr ) && rc < 10); } else { do { p->set_mutation(mstr ); rc++; } while (!p->has_trait( mstr ) && rc < 10); } } else if ( p->has_trait( mstr ) ) { do { p->remove_mutation(mstr ); rc++; } while (p->has_trait( mstr ) && rc < 10); } else { do { p->mutate_towards(mstr ); rc++; } while (!p->has_trait( mstr ) && rc < 10); } cb->msg = string_format(_("%s Mutation changes: %d"), mstr.c_str(), rc); uistate.wishmutate_selected = wmenu.ret; if ( rc != 0 ) { for ( size_t i = 0; i < cb->vTraits.size(); i++ ) { wmenu.entries[ i ].extratxt.txt = ""; if ( p->has_trait( cb->vTraits[ i ] ) ) { wmenu.entries[ i ].text_color = c_green; cb->pTraits[ cb->vTraits[ i ] ] = true; if ( p->has_base_trait( cb->vTraits[ i ] ) ) { wmenu.entries[ i ].extratxt.txt = "T"; } } else { wmenu.entries[ i ].text_color = wmenu.text_color; cb->pTraits[ cb->vTraits[ i ] ] = false; } } } } } while ( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' ); delete cb; cb = NULL; return; }
iram void io_periodic(void) { const io_info_entry_t *info; io_data_entry_t *data; io_config_pin_entry_t *pin_config; io_data_pin_entry_t *pin_data; int io, pin, status_io, status_pin; io_flags_t flags = { .counter_triggered = 0 }; int value; status_io = config.status_trigger.io; status_pin = config.status_trigger.pin; for(io = 0; io < io_id_size; io++) { info = &io_info[io]; data = &io_data[io]; if(!data->detected) continue; if(info->periodic_fn) info->periodic_fn(io, info, data, &flags); for(pin = 0; pin < info->pins; pin++) { pin_config = &config.io_config[io][pin]; pin_data = &data->pin[pin]; switch(pin_config->mode) { case(io_pin_disabled): case(io_pin_input_digital): case(io_pin_counter): case(io_pin_output_digital): case(io_pin_input_analog): case(io_pin_i2c): case(io_pin_uart): case(io_pin_lcd): case(io_pin_error): { break; } case(io_pin_timer): { if((pin_data->direction != io_dir_none) && (pin_data->speed >= 10) && ((pin_data->speed -= 10) <= 0)) { switch(pin_data->direction) { case(io_dir_none): { break; } case(io_dir_up): { info->write_pin_fn((string_t *)0, info, pin_data, pin_config, pin, 1); pin_data->direction = io_dir_down; break; } case(io_dir_down): { info->write_pin_fn((string_t *)0, info, pin_data, pin_config, pin, 0); pin_data->direction = io_dir_up; break; } } if(pin_config->flags.repeat) pin_data->speed = pin_config->speed; else { pin_data->speed = 0; pin_data->direction = io_dir_none; } } break; } case(io_pin_trigger): { if((info->read_pin_fn((string_t *)0, info, pin_data, pin_config, pin, &value) == io_ok) && (value != 0)) { io_trigger_pin((string_t *)0, pin_config->shared.trigger.io.io, pin_config->shared.trigger.io.pin, pin_config->shared.trigger.trigger_mode); info->write_pin_fn((string_t *)0, info, pin_data, pin_config, pin, 0); } break; } case(io_pin_output_analog): { if((pin_config->shared.output_analog.upper_bound > pin_config->shared.output_analog.lower_bound) && (pin_config->speed > 0) && (pin_data->direction != io_dir_none)) io_trigger_pin_x((string_t *)0, info, pin_data, pin_config, pin, (pin_data->direction == io_dir_up) ? io_trigger_up : io_trigger_down); break; } } } } if((flags.counter_triggered) && (status_io >= 0) && (status_pin >= 0)) io_trigger_pin((string_t *)0, status_io, status_pin, io_trigger_on); } /* app commands */ irom app_action_t application_function_io_mode(const string_t *src, string_t *dst) { const io_info_entry_t *info; io_data_entry_t *data; io_config_pin_entry_t *pin_config; io_data_pin_entry_t *pin_data; io_pin_mode_t mode; io_pin_ll_mode_t llmode; int io, pin; if(parse_int(1, src, &io, 0) != parse_ok) { io_config_dump(dst, &config, -1, -1, false); return(app_action_normal); } if((io < 0) || (io >= io_id_size)) { string_format(dst, "invalid io %d\n", io); return(app_action_error); } info = &io_info[io]; data = &io_data[io]; if(!data->detected) { string_format(dst, "io %d not detected\n", io); return(app_action_error); } if(parse_int(2, src, &pin, 0) != parse_ok) { io_config_dump(dst, &config, io, -1, false); return(app_action_normal); } if((pin < 0) || (pin >= info->pins)) { string_cat(dst, "io pin out of range\n"); return(app_action_error); } pin_config = &config.io_config[io][pin]; pin_data = &data->pin[pin]; if(parse_string(3, src, dst) != parse_ok) { string_clear(dst); io_config_dump(dst, &config, io, pin, false); return(app_action_normal); } if((mode = io_mode_from_string(dst)) == io_pin_error) { string_copy(dst, "invalid mode\n"); return(app_action_error); } string_clear(dst); llmode = io_pin_ll_error; switch(mode) { case(io_pin_input_digital): { if(!info->caps.input_digital) { string_cat(dst, "digital input mode invalid for this io\n"); return(app_action_error); } llmode = io_pin_ll_input_digital; break; } case(io_pin_counter): { if(!info->caps.counter) { string_cat(dst, "counter mode invalid for this io\n"); return(app_action_error); } int debounce; if((parse_int(4, src, &debounce, 0) != parse_ok)) { string_cat(dst, "counter: <debounce ms>\n"); return(app_action_error); } pin_config->speed = debounce; llmode = io_pin_ll_counter; break; } case(io_pin_trigger): { int debounce, trigger_io, trigger_pin; io_trigger_t trigger_type; if(!info->caps.counter) { string_cat(dst, "trigger mode invalid for this io\n"); return(app_action_error); } if((parse_int(4, src, &debounce, 0) != parse_ok)) { string_cat(dst, "trigger: <debounce ms> <io> <pin> <action>\n"); return(app_action_error); } if((parse_int(5, src, &trigger_io, 0) != parse_ok)) { string_cat(dst, "trigger: <debounce ms> <io> <pin> <action>\n"); return(app_action_error); } if((parse_int(6, src, &trigger_pin, 0) != parse_ok)) { string_cat(dst, "trigger: <debounce ms> <io> <pin> <action>\n"); return(app_action_error); } if((parse_string(7, src, dst) != parse_ok)) { string_clear(dst); string_cat(dst, "trigger: <debounce ms> <io> <pin> <action>\n"); return(app_action_error); } trigger_type = string_to_trigger_type(dst); if(trigger_type == io_trigger_error) { string_clear(dst); string_cat(dst, "trigger: <io> <pin> <action>\n"); return(app_action_error); } string_clear(dst); pin_config->speed = debounce; pin_config->shared.trigger.io.io = trigger_io; pin_config->shared.trigger.io.pin = trigger_pin; pin_config->shared.trigger.trigger_mode = trigger_type; llmode = io_pin_ll_counter; break; } case(io_pin_output_digital): { if(!info->caps.output_digital) { string_cat(dst, "digital output mode invalid for this io\n"); return(app_action_error); } llmode = io_pin_ll_output_digital; break; } case(io_pin_timer): { io_direction_t direction; int speed; if(!info->caps.output_digital) { string_cat(dst, "timer mode invalid for this io\n"); return(app_action_error); } if(parse_string(4, src, dst) != parse_ok) { string_copy(dst, "timer: <direction>:up/down <speed>:ms\n"); return(app_action_error); } if(string_match(dst, "up")) direction = io_dir_up; else if(string_match(dst, "down")) direction = io_dir_down; else { string_cat(dst, ": timer direction invalid\n"); return(app_action_error); } string_clear(dst); if((parse_int(5, src, &speed, 0) != parse_ok)) { string_copy(dst, "timer: <direction>:up/down <speed>:ms\n"); return(app_action_error); } if(speed < 10) { string_cat(dst, "timer: speed too small: must be >= 10 ms\n"); return(app_action_error); } pin_config->direction = direction; pin_config->speed = speed; llmode = io_pin_ll_output_digital; break; } case(io_pin_input_analog): { if(!info->caps.input_analog) { string_cat(dst, "analog input mode invalid for this io\n"); return(app_action_error); } llmode = io_pin_ll_input_analog; break; } case(io_pin_output_analog): { int lower_bound = 0; int upper_bound = 0; int speed = 0; if(!info->caps.output_analog) { string_cat(dst, "analog output mode invalid for this io\n"); return(app_action_error); } parse_int(4, src, &lower_bound, 0); parse_int(5, src, &upper_bound, 0); parse_int(6, src, &speed, 0); if((lower_bound < 0) || (lower_bound > 65535)) { string_format(dst, "outputa: lower bound out of range: %d\n", lower_bound); return(app_action_error); } if(upper_bound == 0) upper_bound = lower_bound; if((upper_bound < 0) || (upper_bound > 65535)) { string_format(dst, "outputa: upper bound out of range: %d\n", upper_bound); return(app_action_error); } if(upper_bound < lower_bound) { string_cat(dst, "upper bound below lower bound\n"); return(app_action_error); } if((speed < 0) || (speed > 65535)) { string_format(dst, "outputa: speed out of range: %d\n", speed); return(app_action_error); } pin_config->shared.output_analog.lower_bound = lower_bound; pin_config->shared.output_analog.upper_bound = upper_bound; pin_config->speed = speed; llmode = io_pin_ll_output_analog; break; } case(io_pin_i2c): { io_i2c_t pin_mode; if(!info->caps.i2c) { string_cat(dst, "i2c mode invalid for this io\n"); return(app_action_error); } if(parse_string(4, src, dst) != parse_ok) { string_copy(dst, "i2c: <pin mode>=sda|scl\n"); return(app_action_error); } if((pin_mode = io_i2c_pin_from_string(dst)) == io_i2c_error) { string_copy(dst, "i2c: <pin mode>=sda|scl\n"); return(app_action_error); } string_clear(dst); pin_config->shared.i2c.pin_mode = pin_mode; llmode = io_pin_ll_i2c; break; } case(io_pin_uart): { if(!info->caps.uart) { string_cat(dst, "uart mode invalid for this io\n"); return(app_action_error); } llmode = io_pin_ll_uart; break; } case(io_pin_lcd): { io_lcd_mode_t pin_mode; if(parse_string(4, src, dst) != parse_ok) { string_copy(dst, "lcd: <pin use>=rs|rw|e|d0|d1|d2|d3|d4|d5|d6|d7|bl\n"); return(app_action_error); } if((pin_mode = io_lcd_mode_from_string(dst)) == io_lcd_error) { string_copy(dst, "lcd: <pin use>=rs|rw|e|d0|d1|d2|d3|d4|d5|d6|d7|bl\n"); return(app_action_error); } string_clear(dst); if(pin_mode == io_lcd_bl) // backlight { if(info->caps.output_analog) llmode = io_pin_ll_output_analog; else if(info->caps.output_digital) llmode = io_pin_ll_output_digital; else { string_cat(dst, "analog/digital output mode invalid for this io\n"); return(app_action_error); } } else { if(!info->caps.output_digital) { string_cat(dst, "digital output mode invalid for this io\n"); return(app_action_error); } llmode = io_pin_ll_output_digital; } pin_config->shared.lcd.pin_use = pin_mode; break; } case(io_pin_disabled): { llmode = io_pin_ll_disabled; break; } case(io_pin_error): { llmode = io_pin_ll_error; string_cat(dst, "unsupported io mode\n"); return(app_action_error); } } if((mode == io_pin_error) || (llmode == io_pin_ll_error)) { string_cat(dst, "error\n"); return(app_action_error); } pin_config->mode = mode; pin_config->llmode = llmode; if(info->init_pin_mode_fn && (info->init_pin_mode_fn(dst, info, pin_data, pin_config, pin) != io_ok)) { pin_config->mode = io_pin_disabled; pin_config->llmode = io_pin_ll_disabled; return(app_action_error); } io_config_dump(dst, &config, io, pin, false); return(app_action_normal); } irom app_action_t application_function_io_read(const string_t *src, string_t *dst) { const io_info_entry_t *info; io_config_pin_entry_t *pin_config; int io, pin, value; if(parse_int(1, src, &io, 0) != parse_ok) { string_cat(dst, "io-read: <io> <pin>\n"); return(app_action_error); } if((io < 0) || (io >= io_id_size)) { string_format(dst, "invalid io %d\n", io); return(app_action_error); } info = &io_info[io]; if(parse_int(2, src, &pin, 0) != parse_ok) { string_cat(dst, "get: <io> <pin>\n"); return(app_action_error); } if((pin < 0) || (pin >= info->pins)) { string_cat(dst, "io pin out of range\n"); return(app_action_error); } pin_config = &config.io_config[io][pin]; io_string_from_mode(dst, pin_config->mode); if(pin_config->mode == io_pin_i2c) { string_cat(dst, "/"); io_string_from_i2c_type(dst, pin_config->shared.i2c.pin_mode); } if(pin_config->mode == io_pin_lcd) { string_cat(dst, "/"); io_string_from_lcd_mode(dst, pin_config->shared.lcd.pin_use); } string_cat(dst, ": "); if(io_read_pin(dst, io, pin, &value) != io_ok) return(app_action_error); string_format(dst, "[%d]\n", value); return(app_action_normal); } irom app_action_t application_function_io_write(const string_t *src, string_t *dst) { const io_info_entry_t *info; io_config_pin_entry_t *pin_config; int io, pin, value; if(parse_int(1, src, &io, 0) != parse_ok) { string_cat(dst, "io-write <io> <pin> <value>\n"); return(app_action_error); } if((io < 0) || (io >= io_id_size)) { string_format(dst, "invalid io %d\n", io); return(app_action_error); } info = &io_info[io]; if(parse_int(2, src, &pin, 0) != parse_ok) { string_cat(dst, "io-write <io> <pin> <value>\n"); return(app_action_error); } if((pin < 0) || (pin >= info->pins)) { string_cat(dst, "invalid pin\n"); return(app_action_error); } pin_config = &config.io_config[io][pin]; value = 0; parse_int(3, src, &value, 0); io_string_from_mode(dst, pin_config->mode); if(pin_config->mode == io_pin_lcd) { string_cat(dst, "/"); io_string_from_lcd_mode(dst, pin_config->shared.lcd.pin_use); } string_cat(dst, ": "); if(io_write_pin(dst, io, pin, value) != io_ok) { string_cat(dst, "\n"); return(app_action_error); } if(io_read_pin(dst, io, pin, &value) != io_ok) { string_cat(dst, "\n"); return(app_action_error); } string_format(dst, "[%d]\n", value); return(app_action_normal); } irom app_action_t application_function_io_trigger(const string_t *src, string_t *dst) { const io_info_entry_t *info; int io, pin; io_trigger_t trigger_type; if(parse_int(1, src, &io, 0) != parse_ok) goto usage; if((io < 0) || (io >= io_id_size)) { string_format(dst, "invalid io %d\n", io); return(app_action_error); } info = &io_info[io]; if(parse_int(2, src, &pin, 0) != parse_ok) goto usage; if((pin < 0) || (pin >= info->pins)) { string_cat(dst, "invalid pin\n"); return(app_action_error); } if(parse_string(3, src, dst) != parse_ok) goto usage; if((trigger_type = string_to_trigger_type(dst)) == io_trigger_error) goto usage; string_clear(dst); string_cat(dst, "trigger "); trigger_type_to_string(trigger_type, dst); string_format(dst, " %u/%u: ", io, pin); if(io_trigger_pin(dst, io, pin, trigger_type) != io_ok) { string_cat(dst, "\n"); return(app_action_error); } string_cat(dst, "ok\n"); return(app_action_normal); usage: string_clear(dst); string_cat(dst, "io-trigger <io> <pin> <action> (action = off/on/down/up)\n"); return(app_action_error); } irom static app_action_t application_function_io_clear_set_flag(const string_t *src, string_t *dst, int value) { const io_info_entry_t *info; io_data_entry_t *data; io_data_pin_entry_t *pin_data; io_config_pin_entry_t *pin_config; int io, pin; io_pin_flag_t saved_flags; if(parse_int(1, src, &io, 0) != parse_ok) { string_cat(dst, "io-flag <io> <pin> <flag>\n"); return(app_action_error); } if((io < 0) || (io >= io_id_size)) { string_format(dst, "invalid io %d\n", io); return(app_action_error); } info = &io_info[io]; data = &io_data[io]; if(parse_int(2, src, &pin, 0) != parse_ok) { string_cat(dst, "io-flag <io> <pin> <flag>\n"); return(app_action_error); } if((pin < 0) || (pin >= info->pins)) { string_cat(dst, "invalid pin\n"); return(app_action_error); } pin_data = &data->pin[pin]; pin_config = &config.io_config[io][pin]; saved_flags = pin_config->flags; if((parse_string(3, src, dst) == parse_ok) && !pin_flag_from_string(dst, pin_config, value)) { string_copy(dst, "io-flag <io> <pin> <flag>\n"); return(app_action_error); } if(pin_config->flags.pullup && !info->caps.pullup) { pin_config->flags = saved_flags; string_copy(dst, "io does not support pullup\n"); return(app_action_error); } if(info->init_pin_mode_fn && (info->init_pin_mode_fn(dst, info, pin_data, pin_config, pin) != io_ok)) { pin_config->flags = saved_flags; string_copy(dst, "cannot enable this flag\n"); return(app_action_error); } string_clear(dst); string_format(dst, "flags for pin %d/%d:", io, pin); pin_string_from_flags(dst, pin_config); string_cat(dst, "\n"); return(app_action_normal); } irom app_action_t application_function_io_set_flag(const string_t *src, string_t *dst) { return(application_function_io_clear_set_flag(src, dst, 1)); } irom app_action_t application_function_io_clear_flag(const string_t *src, string_t *dst) { return(application_function_io_clear_set_flag(src, dst, 0)); } /* dump */ typedef enum { ds_id_io, ds_id_pin, ds_id_flags_1, ds_id_flags_2, ds_id_mode, ds_id_disabled, ds_id_input, ds_id_counter, ds_id_trigger_1, ds_id_trigger_2, ds_id_output, ds_id_timer, ds_id_analog_output, ds_id_i2c_sda, ds_id_i2c_scl, ds_id_uart, ds_id_lcd, ds_id_unknown, ds_id_not_detected, ds_id_info_1, ds_id_info_2, ds_id_header, ds_id_footer, ds_id_preline, ds_id_postline, ds_id_error, ds_id_length, ds_id_invalid = ds_id_length } dump_string_id_t; typedef const char string_array_t[ds_id_length][256]; typedef struct { const string_array_t plain; const string_array_t html; } dump_string_t; static const roflash dump_string_t dump_strings = { .plain = { "io[%d]: %[email protected]%x", " pin: %2d", " flags:", ", ", "mode: ", "disabled", "input, state: %s", "counter, counter: %d, debounce: %d", "trigger, counter: %d, debounce: %d, io: %d, pin: %d, trigger type: ", "", "output, state: %s", "timer, config direction: %s, speed: %d ms, current direction: %s, delay: %d ms, state: %s", "analog output, min/static: %d, max: %d, current speed: %d, direction: %s, value: %d", "i2c/sda", "i2c/scl", "uart", "lcd", "unknown", " not found\n", ", info: ", "", "", "", "", "\n", "error", }, .html = { "<td>io[%d]</td><td>%[email protected]%x</td>", "<td></td><td>%d</td>", "<td>", "</td>", "", "<td>disabled</td>", "<td>input</td><td>state: %s</td>", "<td>counter</td><td><td>counter: %d</td><td>debounce: %d</td>", "<td>trigger</td><td>counter: %d</td><td>debounce: %d</td><td>io: %d</td><td>pin: %d</td><td>trigger type: ", "</td>", "<td>output</td><td>state: %s</td>", "<td>timer</td><td>config direction: %s, speed: %d ms</td><<td>current direction %s, delay: %d ms, state: %s</td>", "<td>analog output</td><td>min/static: %d, max: %d, speed: %d, current direction: %s, value: %d", "<td>i2c</td><td>sda</td>", "<td>i2c</td><td>scl, speed: %d</td>", "<td>uart</td>", "<td>lcd</td>", "<td>unknown</td>", "<td>not found</td>", "<td>", "</td>", "<table border=\"1\"><tr><th>index</th><th>name</th><th>mode</th><th colspan=\"8\"></th></tr>", "</table>\n", "<tr>", "</trd>\n", "<td>error</td>", } };
/* * Set skill on any player object; player character or NPC */ void game::wishskill(player *p) { const int skoffset = 1; uimenu skmenu; skmenu.text = _("Select a skill to modify"); skmenu.return_invalid = true; skmenu.addentry(0, true, '1', _("Modify all skills...")); std::vector<int> origskills; origskills.reserve(Skill::skills.size()); for (auto const &s : Skill::skills) { auto const level = static_cast<int>(p->skillLevel(s)); skmenu.addentry( origskills.size() + skoffset, true, -2, _( "@ %d: %s " ), level, s.name().c_str() ); origskills.push_back(level); } do { skmenu.query(); int skill_id = -1; int skset = -1; int sksel = skmenu.selected - skoffset; if ( skmenu.ret == -1 && ( skmenu.keypress == KEY_LEFT || skmenu.keypress == KEY_RIGHT ) ) { if ( sksel >= 0 && sksel < (int)Skill::skills.size() ) { skill_id = sksel; skset = (int)p->skillLevel( Skill::skills[skill_id] ) + ( skmenu.keypress == KEY_LEFT ? -1 : 1 ); } skmenu.ret = -2; } else if ( skmenu.selected == skmenu.ret && sksel >= 0 && sksel < (int)Skill::skills.size() ) { skill_id = sksel; uimenu sksetmenu; sksetmenu.w_x = skmenu.w_x + skmenu.w_width + 1; sksetmenu.w_y = skmenu.w_y + 2; sksetmenu.w_height = skmenu.w_height - 4; sksetmenu.return_invalid = true; sksetmenu.settext( _("Set '%s' to.."), Skill::skills[skill_id].ident().c_str() ); int skcur = (int)p->skillLevel(Skill::skills[skill_id]); sksetmenu.selected = skcur; for ( int i = 0; i < 21; i++ ) { sksetmenu.addentry( i, true, i + 48, "%d%s", i, (skcur == i ? _(" (current)") : "") ); } sksetmenu.query(); skset = sksetmenu.ret; } if ( skset != UIMENU_INVALID && skset != -1 && skill_id != -1 ) { p->skillLevel( Skill::skills[skill_id] ).level(skset); skmenu.textformatted[0] = string_format(_("%s set to %d "), Skill::skills[skill_id].ident().c_str(), (int)p->skillLevel(Skill::skills[skill_id])).substr(0, skmenu.w_width - 4); skmenu.entries[skill_id + skoffset].txt = string_format(_("@ %d: %s "), (int)p->skillLevel( Skill::skills[skill_id]), Skill::skills[skill_id].ident().c_str() ); skmenu.entries[skill_id + skoffset].text_color = ( (int)p->skillLevel(Skill::skills[skill_id]) == origskills[skill_id] ? skmenu.text_color : c_yellow ); } else if ( skmenu.ret == 0 && sksel == -1 ) { int ret = menu(true, _("Alter all skill values"), _("Add 3"), _("Add 1"), _("Subtract 1"), _("Subtract 3"), _("set to 0"), _("Set to 5"), _("Set to 10"), _("(Reset changes)"), NULL); if ( ret > 0 ) { int skmod = 0; int skset = -1; if (ret < 5 ) { skmod = ( ret < 3 ? ( ret == 1 ? 3 : 1 ) : ( ret == 3 ? -1 : -3 )); } else if ( ret < 8 ) { skset = ( ( ret - 5 ) * 5 ); } for (size_t skill_id = 0; skill_id < Skill::skills.size(); skill_id++ ) { int changeto = ( skmod != 0 ? p->skillLevel( Skill::skills[skill_id] ) + skmod : ( skset != -1 ? skset : origskills[skill_id] ) ); p->skillLevel( Skill::skills[skill_id] ).level( changeto ); skmenu.entries[skill_id + skoffset].txt = string_format(_("@ %d: %s "), (int)p->skillLevel(Skill::skills[skill_id]), Skill::skills[skill_id].ident().c_str() ); skmenu.entries[skill_id + skoffset].text_color = ( (int)p->skillLevel(Skill::skills[skill_id]) == origskills[skill_id] ? skmenu.text_color : c_yellow ); } } } } while ( skmenu.ret != -1 && ( skmenu.keypress != 'q' && skmenu.keypress != ' ' && skmenu.keypress != KEY_ESCAPE ) ); }
void game::wishmutate( player *p ) { uimenu wmenu; int c=0; for (std::map<std::string, trait>::iterator iter = traits.begin(); iter != traits.end(); ++iter) { wmenu.addentry(-1,true,-2,"%s",iter->second.name.c_str() ); wmenu.entries[ c ].extratxt.left=1; wmenu.entries[ c ].extratxt.txt=""; wmenu.entries[ c ].extratxt.color=c_ltgreen; if( p->has_trait( iter->first ) ) { wmenu.entries[ c ].text_color = c_green; if ( p->has_base_trait( iter->first ) ) { wmenu.entries[ c ].extratxt.txt="T"; } } c++; } wmenu.w_x = 0; wmenu.w_width = TERMX; // disabled due to foldstring crash // ( TERMX - getmaxx(w_terrain) - 30 > 24 ? getmaxx(w_terrain) : TERMX ); wmenu.pad_right = ( wmenu.w_width - 30 ); wmenu.return_invalid = true; wmenu.selected = uistate.wishmutate_selected; wish_mutate_callback *cb = new wish_mutate_callback(); cb->g=this; cb->p=p; wmenu.callback = cb; do { wmenu.query(); if ( wmenu.ret > 0 ) { int rc=0; std::string mstr=cb->vTraits[ wmenu.ret ]; if ( p->has_trait( mstr ) ) { do { p->remove_mutation(this, mstr ); rc++; } while (p->has_trait( mstr ) && rc < 10); } else { do { p->mutate_towards(this, mstr ); rc++; } while (!p->has_trait( mstr ) && rc < 10); } cb->msg=string_format("%s Mutation changes: %d",mstr.c_str(),rc); uistate.wishmutate_selected = wmenu.ret; if ( rc != 0 ) { for ( int i = 0; i < cb->vTraits.size(); i++ ) { wmenu.entries[ i ].extratxt.txt=""; if ( p->has_trait( cb->vTraits[ i ] ) ) { wmenu.entries[ i ].text_color = c_green; cb->pTraits[ cb->vTraits[ i ] ] = true; if ( p->has_base_trait( cb->vTraits[ i ] ) ) { wmenu.entries[ i ].extratxt.txt="T"; } } else { wmenu.entries[ i ].text_color = wmenu.text_color; cb->pTraits[ cb->vTraits[ i ] ] = false; } } } } } while ( wmenu.keypress != 'q' && wmenu.keypress != KEY_ESCAPE && wmenu.keypress != ' ' ); delete cb; cb = NULL; return; }
static int fakens_search(const uschar *domain, int type, uschar *answerptr, int size) { int len = Ustrlen(domain); int asize = size; /* Locally modified */ uschar name[256]; uschar utilname[256]; uschar *aptr = answerptr; /* Locally modified */ struct stat statbuf; /* Remove terminating dot. */ if (domain[len - 1] == '.') len--; Ustrncpy(name, domain, len); name[len] = 0; /* Look for the fakens utility, and if it exists, call it. */ (void)string_format(utilname, sizeof(utilname), "%s/bin/fakens", config_main_directory); if (stat(CS utilname, &statbuf) >= 0) { pid_t pid; int infd, outfd, rc; uschar *argv[5]; DEBUG(D_dns) debug_printf("DNS lookup of %s (%s) using fakens\n", name, dns_text_type(type)); argv[0] = utilname; argv[1] = config_main_directory; argv[2] = name; argv[3] = dns_text_type(type); argv[4] = NULL; pid = child_open(argv, NULL, 0000, &infd, &outfd, FALSE); if (pid < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "failed to run fakens: %s", strerror(errno)); len = 0; rc = -1; while (asize > 0 && (rc = read(outfd, aptr, asize)) > 0) { len += rc; aptr += rc; /* Don't modify the actual arguments, because they */ asize -= rc; /* may need to be passed on to res_search(). */ } /* If we ran out of output buffer before exhausting the return, carry on reading and counting it. */ if (asize == 0) while ((rc = read(outfd, name, sizeof(name))) > 0) len += rc; if (rc < 0) log_write(0, LOG_MAIN|LOG_PANIC_DIE, "read from fakens failed: %s", strerror(errno)); switch(child_close(pid, 0)) { case 0: return len; case 1: h_errno = HOST_NOT_FOUND; return -1; case 2: h_errno = TRY_AGAIN; return -1; default: case 3: h_errno = NO_RECOVERY; return -1; case 4: h_errno = NO_DATA; return -1; case 5: /* Pass on to res_search() */ DEBUG(D_dns) debug_printf("fakens returned PASS_ON\n"); } } else { DEBUG(D_dns) debug_printf("fakens (%s) not found\n", utilname); } /* fakens utility not found, or it returned "pass on" */ DEBUG(D_dns) debug_printf("passing %s on to res_search()\n", domain); return res_search(CS domain, C_IN, type, answerptr, size); }
std::string weather_forecast(radio_tower tower) { std::stringstream weather_report; // Local conditions city *closest_city = &g->cur_om->cities[g->cur_om->closest_city(point(tower.x, tower.y))]; // Current time weather_report << string_format( _("The current time is %s Eastern Standard Time. At %s in %s, it was %s. The temperature was %s"), g->turn.print_time().c_str(), g->turn.print_time(true).c_str(), closest_city->name.c_str(), weather_data[g->weather].name.c_str(), print_temperature(g->temperature).c_str() ); //weather_report << ", the dewpoint ???, and the relative humidity ???. "; //weather_report << "The wind was <direction> at ? mi/km an hour. "; //weather_report << "The pressure was ??? in/mm and steady/rising/falling."; // Regional conditions (simulated by chosing a random range containing the current conditions). // Adjusted for weather volatility based on how many weather changes are coming up. //weather_report << "Across <region>, skies ranged from <cloudiest> to <clearest>. "; // TODO: Add fake reports for nearby cities // TODO: weather forecast // forecasting periods are divided into 12-hour periods, day (6-18) and night (19-5) // Accumulate percentages for each period of various weather statistics, and report that // (with fuzz) as the weather chances. int weather_proportions[NUM_WEATHER_TYPES] = {0}; signed char high = 0; signed char low = 0; calendar start_time = g->turn; int period_start = g->turn.hours(); // TODO wind direction and speed for(std::map<int, weather_segment>::iterator it = g->weather_log.lower_bound( int(g->turn) ); it != g->weather_log.end(); ++it ) { weather_segment * period = &(it->second); int period_deadline = period->deadline.hours(); signed char period_temperature = period->temperature; weather_type period_weather = period->weather; bool start_day = period_start >= 6 && period_start <= 18; bool end_day = period_deadline >= 6 && period_deadline <= 18; high = std::max(high, period_temperature); low = std::min(low, period_temperature); if(start_day != end_day) // Assume a period doesn't last over 12 hrs? { weather_proportions[period_weather] += end_day ? 6 : 18 - period_start; int weather_duration = 0; int predominant_weather = 0; std::string day; if( g->turn.days() == period->deadline.days() ) { if( start_day ) { day = _("Today"); } else { day = _("Tonight"); } } else { std::string dayofweak = start_time.day_of_week(); if( !start_day ) { day = rmp_format(_("<Mon Night>%s Night"), dayofweak.c_str()); } else { day = dayofweak; } } for( int i = WEATHER_CLEAR; i < NUM_WEATHER_TYPES; i++) { if( weather_proportions[i] > weather_duration) { weather_duration = weather_proportions[i]; predominant_weather = i; } } // Print forecast weather_report << string_format( _("%s...%s. Highs of %s. Lows of %s. "), day.c_str(), weather_data[predominant_weather].name.c_str(), print_temperature(high).c_str(), print_temperature(low).c_str() ); low = period_temperature; high = period_temperature; weather_proportions[period_weather] += end_day ? 6 : 18 - period_start; } else { weather_proportions[period_weather] += period_deadline - period_start; } start_time = period->deadline; period_start = period_deadline; } return weather_report.str(); }
void mod_manager::load_modfile(JsonObject &jo, const std::string &main_path) { if (!jo.has_string("type") || jo.get_string("type") != "MOD_INFO") { // Ignore anything that is not a mod-info return; } std::string m_ident = jo.get_string("ident"); if (has_mod(m_ident)) { // TODO: change this to make unique ident for the mod // (instead of discarding it?) debugmsg("there is already a mod with ident %s", m_ident.c_str()); return; } if( jo.has_bool( "obsolete" ) ) { // Marked obsolete, no need to try to load anything else. MOD_INFORMATION *modfile = new MOD_INFORMATION; modfile->ident = m_ident; modfile->obsolete = true; mod_map[modfile->ident] = modfile; return; } std::string t_type = jo.get_string("mod-type", "SUPPLEMENTAL"); std::vector<std::string> m_authors; if (jo.has_array("authors")) { m_authors = jo.get_string_array("authors"); } else { if(jo.has_string("author")) { m_authors.push_back(jo.get_string("author")); } } std::string m_name = jo.get_string("name", ""); if (m_name.empty()) { // "No name" gets confusing if many mods have no name //~ name of a mod that has no name entry, (%s is the mods identifier) m_name = string_format(_("No name (%s)"), m_ident.c_str()); } else { m_name = _(m_name.c_str()); } std::string m_desc = jo.get_string("description", ""); if (m_desc.empty()) { m_desc = _("No description"); } else { m_desc = _(m_desc.c_str()); } std::string m_path; if (jo.has_string("path")) { m_path = jo.get_string("path"); if (m_path.empty()) { // If an empty path is given, use only the // folder of the modinfo.json m_path = main_path; } else { // prefix the folder of modinfo.json m_path = main_path + "/" + m_path; } } else { // Default if no path is given: // "<folder-of-modinfo.json>/data" m_path = main_path + "/data"; } std::vector<std::string> m_dependencies; if (jo.has_member("dependencies") && jo.has_array("dependencies")) { JsonArray jarr = jo.get_array("dependencies"); while(jarr.has_more()) { const std::string dep = jarr.next_string(); if (dep == m_ident) { debugmsg("mod %s has itself as dependency", m_ident.c_str()); continue; } if (std::find(m_dependencies.begin(), m_dependencies.end(), dep) != m_dependencies.end()) { // Some dependency listed twice, ignore it, what else can be done? continue; } m_dependencies.push_back(dep); } } mod_type m_type; if (t_type == "CORE") { m_type = MT_CORE; } else if (t_type == "SUPPLEMENTAL") { m_type = MT_SUPPLEMENTAL; } else { throw std::string("Invalid mod type: ") + t_type + " for mod " + m_ident; } MOD_INFORMATION *modfile = new MOD_INFORMATION; modfile->ident = m_ident; modfile->_type = m_type; modfile->authors = m_authors; modfile->name = m_name; modfile->description = m_desc; modfile->dependencies = m_dependencies; modfile->path = m_path; mod_map[modfile->ident] = modfile; }
void OpenGLWindowProvider::create(DisplayWindowSite *new_site, const DisplayWindowDescription &desc) { site = new_site; fullscreen = desc.is_fullscreen(); win32_window.create(site, desc); if (!opengl_context) { HWND handle = win32_window.get_hwnd(); dwm_layered = false; if (desc.is_layered() && !DwmFunctions::is_composition_enabled()) { create_shadow_window(handle); } else { if (desc.is_layered()) dwm_layered = true; } desc.is_layered() ? double_buffered = false : double_buffered = true; // Only can use Layered windows that are single buffered with OpenGL (via shadow window) ( PFD_DOUBLEBUFFER_DONTCARE set in OpenGLCreationHelper::set_multisampling_pixel_format) device_context = GetDC(handle); HGLRC share_context = get_share_context(); OpenGLCreationHelper helper(handle, device_context); helper.set_multisampling_pixel_format(desc); int gl_major = opengl_desc.get_version_major(); int gl_minor = opengl_desc.get_version_minor(); if (opengl_desc.get_allow_lower_versions() == false) { opengl_context = helper.create_opengl3_context(share_context, gl_major, gl_minor, opengl_desc); if (!opengl_context) throw Exception(string_format("This application requires OpenGL %1.%2 or above. Try updating your drivers, or upgrade to a newer graphics card.", gl_major, gl_minor)); } else { static const char opengl_version_list[] = { // Clanlib supported version pairs 4, 5, 4, 4, 4, 3, 4, 2, 4, 1, 4, 0, 3, 3, 3, 2, 3, 1, 3, 0, 0, 0, // End of list }; const char *opengl_version_list_ptr = opengl_version_list; do { int major = *(opengl_version_list_ptr++); if (major == 0) break; int minor = *(opengl_version_list_ptr++); // Find the appropriate version in the list if (major > gl_major) continue; if (major == gl_major) { if (minor > gl_minor) continue; } opengl_context = helper.create_opengl3_context(share_context, major, minor, opengl_desc); } while (!opengl_context); if (!opengl_context) opengl_context = helper.create_opengl2_context(share_context); if (!opengl_context) throw Exception("This application requires OpenGL. Try updating your drivers, or upgrade to a newer graphics card."); } bool use_gl3; int desc_version_major = opengl_desc.get_version_major(); int desc_version_minor = opengl_desc.get_version_minor(); // Do not attempt GL3, if not requested that version if (desc_version_major < 3) { use_gl3 = false; } else if (!opengl_desc.get_allow_lower_versions()) // Else, if we do not allow lower versions, only attempt GL3 { use_gl3 = true; } else { // Choose the target depending on the current opengl version int gl_version_major; int gl_version_minor; get_opengl_version(gl_version_major, gl_version_minor); if (gl_version_major < 3) { use_gl3 = false; } else { use_gl3 = true; } } if (use_gl3) { using_gl3 = true; gc = GraphicContext(new GL3GraphicContextProvider(this)); } else { using_gl3 = false; gc = GraphicContext(new GL1GraphicContextProvider(this)); } } wglSwapIntervalEXT = (ptr_wglSwapIntervalEXT)OpenGL::get_proc_address("wglSwapIntervalEXT"); swap_interval = desc.get_swap_interval(); if (wglSwapIntervalEXT && swap_interval != -1) wglSwapIntervalEXT(swap_interval); }
NetGameEventValue NetGameEvent::get_argument(unsigned int index) const { if (index >= arguments.size()) throw Exception(string_format("Arguments out of bounds for game event %1", name)); return arguments[index]; }
void mission_start::place_npc_software(game *g, mission *miss) { npc* dev = g->find_npc(miss->npc_id); if (dev == NULL) { debugmsg("Couldn't find NPC! %d", miss->npc_id); return; } g->u.i_add( item(g->itypes["usb_drive"], 0) ); g->add_msg(_("%s gave you a USB drive."), dev->name.c_str()); oter_id ter = ot_house_north; switch (dev->myclass) { case NC_HACKER: miss->item_id = "software_hacking"; break; case NC_DOCTOR: miss->item_id = "software_medical"; ter = ot_s_pharm_north; miss->follow_up = MISSION_GET_ZOMBIE_BLOOD_ANAL; break; case NC_SCIENTIST: miss->item_id = "software_math"; break; default: miss->item_id = "software_useless"; } int dist = 0; point place; if (ter == ot_house_north) { int city_id = g->cur_om->closest_city( g->om_location() ); place = g->cur_om->random_house_in_city(city_id); } else place = g->cur_om->find_closest(g->om_location(), ter, 4, dist, false); miss->target = place; // Make it seen on our map for (int x = place.x - 6; x <= place.x + 6; x++) { for (int y = place.y - 6; y <= place.y + 6; y++) g->cur_om->seen(x, y, 0) = true; } tinymap compmap(&(g->traps)); compmap.load(g, place.x * 2, place.y * 2, 0, false); point comppoint; switch (g->cur_om->ter(place.x, place.y, 0)) { case ot_house_north: case ot_house_east: case ot_house_west: case ot_house_south: { std::vector<point> valid; for (int x = 0; x < SEEX * 2; x++) { for (int y = 0; y < SEEY * 2; y++) { if (compmap.ter(x, y) == t_floor && compmap.furn(x, y) == f_null) { bool okay = false; for (int x2 = x - 1; x2 <= x + 1 && !okay; x2++) { for (int y2 = y - 1; y2 <= y + 1 && !okay; y2++) { if (compmap.furn(x2, y2) == f_bed || compmap.furn(x2, y2) == f_dresser) { okay = true; valid.push_back( point(x, y) ); } } } } } } if (valid.empty()) comppoint = point( rng(6, SEEX * 2 - 7), rng(6, SEEY * 2 - 7) ); else comppoint = valid[rng(0, valid.size() - 1)]; } break; case ot_s_pharm_north: { bool found = false; for (int x = SEEX * 2 - 1; x > 0 && !found; x--) { for (int y = SEEY * 2 - 1; y > 0 && !found; y--) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } break; case ot_s_pharm_east: { bool found = false; for (int x = 0; x < SEEX * 2 && !found; x++) { for (int y = SEEY * 2 - 1; y > 0 && !found; y--) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } break; case ot_s_pharm_south: { bool found = false; for (int x = 0; x < SEEX * 2 && !found; x++) { for (int y = 0; y < SEEY * 2 && !found; y++) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } break; case ot_s_pharm_west: { bool found = false; for (int x = SEEX * 2 - 1; x > 0 && !found; x--) { for (int y = 0; y < SEEY * 2 && !found; y++) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } break; } compmap.ter_set(comppoint.x, comppoint.y, t_console); computer *tmpcomp = compmap.add_computer(comppoint.x, comppoint.y, string_format(_("%s's Terminal"), dev->name.c_str()), 0); tmpcomp->mission_id = miss->uid; tmpcomp->add_option(_("Download Software"), COMPACT_DOWNLOAD_SOFTWARE, 0); compmap.save(g->cur_om, int(g->turn), place.x * 2, place.y * 2, 0); }
void mission_start::place_npc_software(mission *miss) { npc* dev = g->find_npc(miss->npc_id); if (dev == NULL) { debugmsg("Couldn't find NPC! %d", miss->npc_id); return; } g->u.i_add( item("usb_drive", 0) ); add_msg(_("%s gave you a USB drive."), dev->name.c_str()); std::string type = "house"; switch (dev->myclass) { case NC_HACKER: miss->item_id = "software_hacking"; break; case NC_DOCTOR: miss->item_id = "software_medical"; type = "s_pharm"; miss->follow_up = MISSION_GET_ZOMBIE_BLOOD_ANAL; break; case NC_SCIENTIST: miss->item_id = "software_math"; break; default: miss->item_id = "software_useless"; } int dist = 0; point place; if (type == "house") { int city_id = g->cur_om->closest_city( g->om_location() ); place = g->cur_om->random_house_in_city(city_id); // make it global coordinates place.x += g->cur_om->pos().x * OMAPX; place.y += g->cur_om->pos().y * OMAPY; } else { place = overmap_buffer.find_closest(g->om_global_location(), type, dist, false); } miss->target = place; overmap_buffer.reveal(place, 6, g->levz); tinymap compmap; compmap.load_abs(place.x * 2, place.y * 2, g->levz, false); point comppoint; oter_id oter = g->cur_om->ter(place.x, place.y, 0); if (oter == "house_north" || oter == "house_east" || oter == "house_south" || oter == "house_west") { std::vector<point> valid; for (int x = 0; x < SEEX * 2; x++) { for (int y = 0; y < SEEY * 2; y++) { if (compmap.ter(x, y) == t_floor && compmap.furn(x, y) == f_null) { bool okay = false; for (int x2 = x - 1; x2 <= x + 1 && !okay; x2++) { for (int y2 = y - 1; y2 <= y + 1 && !okay; y2++) { if (compmap.furn(x2, y2) == f_bed || compmap.furn(x2, y2) == f_dresser) { okay = true; valid.push_back( point(x, y) ); } } } } } } if (valid.empty()) { comppoint = point( rng(6, SEEX * 2 - 7), rng(6, SEEY * 2 - 7) ); } else { comppoint = valid[rng(0, valid.size() - 1)]; } } else if (oter == "s_pharm_north") { bool found = false; for (int x = SEEX * 2 - 1; x > 0 && !found; x--) { for (int y = SEEY * 2 - 1; y > 0 && !found; y--) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } else if (oter == "s_pharm_east") { bool found = false; for (int x = 0; x < SEEX * 2 && !found; x++) { for (int y = SEEY * 2 - 1; y > 0 && !found; y--) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } else if (oter == "s_pharm_south") { bool found = false; for (int x = 0; x < SEEX * 2 && !found; x++) { for (int y = 0; y < SEEY * 2 && !found; y++) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } else if (oter == "s_pharm_west") { bool found = false; for (int x = SEEX * 2 - 1; x > 0 && !found; x--) { for (int y = 0; y < SEEY * 2 && !found; y++) { if (compmap.ter(x, y) == t_floor) { found = true; comppoint = point(x, y); } } } } compmap.ter_set(comppoint.x, comppoint.y, t_console); computer *tmpcomp = compmap.add_computer(comppoint.x, comppoint.y, string_format(_("%s's Terminal"), dev->name.c_str()), 0); tmpcomp->mission_id = miss->uid; tmpcomp->add_option(_("Download Software"), COMPACT_DOWNLOAD_SOFTWARE, 0); compmap.save(); }
std::string tpanelload_pending_op::dump() { std::shared_ptr<tpanel> tp=pushtpanel.lock(); tpanelparentwin_nt *window=win.get(); return string_format("Push tweet to tpanel: %s, window: %p, pushflags: 0x%X", (tp) ? cstr(wxstrstd(tp->dispname)) : "N/A", window, pushflags); }
/// @return hardware GUID in URN format to identify hardware as uniquely as possible virtual string hardwareGUID() { return string_format("sparkcoreid:%s", sparkCoreID.c_str()); }
std::string machine_info::game_info_string() { std::ostringstream buf; // print description, manufacturer, and CPU: util::stream_format(buf, _("%1$s\n%2$s %3$s\nDriver: %4$s\n\nCPU:\n"), m_machine.system().description, m_machine.system().year, m_machine.system().manufacturer, core_filename_extract_base(m_machine.system().source_file)); // loop over all CPUs execute_interface_iterator execiter(m_machine.root_device()); std::unordered_set<std::string> exectags; for (device_execute_interface &exec : execiter) { if (!exectags.insert(exec.device().tag()).second) continue; // get cpu specific clock that takes internal multiplier/dividers into account int clock = exec.device().clock(); // count how many identical CPUs we have int count = 1; const char *name = exec.device().name(); for (device_execute_interface &scan : execiter) { if (exec.device().type() == scan.device().type() && strcmp(name, scan.device().name()) == 0 && exec.device().clock() == scan.device().clock()) if (exectags.insert(scan.device().tag()).second) count++; } // if more than one, prepend a #x in front of the CPU name // display clock in kHz or MHz util::stream_format(buf, (count > 1) ? "%1$d" UTF8_MULTIPLY "%2$s %3$d.%4$0*5$d%6$s\n" : "%2$s %3$d.%4$0*5$d%6$s\n", count, name, (clock >= 1000000) ? (clock / 1000000) : (clock / 1000), (clock >= 1000000) ? (clock % 1000000) : (clock % 1000), (clock >= 1000000) ? 6 : 3, (clock >= 1000000) ? _("MHz") : _("kHz")); } // loop over all sound chips sound_interface_iterator snditer(m_machine.root_device()); std::unordered_set<std::string> soundtags; bool found_sound = false; for (device_sound_interface &sound : snditer) { if (!sound.issound() || !soundtags.insert(sound.device().tag()).second) continue; // append the Sound: string if (!found_sound) buf << _("\nSound:\n"); found_sound = true; // count how many identical sound chips we have int count = 1; for (device_sound_interface &scan : snditer) { if (sound.device().type() == scan.device().type() && sound.device().clock() == scan.device().clock()) if (soundtags.insert(scan.device().tag()).second) count++; } // if more than one, prepend a #x in front of the CPU name // display clock in kHz or MHz int clock = sound.device().clock(); util::stream_format(buf, (count > 1) ? ((clock != 0) ? "%1$d" UTF8_MULTIPLY "%2$s %3$d.%4$0*5$d%6$s\n" : "%1$d" UTF8_MULTIPLY "%2$s\n") : ((clock != 0) ? "%2$s %3$d.%4$0*5$d%6$s\n" : "%2$s\n"), count, sound.device().name(), (clock >= 1000000) ? (clock / 1000000) : (clock / 1000), (clock >= 1000000) ? (clock % 1000000) : (clock % 1000), (clock >= 1000000) ? 6 : 3, (clock >= 1000000) ? _("MHz") : _("kHz")); } // display screen information buf << _("\nVideo:\n"); screen_device_iterator scriter(m_machine.root_device()); int scrcount = scriter.count(); if (scrcount == 0) buf << _("None\n"); else { for (screen_device &screen : scriter) { std::string detail; if (screen.screen_type() == SCREEN_TYPE_VECTOR) detail = _("Vector"); else { const rectangle &visarea = screen.visible_area(); detail = string_format("%d " UTF8_MULTIPLY " %d (%s) %f" UTF8_NBSP "Hz", visarea.width(), visarea.height(), (m_machine.system().flags & ORIENTATION_SWAP_XY) ? "V" : "H", ATTOSECONDS_TO_HZ(screen.frame_period().attoseconds())); } util::stream_format(buf, (scrcount > 1) ? _("%1$s: %2$s\n") : _("%2$s\n"), get_screen_desc(screen), detail); } } return buf.str(); }
irom app_action_t application_function_ota_send(const string_t *src, string_t *dst) { int chunk_offset, chunk_length, remote_chunk_length; uint32_t crc, remote_crc; app_action_t action; if((ota_state != state_write) && (ota_state != state_verify)) { string_cat(dst, "OTA: not active\n"); ota_state = state_inactive; return(app_action_error); } if(parse_int(1, src, &remote_chunk_length, 0) != parse_ok) { string_cat(dst, "OTA: missing chunk length\n"); ota_state = state_inactive; return(app_action_error); } if(parse_int(2, src, &remote_crc, 0) != parse_ok) { string_cat(dst, "OTA: missing crc\n"); ota_state = state_inactive; return(app_action_error); } if((chunk_offset = string_sep(src, 0, 3, ' ')) < 0) { string_cat(dst, "OTA: missing data chunk\n"); ota_state = state_inactive; return(app_action_error); } if((chunk_length = string_length(src) - chunk_offset) != remote_chunk_length) { string_format(dst, "OTA: chunk length mismatch: %d != %d\n", remote_chunk_length, chunk_length); ota_state = state_inactive; return(app_action_error); } if((crc = string_crc32(src, chunk_offset, chunk_length)) != remote_crc) { string_format(dst, "OTA: CRC mismatch %08x != %08x\n", remote_crc, crc); ota_state = state_inactive; return(app_action_error); } string_splice(&buffer_4k, src, chunk_offset, chunk_length); if(string_length(&buffer_4k) > 0x1000) { string_format(dst, "OTA: unaligned %u\n", string_length(&buffer_4k)); ota_state = state_inactive; return(app_action_error); } if((string_length(&buffer_4k) == 0x1000) && ((action = flash_write_verify(src, dst)) != app_action_normal)) { ota_state = state_inactive; return(action); } string_format(dst, "ACK %d\n", received); return(app_action_normal); }