Пример #1
0
bool item::is_food(player *u)
{
 if (!u)
  return is_food();

 if( is_null() )
  return false;

 if (type->is_food())
  return true;

 if (u->has_bionic(bio_batteries) && is_ammo() &&
     (dynamic_cast<it_ammo*>(type))->type == AT_BATT)
  return true;
 if (u->has_bionic(bio_furnace) && is_flammable(type->m1) &&
     is_flammable(type->m2) && typeId() != itm_corpse)
  return true;
 return false;
}
Пример #2
0
bool item::has_flag(item_flag f)
{
 if (is_gun()) {
  if (mode == IF_MODE_AUX) {
   item* gunmod = active_gunmod();
   if( gunmod != NULL )
    return gunmod->has_flag(f);
  } else {
   for (int i = 0; i < contents.size(); i++) {
     // Don't report flags from active gunmods for the gun.
    if (contents[i].has_flag(f) && contents[i].has_flag(IF_MODE_AUX))
     return true;
   }
  }
 }
 if( is_null() )
  return false;
 return (type->item_flags & mfb(f));
}
Пример #3
0
//one arg: exps
static cellpoint sequence_2_exp(void)
{
	//used in cond_2_if
	reg = args_ref(1);
	if (is_false(is_null(reg))){
		//calls last_exp
		args_push(args_ref(1));
		reg = last_exp();
		if (is_true(reg)){
			args_push(args_ref(1));
			reg = first_exp();
		}else {
			args_push(args_ref(1));
			reg = make_begin();
		}
	}
	args_pop(1);
	return reg;
}
Пример #4
0
	bool	as_value::operator==(const as_value& v) const
	// Return true if operands are equal.
	{
		// types don't match
		if (m_type != PROPERTY && v.m_type != PROPERTY && m_type != v.m_type)
		{
			if ((is_undefined() && v.is_null()) || (is_null() && v.is_undefined()))
			{
				return true;
			}
			return false;
		}

		switch (m_type)
		{
			case UNDEFINED:
				return v.m_type == UNDEFINED;

			case STRING:
				return m_string == v.to_tu_string();

			case NUMBER:
				return m_number == v.to_number();

			case BOOLEAN:
				return m_bool == v.to_bool();

			case OBJECT:
				return m_object.get() == v.to_object();

			case PROPERTY:
			{
				as_value prop;
				get_property(&prop);
				return prop == v;
			}

			default:
				assert(0);
				return false;
		}
	}
