struct type quad_res_type(const struct type *type1, const struct type *type2, enum quad_type type) { switch (type) { /* Unary operators */ case AFFEC: case AFFEC_UNARY_MINUS: case AFFEC_UNARY_NOT: return *type1; /* Binary operators */ case AFFEC_BINARY_PLUS: case AFFEC_BINARY_MINUS: case AFFEC_BINARY_MULT: case AFFEC_BINARY_DIV: case AFFEC_BINARY_OR: case AFFEC_BINARY_AND: /* * No automatic type converstion * both must be the same type */ if (!same_type(*type1, *type2)) { fprintf(stderr, "Can't apply an operator between two distinct types\n"); exit(EXIT_FAILURE); } return *type1; default: fprintf(stderr, "No result type for this kind of quad\n"); exit(EXIT_FAILURE); } }
void drop_on_map( const std::list<item> &items, const tripoint &where ) { if( items.empty() ) { return; } const std::string ter_name = g->m.name( where ); const bool can_move_there = g->m.passable( where ); if( same_type( items ) ) { const item &it = items.front(); const int dropcount = items.size() * ( it.count_by_charges() ? it.charges : 1 ); const std::string it_name = it.tname( dropcount ); if( can_move_there ) { add_msg( ngettext( "You drop your %1$s on the %2$s.", "You drop your %1$s on the %2$s.", dropcount ), it_name.c_str(), ter_name.c_str() ); } else { add_msg( ngettext( "You put your %1$s in the %2$s.", "You put your %1$s in the %2$s.", dropcount ), it_name.c_str(), ter_name.c_str() ); } } else { if( can_move_there ) { add_msg( _( "You drop several items on the %s." ), ter_name.c_str() ); } else { add_msg( _( "You put several items in the %s." ), ter_name.c_str() ); } } for( const auto &it : items ) { g->m.add_item_or_charges( where, it ); } }
ecto::tendril& tendril::operator<<(const tendril& rhs) { if (this == &rhs) return *this; if (is_type<none>() || same_type(rhs)) { copy_holder(rhs); } else { enforce_compatible_type(rhs); if (rhs.is_type<none>()) { throw ecto::except::ValueNone("You may not copy the value of a tendril that holds a tendril::none."); } else if (rhs.is_type<boost::python::object>()) { *this << rhs.get<boost::python::object>(); } else if (is_type<boost::python::object>()) { (*rhs.converter)(*boost::unsafe_any_cast<boost::python::object>(&holder_), rhs); } } user_supplied(true); return *this; }
bool padding_first_layer::should_check(const widget &A, const widget &B) { if (A.Is_transparent() || B.Is_transparent()) return false; if (A.Is_browse_button() || B.Is_browse_button()) return false; // Ignore pushbuttons (too many fixes) if (A.isDefPushButton() || A.isPushButton() || B.isPushButton() || B.isDefPushButton()) return false; // This set the max layer for padding if (A.Get_deep() > 1 || B.Get_deep() > 1) return false; // This will enable issues between other types of widgets if (!same_type(A, B)) return false; if(A.Get_father_pointer() != B.Get_father_pointer()) return false; if (overlapped_controllers(A, B)) return false; return true; }
bool tendril::compatible_type(const tendril& rhs) const { if (same_type(rhs)) return true; return is_type<none>() || rhs.is_type<none>() || is_type<boost::python::object>() || rhs.is_type<boost::python::object>(); }
void put_into_vehicle( player &p, const std::list<item> &items, vehicle &veh, int part ) { if( items.empty() ) { return; } const tripoint where = veh.global_part_pos3( part ); const std::string ter_name = g->m.name( where ); int fallen_count = 0; for( auto it : items ) { // cant use constant reference here because of the spill_contents() if( it.is_bucket_nonempty() && !it.spill_contents( p ) ) { p.add_msg_player_or_npc( _( "To avoid spilling its contents, you set your %1$s on the %2$s." ), _( "To avoid spilling its contents, <npcname> sets their %1$s on the %2$s." ), it.display_name().c_str(), ter_name.c_str() ); g->m.add_item_or_charges( where, it ); continue; } if( !veh.add_item( part, it ) ) { if( it.count_by_charges() ) { // Maybe we can add a few charges in the trunk and the rest on the ground. it.mod_charges( -veh.add_charges( part, it ) ); } g->m.add_item_or_charges( where, it ); ++fallen_count; } } const std::string part_name = veh.part_info( part ).name(); if( same_type( items ) ) { const item &it = items.front(); const int dropcount = items.size() * ( it.count_by_charges() ? it.charges : 1 ); p.add_msg_player_or_npc( ngettext( "You put your %1$s in the %2$s's %3$s.", "You put your %1$s in the %2$s's %3$s.", dropcount ), ngettext( "<npcname> puts their %1$s in the %2$s's %3$s.", "<npcname> puts their %1$s in the %2$s's %3$s.", dropcount ), it.tname( dropcount ).c_str(), veh.name.c_str(), part_name.c_str() ); } else { p.add_msg_player_or_npc( _( "You put several items in the %1$s's %2$s." ), _( "<npcname> puts several items in the %1$s's %2$s." ), veh.name.c_str(), part_name.c_str() ); } if( fallen_count > 0 ) { add_msg( m_warning, _( "The trunk is full, so some items fell to the %s." ), ter_name.c_str() ); } }
/* check_type -- check for expected type and return it */ PUBLIC type check_type(char *cxt, type expected, type found) { if (same_type(expected, found)) return found; else if (expected == scalar_type) { if (scalar(found)) return found; error("expected scalar in %s", cxt); return err_type; } else if (expected->x_kind == ARRAY && expected->x_elem == char_type && found == string_type) { return found; } else { error("type mismatch in %s", cxt); return err_type; } }
PUBLIC tree lib_call(def d, tree args) { int n_args = list_len(args); tree call = NULL; bool ok = TRUE; type t = d->t_type; switch (d->d_libid) { case L_CHR: ok = (n_args == 1 && same_type(car(args)->t_type, int_type)); break; case L_ORD: ok = (n_args == 1 && (same_type(car(args)->t_type, char_type) || same_type(car(args)->t_type, bool_type))); break; case L_HALT: case L_FLUSH: ok = (n_args == 0); break; case L_EOF: case L_EOLN: if (n_args == 0) args = list1((tree) _input_); else ok = (n_args = 1 && same_type(car(args)->t_type, text_type)); break; case L_READ: case L_READLN: case L_WRITE: case L_WRITELN: { tree p = args; if (p != nil && same_type(car(p)->t_type, text_type)) p = cdr(p); for (; p != nil; p = cdr(p)) { type at = car(p)->t_type; if (! (same_type(at, int_type) || same_type(at, char_type) || same_type(at, string_type))) { ok = FALSE; break; } } return node_t(LIBCALL, (tree) d, args, void_type); } case L_ARGC: ok = (n_args == 0); break; case L_ARGV: ok = (n_args == 2 && same_type(car(args)->t_type, int_type) && is_string_type(cadr(args)->t_type)); break; case L_OPENIN: ok = (n_args == 2 && same_type(car(args)->t_type, text_type) && is_string_type(cadr(args)->t_type)); break; case L_CLOSEIN: ok = (n_args == 1 && same_type(car(args)->t_type, text_type)); break; default: ok = FALSE; t = err_type; } if (! ok) { error("I choked on a library call"); return (tree) dummy_def; } if (call == NULL) return node_t(CALL, (tree) d, args, t); return call; }
PUBLIC void gen_libcall(def d, tree args) { int nargs = list_len(args); switch (d->d_libid) { case L_READ: case L_READLN: { tree file = (tree) _input_; tree p = args; bool first = TRUE; if (nargs > 0 && same_type(car(p)->t_type, text_type)) { file = car(p); p = cdr(p); } for (; p != nil; p = cdr(p)) { if (! first) emit(", "); first = FALSE; if (same_type(car(p)->t_type, char_type)) emit("%e = getc(%e)", car(p), file); else error("I can only read characters"); } if (d->d_libid == L_READLN) { if (! first) emit(", "); emit("skipln(%e)", file); } } break; case L_WRITE: case L_WRITELN: { tree file = (tree) _output_; tree p = args; static char fmt[256]; static tree arg[16]; int n = 0, i; if (nargs > 0 && same_type(car(p)->t_type, text_type)) { file = car(p); p = cdr(p); } /* Special case for efficiency: printing a single character */ if (d->d_libid == L_WRITE && cdr(p) == nil && same_type(car(p)->t_type, char_type)) { emit("putc(%e, %e)", car(p), file); break; } /* Another special case: printing just a newline */ if (d->d_libid == L_WRITELN && p == nil) { emit("putc('\\n', %e)", file); break; } fmt[0] = '\0'; for (; p != nil; p = cdr(p)) { if (same_type(car(p)->t_type, int_type)) { strcat(fmt, "%d"); arg[n++] = car(p); } else if (same_type(car(p)->t_type, char_type)) { strcat(fmt, "%c"); arg[n++] = car(p); } else if (same_type(car(p)->t_type, string_type)) strcat(fmt, encode(((literal) car(p))->l_value)); } if (d->d_libid == L_WRITELN) strcat(fmt, "\\n"); emit("fprintf(%e, \"%t\"", file, fmt); for (i = 0; i < n; i++) emit(", %e", arg[i]); emit(")"); } break; default: emit("<libcall-%d>", d->d_libid); } }
void put_into_vehicle( Character &c, item_drop_reason reason, const std::list<item> &items, vehicle &veh, int part ) { if( items.empty() ) { return; } const tripoint where = veh.global_part_pos3( part ); const std::string ter_name = g->m.name( where ); int fallen_count = 0; int into_vehicle_count = 0; for( auto it : items ) { // cant use constant reference here because of the spill_contents() if( Pickup::handle_spillable_contents( c, it, g->m ) ) { continue; } if( veh.add_item( part, it ) ) { into_vehicle_count += it.count(); } else { if( it.count_by_charges() ) { // Maybe we can add a few charges in the trunk and the rest on the ground. auto charges_added = veh.add_charges( part, it ); it.mod_charges( -charges_added ); into_vehicle_count += charges_added; } g->m.add_item_or_charges( where, it ); fallen_count += it.count(); } } const std::string part_name = veh.part_info( part ).name(); if( same_type( items ) ) { const item &it = items.front(); const int dropcount = items.size() * it.count(); const std::string it_name = it.tname( dropcount ); switch( reason ) { case item_drop_reason::deliberate: c.add_msg_player_or_npc( ngettext( "You put your %1$s in the %2$s's %3$s.", "You put your %1$s in the %2$s's %3$s.", dropcount ), ngettext( "<npcname> puts their %1$s in the %2$s's %3$s.", "<npcname> puts their %1$s in the %2$s's %3$s.", dropcount ), it_name, veh.name, part_name ); break; case item_drop_reason::too_large: c.add_msg_if_player( ngettext( "There's no room in your inventory for the %s, so you drop it into the %s's %s.", "There's no room in your inventory for the %s, so you drop them into the %s's %s.", dropcount ), it_name, veh.name, part_name ); break; case item_drop_reason::too_heavy: c.add_msg_if_player( ngettext( "The %s is too heavy to carry, so you drop it into the %s's %s.", "The %s are too heavy to carry, so you drop them into the %s's %s.", dropcount ), it_name, veh.name, part_name ); break; case item_drop_reason::tumbling: c.add_msg_if_player( m_bad, ngettext( "Your %s tumbles into the %s's %s.", "Your %s tumble into the %s's %s.", dropcount ), it_name, veh.name, part_name ); break; } } else { switch( reason ) { case item_drop_reason::deliberate: c.add_msg_player_or_npc( _( "You put several items in the %1$s's %2$s." ), _( "<npcname> puts several items in the %1$s's %2$s." ), veh.name, part_name ); break; case item_drop_reason::too_large: case item_drop_reason::too_heavy: case item_drop_reason::tumbling: c.add_msg_if_player( m_bad, _( "Some items tumble into the %1$s's %2$s." ), veh.name, part_name ); break; } } if( fallen_count > 0 ) { if( into_vehicle_count > 0 ) { c.add_msg_if_player( m_warning, ngettext( "The %s is full, so something fell to the %s.", "The %s is full, so some items fell to the %s.", fallen_count ), part_name, ter_name ); } else { c.add_msg_if_player( m_warning, ngettext( "The %s is full, so it fell to the %s.", "The %s is full, so they fell to the %s.", fallen_count ), part_name, ter_name ); } } }
void drop_on_map( const Character &c, item_drop_reason reason, const std::list<item> &items, const tripoint &where ) { if( items.empty() ) { return; } const std::string ter_name = g->m.name( where ); const bool can_move_there = g->m.passable( where ); if( same_type( items ) ) { const item &it = items.front(); const int dropcount = items.size() * it.count(); const std::string it_name = it.tname( dropcount ); switch( reason ) { case item_drop_reason::deliberate: if( can_move_there ) { c.add_msg_player_or_npc( ngettext( "You drop your %1$s on the %2$s.", "You drop your %1$s on the %2$s.", dropcount ), ngettext( "<npcname> drops their %1$s on the %2$s.", "<npcname> drops their %1$s on the %2$s.", dropcount ), it_name, ter_name ); } else { c.add_msg_player_or_npc( ngettext( "You put your %1$s in the %2$s.", "You put your %1$s in the %2$s.", dropcount ), ngettext( "<npcname> puts their %1$s in the %2$s.", "<npcname> puts their %1$s in the %2$s.", dropcount ), it_name, ter_name ); } break; case item_drop_reason::too_large: c.add_msg_if_player( ngettext( "There's no room in your inventory for the %s, so you drop it.", "There's no room in your inventory for the %s, so you drop them.", dropcount ), it_name ); break; case item_drop_reason::too_heavy: c.add_msg_if_player( ngettext( "The %s is too heavy to carry, so you drop it.", "The %s is too heavy to carry, so you drop them.", dropcount ), it_name ); break; case item_drop_reason::tumbling: c.add_msg_if_player( m_bad, ngettext( "Your %1$s tumbles to the %2$s.", "Your %1$s tumble to the %2$s.", dropcount ), it_name, ter_name ); break; } } else { switch( reason ) { case item_drop_reason::deliberate: if( can_move_there ) { c.add_msg_player_or_npc( _( "You drop several items on the %s." ), _( "<npcname> drops several items on the %s." ), ter_name ); } else { c.add_msg_player_or_npc( _( "You put several items in the %s." ), _( "<npcname> puts several items in the %s." ), ter_name ); } break; case item_drop_reason::too_large: case item_drop_reason::too_heavy: case item_drop_reason::tumbling: c.add_msg_if_player( m_bad, _( "Some items tumble to the %s." ), ter_name ); break; } } for( const auto &it : items ) { g->m.add_item_or_charges( where, it ); } }
PUBLIC bool is_string_type(type t) { return (t->x_kind == ARRAY && same_type(t->x_elem, char_type) && t->x_index->x_base == int_type && t->x_index->x_lo == 1); }