// Attempts to open a door if present, return 1 on succesful open int attempt_open_door(player_t* p, room_t* r) { object_t* door = NULL; if(is_of_type(object_at(p->pos.x - 1, p->pos.y, r), DOOR_ID)) door = object_at(p->pos.x - 1, p->pos.y, r); else if(is_of_type(object_at(p->pos.x + 1, p->pos.y, r), DOOR_ID)) door = object_at(p->pos.x + 1, p->pos.y, r); else if(is_of_type(object_at(p->pos.x, p->pos.y - 1, r), DOOR_ID)) door = object_at(p->pos.x, p->pos.y - 1, r); else if(is_of_type(object_at(p->pos.x, p->pos.y + 1, r), DOOR_ID)) door = object_at(p->pos.x, p->pos.y + 1, r); if(door != NULL) { open_door(door); return 1; } else { return 0; } }
template <> cut_part_factory<Cut_Part_base>* cut_part_factory<Cut_Part_base>::s_default_cut_part_factory(const process& pro){ process::const_iterator it = find_if(pro.begin(),pro.end(),is_of_type(higgs)); bool has_a_higgs = ( it != pro.end() ) ; // bool has_a_higgs = true; #ifndef BH_PUBLIC if ( has_a_higgs ) { switch ( settings::general::s_cut_type ){ case settings::general::Darren: return &global_CPFH; case settings::general::FHZ: _WARNING("cut_part_factory<Cut_Part_base>::s_default_higgs_cut_part_factory() : No FHZ factory exists using Darren extended factory"); return &global_CPFH; case settings::general::worker: _WARNING("cut_part_factory<Cut_Part_base>::s_default_higgs_cut_part_factory() : No worker factory exists using Darren extended factory"); return &global_CPFH; } } else { switch ( settings::general::s_cut_type ){ case settings::general::Darren: return &global_CPFD; case settings::general::FHZ: return &global_CPFF; case settings::general::worker: return &global_CPFW; } } #else return &global_CPFW; #endif };
static std::pair<std::string, strus::NumericVariant> get( value const &v ) { std::pair<std::string, strus::NumericVariant> p; if( v.type( ) != is_object) { throw bad_value_cast( ); } p.first = v.get<std::string>( "key" ); value val = v["value"]; switch( val.type( ) ) { case is_boolean: // TODO: really? Do we allow this? p.second = ( v.get<bool>( "value" ) ) ? 1 : 0; break; case is_string: // TODO: really? Do we allow this? case is_number: if( is_of_type( val, p.second.variant.Int ) ) { p.second = v.get<BOOST_TYPEOF( p.second.variant.Int )>( "value" ); } else if( is_of_type( val, p.second.variant.UInt ) ) { p.second = v.get<BOOST_TYPEOF( p.second.variant.UInt )>( "value" ); } else if( is_of_type( val, p.second.variant.Float ) ) { p.second = v.get<BOOST_TYPEOF( p.second.variant.Float )>( "value" ); } else { throw bad_value_cast( ); } break; case is_undefined: case is_null: // TODO: how do we map absence case is_object: case is_array: default: throw bad_value_cast( ); } return p; }
int new_mj_new_object(ast *class_id, ast **node) { mj_new_object *no; if(!is_of_type(MJ_IDENTIFIER, class_id)) { return invalid_type(node); } no = jrv_malloc(sizeof(mj_new_object)); no->type = MJ_NEW_OBJECT; no->class_id = (mj_identifier *) class_id; *node = (ast *) no; return JRV_SUCCESS; }
/** * Classifies a file based on file extension. This classifier uses extensions * installed at the file type extension point. Therefore we need pointer to * the plug-in context to access the extensions. A plug-in instance initializes * the classifier structure with the plug-in context pointer and registers a * virtual symbol pointing to the classifier. */ static int classify(void *d, const char *path) { cp_context_t *ctx = d; cp_extension_t **exts; const char *type = NULL; int i; // Go through all extensions registered at the extension point exts = cp_get_extensions_info(ctx, "org.c-pluff.examples.cpfile.extension.file-types", NULL, NULL); if (exts == NULL) { cp_log(ctx, CP_LOG_ERROR, "Could not resolve file type extensions."); return 0; } for (i = 0; type == NULL && exts[i] != NULL; i++) { int j; // Go through all file types provided by the extension for (j = 0; type == NULL && j < exts[i]->configuration->num_children; j++) { cp_cfg_element_t *elem = exts[i]->configuration->children + j; const char *desc = NULL; if (strcmp(elem->name, "file-type") == 0 && (desc = cp_lookup_cfg_value(elem, "@description")) != NULL && (is_of_type(path, elem))) { type = desc; } } } // Release extension information cp_release_info(ctx, exts); // Print file type if recognized, otherwise try other classifiers if (type != NULL) { fputs(type, stdout); putchar('\n'); return 1; } else { return 0; } }
url complete (url base, url u, string filter, bool flag) { // cout << "complete " << base << " |||| " << u << LF; if (!is_rooted(u)) { if (is_none (base)) return base; if (is_none (u)) return u; if ((!is_root (base)) && (!is_rooted_name (base))) { failed_error << "base= " << base << LF; FAILED ("invalid base url"); } } if (is_name (u) || (is_concat (u) && is_root (u[1]) && is_name (u[2]))) { url comp= base * u; if (is_rooted (comp, "default") || is_rooted (comp, "file")) { if (is_of_type (comp, filter)) return reroot (u, "default"); return url_none (); } if (is_rooted_web (comp) || is_rooted_tmfs (comp) || is_ramdisc (comp)) { if (is_of_type (comp, filter)) return u; return url_none (); } failed_error << "base= " << base << LF; failed_error << "u= " << u << LF; ASSERT (is_rooted (comp), "unrooted url"); FAILED ("bad protocol in url"); } if (is_root (u)) { // FIXME: test filter flags here return u; } if (is_concat (u) && is_wildcard (u[1], 0) && is_wildcard (u[2], 1)) { // FIXME: ret= ret | ... is unefficient (quadratic) in main loop if (!(is_rooted (base, "default") || is_rooted (base, "file"))) { failed_error << "base= " << base << LF; FAILED ("wildcards only implemented for files"); } url ret= url_none (); bool error_flag; array<string> dir= read_directory (base, error_flag); int i, n= N(dir); for (i=0; i<n; i++) { if ((!is_none (ret)) && flag) return ret; if ((dir[i] == ".") || (dir[i] == "..")) continue; if (starts (dir[i], "http://") || starts (dir[i], "ftp://")) if (is_directory (base * dir[i])) continue; ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag)); if (match_wildcard (dir[i], u[2][1]->t->label)) ret= ret | complete (base, dir[i], filter, flag); } return ret; } if (is_concat (u)) { url sub= complete (base, u[1], "", false); // "" should often be faster than the more correct "d" here return complete (base, sub, u[2], filter, flag); } if (is_or (u)) { url res1= complete (base, u[1], filter, flag); if ((!is_none (res1)) && flag) return res1; return res1 | complete (base, u[2], filter, flag); } if (is_wildcard (u)) { // FIXME: ret= ret | ... is unefficient (quadratic) in main loop if (!(is_rooted (base, "default") || is_rooted (base, "file"))) { failed_error << "base= " << base << LF; FAILED ("wildcards only implemented for files"); } url ret= url_none (); if (is_wildcard (u, 0) && is_of_type (base, filter)) ret= url_here (); bool error_flag; array<string> dir= read_directory (base, error_flag); int i, n= N(dir); for (i=0; i<n; i++) { if ((!is_none (ret)) && flag) return ret; if ((dir[i] == ".") || (dir[i] == "..")) continue; if (starts (dir[i], "http://") || starts (dir[i], "ftp://")) if (is_directory (base * dir[i])) continue; if (is_wildcard (u, 0)) ret= ret | (dir[i] * complete (base * dir[i], u, filter, flag)); else if (match_wildcard (dir[i], u[1]->t->label)) ret= ret | complete (base, dir[i], filter, flag); } return ret; } failed_error << "url= " << u << LF; FAILED ("bad url"); return u; }
u8 change_stats(struct stat stat_change, u8 stat, struct failbank bank, void* battlescript_if_fails) { if (stat_change.decrement) battle_scripting.stat_changer |= 0x80; else battle_scripting.stat_changer &= 0x7F; u8 fail = 0; if (bank.attacker) { active_bank = bank_attacker; battle_scripting.active_bank = bank_attacker; } else { active_bank = bank_target; battle_scripting.active_bank = bank_target; } battle_text_buff1[0] = 0xFD; battle_text_buff1[1] = 5; battle_text_buff1[2] = stat; battle_text_buff1[3] = 0xFF; u8 has_ability=has_ability_effect(active_bank, !bank.attacker, 1); if (has_ability) { if (battle_participants[active_bank].ability_id == ABILITY_CONTRARY) { stat_change.decrement ^= 1; battle_scripting.stat_changer ^= 0x80; record_usage_of_ability(active_bank, ABILITY_CONTRARY); } else if (battle_participants[active_bank].ability_id == ABILITY_SIMPLE) { if ((stat_change.how_much * 2) > 7) { stat_change.how_much = 7; } else { stat_change.how_much *= 2; } record_usage_of_ability(active_bank, ABILITY_SIMPLE); } } u8* stat_ptr = &battle_participants[active_bank].hp_buff; stat_ptr += stat; if (stat_change.decrement) //we're lowering stats { if (side_affecting_halfword[get_battle_side(active_bank) & 1].mist_on && current_move != MOVE_CURSE && bank.cannotfail == 0) { if (special_statuses[active_bank].statloweringflag) { battlescripts_curr_instruction = battlescript_if_fails; } else { ability_affects_stat_reduction(active_bank,(void*) 0x082DAE03, battlescript_if_fails, 0); special_statuses[active_bank].statloweringflag = 1; } return 1; } else if (does_protect_affect_move(0) && current_move != MOVE_CURSE && bank.ignore_opponent_protect == 0) { battlescripts_curr_instruction = (void*) 0x082D9F1C; return 1; } else if (has_ability && (battle_participants[active_bank].ability_id == ABILITY_WHITE_SMOKE || battle_participants[active_bank].ability_id == ABILITY_CLEAR_BODY) && current_move != MOVE_CURSE && bank.cannotfail == 0) { if (special_statuses[active_bank].statloweringflag) { battlescripts_curr_instruction = battlescript_if_fails; } else { ability_affects_stat_reduction(active_bank, (void*) 0x082DB5C7, battlescript_if_fails, 1); special_statuses[active_bank].statloweringflag = 1; } return 1; } if (current_move != MOVE_CURSE && bank.cannotfail == 0 && is_of_type(active_bank, TYPE_GRASS)) { u8 flower = ability_battle_effects(13, active_bank, ABILITY_FLOWER_VEIL, 1, 0); if (flower) { if (special_statuses[active_bank].statloweringflag && battlescript_if_fails) battlescripts_curr_instruction = battlescript_if_fails; else { ability_affects_stat_reduction(flower - 1, (void*) 0x082DB5C7, battlescript_if_fails, 1); special_statuses[active_bank].statloweringflag = 1; } } } if (has_ability && battle_participants[active_bank].ability_id == ABILITY_KEEN_EYE && stat == STAT_ACCURACY && bank.cannotfail == 0) { if (!bank.failsth) { } else { ability_affects_stat_reduction(active_bank, (void*)0x082DB62F, battlescript_if_fails, 1); } return 1; } else if (has_ability && battle_participants[active_bank].ability_id == ABILITY_HYPER_CUTTER && stat == STAT_ATTACK && bank.cannotfail == 0) { if (!bank.failsth) { } else { ability_affects_stat_reduction(active_bank,(void*) 0x082DB62F, battlescript_if_fails, 1); } return 1; } else if (has_ability && battle_participants[active_bank].ability_id == ABILITY_BIG_PECKS && stat == STAT_DEFENCE && bank.cannotfail == 0) { if (!bank.failsth) { } else { ability_affects_stat_reduction(active_bank,(void*) 0x082DB62F, battlescript_if_fails, 1); } return 1; } else if (has_ability && battle_participants[active_bank].ability_id == ABILITY_SHIELD_DUST && bank.failsth == 0) { return 1; } else { if (*stat_ptr == 0) { battle_communication_struct.multistring_chooser = 2; if (bank.failsth) { move_outcome.missed = 1; fail = 0; } else { fail = 1; } } else { if (active_bank == bank_target) { battle_communication_struct.multistring_chooser = 1; } else { battle_communication_struct.multistring_chooser = 0; } u8 lowered_stats = 0; u8 amount = 0; battle_scripting.stat_changer &= 0x8F; while (stat_change.how_much != 0) { stat_change.how_much--; *stat_ptr -= 1; lowered_stats++; amount += 0x10; if (*stat_ptr == 0) break; } battle_scripting.stat_changer ^= amount; u8 i = 2; battle_text_buff2[0] = 0xFD; battle_text_buff2[1] = 0; if (lowered_stats == 2) { battle_text_buff2[2] = 0xD3; battle_text_buff2[3] = 0; battle_text_buff2[4] = 0; i += 3; } else if (lowered_stats >= 3) { battle_text_buff2[2] = 0x97; battle_text_buff2[3] = 1; battle_text_buff2[4] = 0; i += 3; } battle_text_buff2[i] = 0xD4; battle_text_buff2[i + 1] = 0; battle_text_buff2[i + 2] = 0xFF; } } } else // we're raising stats { if (*stat_ptr == 0xC) { battle_communication_struct.multistring_chooser = 2; if (bank.failsth) { move_outcome.missed = 1; fail = 0; } else { fail = 1; } } else { if (active_bank == bank_target) { battle_communication_struct.multistring_chooser = 1; } else { battle_communication_struct.multistring_chooser = 0; } u8 raised_stats = 0; u8 amount = 0; battle_scripting.stat_changer &= 0x8F; while (stat_change.how_much != 0) { stat_change.how_much--; *stat_ptr += 1; raised_stats++; amount += 0x10; if (*stat_ptr == 0xC) break; } battle_scripting.stat_changer ^= amount; u8 i = 2; battle_text_buff2[0] = 0xFD; battle_text_buff2[1] = 0; if (raised_stats == 2) { battle_text_buff2[2] = 0xD1; battle_text_buff2[3] = 0; battle_text_buff2[4] = 0; i += 3; } else if (raised_stats >= 3) { battle_text_buff2[2] = 0x97; battle_text_buff2[3] = 1; battle_text_buff2[4] = 0; i += 3; } battle_text_buff2[i] = 0xD2; battle_text_buff2[i + 1] = 0; battle_text_buff2[i + 2] = 0xFF; } } if (fail == 0 && battle_communication_struct.multistring_chooser != 2 && stat_change.decrement && has_ability && active_bank != bank_attacker) new_battlestruct.ptr->bank_affecting[active_bank].stat_lowered = 1; return fail; }