Пример #5
0
/*@null@*/ static PyObject*
PyTabprm_get_extrema(
    PyTabprm* self,
    /*@unused@*/ void* closure) {

  int ndims;
  npy_intp dims[NPY_MAXDIMS];

  if (is_null(self->x->coord)) {
    return NULL;
  }

  if (make_fancy_dims(self, &ndims, dims)) {
    return NULL;
  }

  dims[ndims-2] = 2;

  return get_double_array("extrema", self->x->extrema, ndims, dims, (PyObject*)self);
}
Пример #6
0
void DefaultSpmdVectorSpace<Scalar>::initialize(
  const RCP<const Teuchos::Comm<Ordinal> > &comm
  ,const Ordinal localSubDim_in, const Ordinal globalDim
  )
{
#ifdef TEUCHOS_DEBUG
  TEUCHOS_TEST_FOR_EXCEPT( !( localSubDim_in >= 0 ) );
#endif
  comm_ = comm;
  localSubDim_ = localSubDim_in;
  if (!is_null(comm)) {
    numProc_ = size(*comm);
    procRank_ = rank(*comm);
  }
  else {
    numProc_ = 1;
    procRank_ = 0;
  }
  this->updateState(globalDim);
}
Пример #7
0
void define_variable(item unev, item val, item env){
	item frame = first_frame(env);
	item vars, vals;
	vars = frame_variables(frame);
	vals = frame_value(frame);
	while (1){
		if (is_null(vars)){
			add_binding_to_frame(unev, val, frame);
			break;
		}
		else if (eq(unev, car(vars))){
			set_car(vals, val);
			break;
		}
		else{
			vars = cdr(vars);
			vals = cdr(vals);
		}
	}
}
Пример #8
0
void print_ptr_rec(ptr x) {
  /*printf("%u\n", x);*/
  if (is_fixnum(x)) {
    printf("%d", to_fixnum(x));
  } else if (x == bool_f) {
    printf("#f");
  } else if (x == bool_t) {
    printf("#t");
  } else if (is_null(x)) {
    print_null();
  } else if (is_char(x)) {
    printf("%s", beautify(to_char(x)));
  } else if (is_pair(x)) {
    printf("(");
    print_pair(x);
    printf(")");
  } else {
    printf("#<unknown 0x%08x>", x);
  }
}
Пример #9
0
void getLocalRowValues (const Teuchos::RCP<Thyra_LinearOp>& lop,
                        const LO lrow,
                        Teuchos::Array<LO>& indices,
                        Teuchos::Array<ST>& values)
{
  // Allow failure, since we don't know what the underlying linear algebra is
  auto tmat = getConstTpetraMatrix(lop,false);
  if (!tmat.is_null()) {
    auto numEntries = tmat->getNumEntriesInLocalRow(lrow);
    indices.resize(numEntries);
    values.resize(numEntries);
    tmat->getLocalRowCopy(lrow,indices,values,numEntries);
    return;
  }

  // TODO: add epetra

  // If all the tries above are not successful, throw an error.
  TEUCHOS_TEST_FOR_EXCEPTION (true, std::runtime_error, "Error! Could not cast Thyra_LinearOp to any of the supported concrete types.\n");
}
Пример #10
0
void set_variable_value(item unev, item val, item env){
	item vars, vals;
	while (!eq(env, the_empty_environment())){
		vars = frame_variables(first_frame(env));
		vals = frame_value(first_frame(env));
		while (1){
			if (is_null(vars)){
				env = enclosing_environment(env);
				break;
			}
			else if (eq(unev, car(vars))){
				set_car(vals, val);
			}
			else {
				vars = cdr(vars);
				vals = cdr(vals);
			}
		}
	}
}
Пример #11
0
// ----------------------------------------------------------------------------
void player::play_from_queue()
{
  if ( play_queue_.size() > 0 )
  {
    auto track = play_queue_.front();
    auto src   = track.find_source();

    if ( !src.is_null() )
    {
      std::cerr << "play_from_queue id=" << track.id() << ", title='" << track.title() << "', source=" << src.name() << std::endl;

      state_.state  = playing;
      state_.track  = std::move(track);
      state_.source = src.name();

      std::cout << "player state=" << state_.state << std::endl;

      if ( !audio_output_ ) {
        audio_output_open();
      }

      play_source(src);
      play_queue_.pop();
    }
    else
    {
      std::cerr << "play_from_queue id=" << track.id() << ", title='" << track.title() << "', NO SOURCE!" << std::endl;
      play_queue_.pop();
      play_from_queue();
    }
  }
  else if ( continuous_playback_ )
  {
    play_queue_.push(ctpb_selector_.next());
    play_from_queue();
  }
  else
  {
    play_stop();
  }
}
Пример #12
0
 void ddp::on_message(client::message_ptr const& msg)
 {
     auto const payload = nlohmann::json::parse(msg->get_payload());
     auto const message = payload["msg"];
     if(message.is_null()) {
         // ignore
     } else if(message == "connected") {
         _session = payload["session"].get<std::string>();
         _connected_sig(_session);
     } else if(message == "failed") {
         // throw error
     } else if(message == "ping") {
         nlohmann::json response;
         response["msg"] = "pong";
         response["id"] = payload["id"];
         _conn->send(response.dump(), websocketpp::frame::opcode::text);
     } else if(message == "error") {
         // throw error
     } else if(message == "nosub") {
         // throw error
     } else if(message == "added") {
         nlohmann::json const& fields = payload["fields"];
         _doc_added_sig(payload["collection"], payload["id"], !fields.is_null() ? fields : nlohmann::json::object());
     } else if(message == "changed") {
         nlohmann::json const& fields = payload["fields"];
         nlohmann::json const& cleared = payload["cleared"];
         _doc_changed_sig(payload["collection"], payload["id"], !fields.is_null() ? fields : nlohmann::json::object(), !cleared.is_null() ? cleared : nlohmann::json::array());
     } else if(message == "removed") {
         _doc_removed_sig(payload["collection"], payload["id"]);
     } else if(message == "ready") {
         for(std::string const& id: payload["subs"]) {
             _ready_sig(id);
         }
     } else if(message == "updated") {
         for(std::string const& id: payload["methods"]) {
             _method_updated_sig(id);
         }
     } else if(message == "result") {
         _method_result_sig(payload["id"], payload["result"], payload["error"]);
     }
 }
bool StarSystem::RemoveUnit( Unit *un )
{
    for (unsigned int locind = 0; locind < Unit::NUM_COLLIDE_MAPS; ++locind)
        if ( !is_null( un->location[locind] ) ) {
            collidemap[locind]->erase( un->location[locind] );
            set_null( un->location[locind] );
        }
    bool  removed2 = false;
    Unit *unit;
    for (un_iter iter = gravitationalUnits().createIterator(); (unit = *iter); ++iter)
        if (unit == un) {
            iter.remove();
            removed2 = true;
            break;                                       //Shouldn't be in there twice
        }
    //NOTE: not sure why if(1) was here, but safemode removed it
    bool removed = false;
    if (1) {
        for (un_iter iter = drawList.createIterator(); (unit = *iter); ++iter)
            if (unit == un) {
                iter.remove();
                removed = true;
                break;
            }
    }
    if (removed) {
        for (unsigned int i = 0; i <= SIM_QUEUE_SIZE; ++i) {
            Unit *unit;
            for (un_iter iter = physics_buffer[i].createIterator(); (unit = *iter); ++iter)
                if (unit == un) {
                    iter.remove();
                    removed = true;
                    //terminate outer loop
                    i = SIM_QUEUE_SIZE+1;
                    break;
                }
        }
        stats.RemoveUnit( un );
    }
    return removed;
}
Пример #14
0
void if_block_turn_common_rebinds_into_outputs(Term* ifCall)
{
    // Find names which are bound in every branch (and not already outputs)
    Branch* contents = nested_contents(ifCall);

    bool firstBranch = true;
    List names;

    for (CaseIterator it(contents); it.unfinished(); it.advance()) {
        Branch* caseBranch = nested_contents(it.current());

        if (firstBranch) {
            firstBranch = false;
            write_all_names_to_list(caseBranch, &names);

            // remove names that are already outputs
            for (int i=0; i < names.length(); i++) {
                Term* existing = contents->get(as_cstring(names[i]));
                if (existing != NULL && existing->function == FUNCS.output)
                    set_null(names[i]);
            }

            continue;
        }

        // search through 'names' and remove any not in this branch.
        for (int i=0; i < names.length(); i++) {
            if (is_null(names[i]))
                continue;
            if (caseBranch->get(as_cstring(names[i])) == NULL)
                set_null(names[i]);
        }
    }

    names.removeNulls();
    // std::cout << names.toString() << std::endl;

    for (int i=0; i < names.length(); i++) {
        if_block_add_output_for_name(ifCall, as_cstring(names[i]));
    }
}
Пример #15
0
Term* find_from_relative_name_list(Value* name, Block* relativeTo)
{
    if (is_null(name))
        return NULL;

    Term* term = NULL;
    for (int index=0; index < list_length(name); index++) {
        if (relativeTo == NULL)
            return NULL;

        term = find_from_unique_name(relativeTo, list_get(name, index));

        if (term == NULL)
            return NULL;

        relativeTo = term->nestedContents;

        // relativeTo may now be NULL. But if we reached the end of this match, that's ok.
    }
    return term;
}
Пример #16
0
/* get the slope between two cells and return a slope direction */
void check(CELL newdir, CELL * dir, void *center, void *edge, double cnst,
	   double *oldslope)
{
    double newslope;

    /* never discharge to a null boundary */
    if (is_null(edge))
	return;

    newslope = slope(center, edge, cnst);
    if (newslope == *oldslope) {
	*dir += newdir;
    }
    else if (newslope > *oldslope) {
	*oldslope = newslope;
	*dir = newdir;
    }

    return;

}
Пример #17
0
DeviceLocalMatrix<ST> getNonconstDeviceData (const Teuchos::RCP<Thyra_LinearOp>& lop)
{
  // Allow failure, since we don't know what the underlying linear algebra is
  auto tmat = getTpetraMatrix(lop,false);
  if (!tmat.is_null()) {
    // Get the local matrix from tpetra.
    DeviceLocalMatrix<ST> data = tmat->getLocalMatrix();
    return data;
  }

  // TODO: to add epetra, create device matrix, get values view, create host copy, extract data
  //       from matrix into values host view, deep copy to device. We could otherwise ENFORCE
  //       PHX::Device to be a host exec space for Epetra.

  // If all the tries above are not successful, throw an error.
  TEUCHOS_TEST_FOR_EXCEPTION (true, std::runtime_error, "Error! Could not cast Thyra_Vector to any of the supported concrete types.\n");

  // Dummy return value, to silence compiler warnings
  DeviceLocalMatrix<ST> dummy;
  return dummy;
}
Пример #18
0
common::List<Uint>& Entities::used_nodes(Component& parent, const bool rebuild)
{
  Handle< common::List<Uint> > used_nodes = find_component_ptr_with_tag<common::List<Uint> >(parent,mesh::Tags::nodes_used());
  if (rebuild && is_not_null(used_nodes))
  {
    parent.remove_component(*used_nodes);
    used_nodes.reset();
  }

  if (is_null(used_nodes))
  {
    const Dictionary& dict = find_components_recursively<Entities>(parent).begin()->geometry_fields();
    boost::shared_ptr< List<Uint> > used_nodes_shr = build_used_nodes_list(parent, dict, true);
    used_nodes = Handle< List<Uint> >(used_nodes_shr);
    parent.add_component(used_nodes_shr);
    used_nodes->add_tag(mesh::Tags::nodes_used());
    used_nodes->properties()["brief"] = std::string("The local node indices used by the parent component");
  }

  return *used_nodes;
}
Пример #19
0
 bool insert(const K& k, const T& t)
 {
   if (is_null(root)) {
     root = get_new_node(k, t);
   } else {
     splay(k, root);
     if (comp(k, root->key)) {
       node_type* n = get_new_node(k, t, root->left, root);
       root->left = null_node;
       root = n;
     } else if (comp(root->key, k)) {
       node_type* n = get_new_node(k, t, root, root->right);
       root->right = null_node;
       root = n;
     } else {
       root->value = t;
       return false;
     }
   }
   return true;
 }
Пример #20
0
QCheckBox * GraphicalBoolTest::findCheckBox(const GraphicalBool* value)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalBool

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QCheckBox * checkBox = nullptr;

  if( is_not_null(layout) )
  {
    checkBox = dynamic_cast<QCheckBox*>(layout->itemAt(0)->widget());

    if( is_null(checkBox) )
      QWARN("Failed to find the check box.");
  }
  else
    QWARN("Failed to find the layout or cast it to QHBoxLayout.");

  return checkBox;
}
Пример #21
0
Файл: io.c Проект: cmatei/yalfs
static void write_pair(object pair, FILE *out)
{
	object car_obj, cdr_obj;

	car_obj = car(pair);
	cdr_obj = cdr(pair);

	lisp_print(car_obj, out);

	if (is_pair(cdr_obj)) {
		fprintf(out, " ");
		write_pair(cdr_obj, out);
	}
	else if (is_null(cdr_obj)) {
		return;
	}
	else {
		fprintf(out, " . ");
		lisp_print(cdr_obj, out);
	}
}
Пример #22
0
QLineEdit * GraphicalDoubleTest::findLineEdit(const GraphicalDouble* value)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalDouble

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QLineEdit * lineEdit = nullptr;

  if( is_not_null(layout) )
  {
    lineEdit = dynamic_cast<QLineEdit*>(layout->itemAt(0)->widget());

    if( is_null(lineEdit) )
      QWARN("Failed to find the line edit.");
  }
  else
    QWARN("Failed to find the layout or cast it to QHBoxLayout.");

  return lineEdit;
}
Пример #23
0
DeviceView1d<ST> getNonconstDeviceData (const Teuchos::RCP<Thyra_Vector>& v)
{
  // Allow failure, since we don't know what the underlying linear algebra is
  auto tv = getTpetraVector(v,false);
  if (!tv.is_null()) {
    auto data2d = tv->getLocalView<KokkosNode::execution_space>();
    DeviceView1d<ST> data = Kokkos::subview(data2d, Kokkos::ALL(), 0);
    return data;
  }

  // TODO: to add epetra, create device view, create host copy, extract data
  //       into host view, deep copy to device. We could otherwise ENFORCE
  //       PHX::Device to be a host exec space for Epetra.

  // If all the tries above are not successful, throw an error.
  TEUCHOS_TEST_FOR_EXCEPTION (true, std::runtime_error, "Error! Could not cast Thyra_Vector to any of the supported concrete types.\n");

  // Dummy return value, to silence compiler warnings
  DeviceView1d<ST> dummy;
  return dummy;
}
Пример #24
0
    /*!
     * \brief Explicitly unregisters this callback.
     *
     * Once the callback has been unregistered the function this is associated
     * with will no longer be called when the CallbackHandler is triggered and
     * this will become a null ScopedCallback.
     *
     * \throws arc::ex::IllegalActionError If this is called on a null
     *                                       ScopedCallbackId.
     */
    void unregister()
    {
        if(is_null())
        {
            throw arc::ex::IllegalActionError(
                    "unregister cannot be called on null ScopedCallbacks");
        }

        // there should be at least one instance!!
        assert(m_ref_counter->count > 0);
        // unregister if it hasn't been done already
        if(is_registered())
        {
            m_interface->unregister_function(m_id);
            m_ref_counter->early_unregister = true;
        }
        // nullify this object
        m_ref_counter = nullptr;
        m_interface   = nullptr;
        m_id          = 0;
    }
Пример #25
0
ElementLoop& BoundaryTerm::access_element_loop( const std::string& type_name )
{
    // ensure that the fields are present

    link_fields();

    // get the element loop or create it if does not exist

    Handle< ElementLoop > loop(get_child( "LOOP" ));
    if( is_null( loop ) )
    {
        const std::string update_vars_type =
            physical_model().get_child( RDM::Tags::update_vars() )
            ->handle<physics::Variables>()
            ->type();

        loop = create_component<FaceLoop>("LOOP", "FaceLoopT<" + type_name + "," + update_vars_type + ">");
    }

    return *loop;
}
Пример #26
0
QDoubleSpinBox * GraphicalIntTest::findSpinBox(const GraphicalInt* value)
{
  // /!\ WARNING /!\
  // THE FOLLOWING CODE IS EXTREMELY SENSITIVE TO ANY MODIFICATION
  // OF THE GRAPHICAL LOOK OF GraphicalInt

  QHBoxLayout * layout = dynamic_cast<QHBoxLayout*>(value->layout());
  QDoubleSpinBox * spinBox = nullptr;

  if( is_not_null(layout) )
  {
    spinBox = dynamic_cast<QDoubleSpinBox*>(layout->itemAt(0)->widget());

    if( is_null(spinBox) )
      QWARN("Failed to find the spin box.");
  }
  else
    QWARN("Failed to find the layout or cast it to QHBoxLayout.");

  return spinBox;
}
Пример #27
0
CIRCA_EXPORT void circa_read_file(caWorld* world, const char* filename, Value* contentsOut)
{
    Value name;
    set_string(&name, filename);

    const char* builtinFile = find_builtin_file(filename);
    if (builtinFile != NULL) {
        set_string(contentsOut, builtinFile);
        return;
    }

    Value* fileSources = &world->fileSources;
    for (int i=list_length(fileSources) - 1; i >= 0; i--) {
        Value* file_source = list_get(fileSources, i);
        file_source_read_file(file_source, &name, contentsOut);
        if (!is_null(contentsOut))
            return;
    }

    set_null(contentsOut);
}
Пример #28
0
/*
 * Parse the input stream and return an action stack.
 * See Wikipedia again.
 */
static obj_t *parse(instream_t *in)
{
    AUTO_ROOT(actions, NIL);
    AUTO_ROOT(yylval, NIL);
    AUTO_ROOT(tmp, make_fixnum(TOK_EOF));
    AUTO_ROOT(stack, NIL);
    stack_push(&stack, tmp);
    tmp = make_fixnum(sym_index(start_symbol));
    stack_push(&stack, tmp);
    int tok = yylex(&yylval, in);
    while (true) {
	int sym = fixnum_value(stack_pop(&stack));
	assert(0 <= sym && sym < symbols_size);
	uint_fast8_t rule = get_rule(symbols[sym], tok);
	if (rule != NO_RULE) {
	    const production_t *pp = &grammar[rule];
	    int j;
	    for (j = strlen(pp->p_rhs); --j >= 0; ) {
		tmp = make_fixnum(sym_index(pp->p_rhs[j]));
		stack_push(&stack, tmp);
	    }
	    if (pp->p_action)
		stack_push(&actions, *pp->p_action);
	} else {
	    if (sym == TOK_EOF)
		break;
	    /* XXX raise an exception here. */
	    assert(sym == tok && "syntax error");
	    if (!is_null(yylval))
		stack_push(&actions, yylval);
	    if (!stack_is_empty(actions) &&
		fixnum_value(stack_top(stack)) == TOK_EOF)
		break;
	    yylval = NIL;
	    tok = yylex(&yylval, in);
	}
    }
    POP_FUNCTION_ROOTS();
    return actions;
}
Пример #29
0
bool VerificationType::is_reference_assignable_from(
    const VerificationType& from, ClassVerifier* context, TRAPS) const {
    instanceKlassHandle klass = context->current_class();
    if (from.is_null()) {
        // null is assignable to any reference
        return true;
    } else if (is_null()) {
        return false;
    } else if (name() == from.name()) {
        return true;
    } else if (is_object()) {
        // We need check the class hierarchy to check assignability
        if (name() == vmSymbols::java_lang_Object()) {
            // any object or array is assignable to java.lang.Object
            return true;
        }
        Klass* obj = SystemDictionary::resolve_or_fail(
                         name(), Handle(THREAD, klass->class_loader()),
                         Handle(THREAD, klass->protection_domain()), true, CHECK_false);
        KlassHandle this_class(THREAD, obj);

        if (this_class->is_interface()) {
            // We treat interfaces as java.lang.Object, including
            // java.lang.Cloneable and java.io.Serializable
            return true;
        } else if (from.is_object()) {
            Klass* from_class = SystemDictionary::resolve_or_fail(
                                    from.name(), Handle(THREAD, klass->class_loader()),
                                    Handle(THREAD, klass->protection_domain()), true, CHECK_false);
            return InstanceKlass::cast(from_class)->is_subclass_of(this_class());
        }
    } else if (is_array() && from.is_array()) {
        VerificationType comp_this = get_component(context, CHECK_false);
        VerificationType comp_from = from.get_component(context, CHECK_false);
        if (!comp_this.is_bogus() && !comp_from.is_bogus()) {
            return comp_this.is_assignable_from(comp_from, context, CHECK_false);
        }
    }
    return false;
}
Пример #30
0
int item::melee_value(int skills[num_skill_types])
{
 if( is_null() )
  return 0;

 int my_value = 0;
 my_value += int(type->melee_dam * (1   + .3 * skills[sk_bashing] +
                                          .1 * skills[sk_melee]    ));
 //debugmsg("My value: (+bash) %d", my_value);

 my_value += int(type->melee_cut * (1   + .4 * skills[sk_cutting] +
                                          .1 * skills[sk_melee]    ));
 //debugmsg("My value: (+cut) %d", my_value);

 my_value += int(type->m_to_hit  * (1.2 + .3 * skills[sk_melee]));
 //debugmsg("My value: (+hit) %d", my_value);

 if (is_style())
  my_value += 15 * skills[sk_unarmed] + 8 * skills[sk_melee];

 return my_value;
}