Exemple #1
0
void velena_wait()
{
	int ret;
	char buffer[256];

	movestatus = 0;
	while(movestatus == 0)
	{
		ret = read(enginechannel, buffer, sizeof(buffer));
		if(ret > 0)
		{
			buffer[ret] = 0;
			examine(buffer);
		}
		else if(ret == 0)
		{
			fprintf(stderr, "velena AI: ciao\n");
			death = 1;
			break;
		}

		ret = waitpid(pid, NULL, WNOHANG);
		if(ret != 0)
		{
			death = 1;
			break;
		}
	}
}
Exemple #2
0
void ScrollAnchor::findAnchor() {
  TRACE_EVENT0("blink", "ScrollAnchor::findAnchor");
  SCOPED_BLINK_UMA_HISTOGRAM_TIMER("Layout.ScrollAnchor.TimeToFindAnchor");

  LayoutObject* stayWithin = scrollerLayoutBox(m_scroller);
  LayoutObject* candidate = stayWithin->nextInPreOrder(stayWithin);
  while (candidate) {
    ExamineResult result = examine(candidate);
    if (result.viable) {
      m_anchorObject = candidate;
      m_corner = result.corner;
    }
    switch (result.status) {
      case Skip:
        candidate = candidate->nextInPreOrderAfterChildren(stayWithin);
        break;
      case Constrain:
        stayWithin = candidate;
      // fall through
      case Continue:
        candidate = candidate->nextInPreOrder(stayWithin);
        break;
      case Return:
        return;
    }
  }
}
void ExamineCommand(char * input)
{

	if( strncmp(input,"EXAMINE",7) == 0 )
	{
		examine(m_RoomId); 
	}
}
void back::examinecheck(gamelevel* level)
{
    bool inmenu = false;
    string iminput;
    int tick = 0;
    current = level;

    if(level->interactable == false)
    {
        do
        {
            inmenu = false;
            cout<<"#"<<endl;
            cout<<"# what:"<<endl;
            getline(cin,iminput);

            searcher = current->childone;
            if(searcher->menuname == iminput)
            {
                examine(searcher);
            }
            else if(searcher->menuname != iminput)
            {
                while(searcher->menuname != iminput)
                {
                    searcher = searcher->next;
                    tick++;
                    if(tick > 10)
                    {
                        cout<<"# wrong input"<<endl;
                        EImenu(level);
                    }
                }
                examine(searcher);
            }
        }
        while(inmenu == true);
    }
}
Exemple #5
0
/* callback() pcap callback */
void callback(unsigned char *string, 
    const struct pcap_pkthdr *framehdr, const unsigned char buf[])
{
	time_t timestamp = framehdr->ts.tv_sec;
	int usecs = framehdr->ts.tv_usec;
	int max_offset = framehdr->caplen;
	iphdr ip;
	tcphdr tcp;

	/* make sure the frame is long enough */
	if (max_offset < 14 + 20 + 20)
		return;

	/* make sure it's ethernet */
	if (ex16(buf,12) != 0x0800)
		return;

	/* IP */
	ip.offset = 14;
	if (IP_VERSION(buf,ip.offset) != 4)
		return;
	ip.proto = IP_PROTOCOL(buf,ip.offset);
	ip.src = IP_SRC(buf,ip.offset);
	ip.dst = IP_DST(buf,ip.offset);
	ip.data_offset = ip.offset + IP_SIZEOF_HDR(buf,ip.offset);
	if (max_offset > IP_TOTALLENGTH(buf,ip.offset) + ip.offset)
		ip.max_offset = IP_TOTALLENGTH(buf,ip.offset) + ip.offset;
	else
		ip.max_offset = max_offset;

	/* UDP */
	if (ip.proto != 17 )
		return;

	tcp.offset = ip.data_offset;
	tcp.dst = TCP_DST(buf,tcp.offset);
	tcp.src = TCP_SRC(buf,tcp.offset);
	tcp.data_offset = tcp.offset + 8;

#ifdef DO_DUMP
	pcap_dump(NULL, framehdr, (buf));
#endif

	examine(timestamp, usecs, &ip, &tcp, buf);

	return;
}
Exemple #6
0
  /**
   * @brief Retrieve contents of keyword
   *
   * This method retrieves the contents of a keyword.   It is specifically
   * designed to handle Kernel group keywords.  As such, any value of "Table"
   * found in the keyword is not added to the kernel list.
   *
   *
   * @param pvl    ISIS label containing the Kernels group.
   * @param kname  Name of keyword to extract
   * @param manage Default management state to assign to kernels.  The default
   *               is to manage the kernels that are found. See examine() for
   *               full disclosure of how this is set.
   *
   * @return Kernels::KernelList List of scrutinized kernel file names
   */
  Kernels::KernelList Kernels::findKernels(Pvl &pvl,
                                           const QString &kname,
                                           const bool &manage) {
    KernelList klist;
    // Get the kernel group and load main kernels
    PvlGroup &kernels = pvl.findGroup("Kernels",Pvl::Traverse);
    // Check for the keyword
    if (kernels.hasKeyword(kname)) {
      PvlKeyword &kkey = kernels[kname];
      for (int i = 0 ; i < kkey.size() ; i++) {
        if (!kkey.isNull(i)) {
          if (kkey[i].toLower() != "table") {
            klist.push_back(examine(kkey[i], manage));
          }
        }
      }
    }

    return (klist);
  }
Exemple #7
0
 /**
  * @brief Determine which NAIF kernels are currently loaded in the pool
  *
  * This method queries the NAIF KEEPER system/pool for all loaded kernels and
  * adds them to the list in this object.  It only knows about kernels that are
  * loaded by the NAIF furnsh_c routine.  If no kernels are loaded there will
  * be no kernels discovered by this routine.
  *
  * Upon entry into this method, the current list is discarded without
  * unloading them.  Hence, any kernels in this list are discard, whether they
  * are loaded and managed by this class or not.  If they are loaded according
  * to the internal state as determined by previous activity in this class, and
  * no additional NAIF activity has occured that unloads them, they should be
  * found again by this method.
  *
  * Note that ALL kernels discovered by this routine are marked as unmanaged,
  * meaning you cannot unload the kernels without exerting management upon
  * them via the Manage() method.  See the Manage() documentation for more
  * details and potential issues with this feature.
  *
  * This method should not be used to update the load nature of an established
  * kernel list.  See the UpdateLoadStatus() method for this feature.
  *
  * Here is a short coding example showing use of this method.  It assumes
  * there are some kernels already loaded (although it is entirely possible
  * that no kernels are loaded).  It will take over management of these kernels
  * as well:
  *
  * @code
  *   Kernels myKernels;
  *   myKernels.Discover();
  *   myKernels.Manage();
  * @endcode
  *
  * @return int Number of kernels discovered
  */
 int Kernels::Discover() {
   _kernels.clear();
   SpiceInt count;
   ktotal_c("ALL", &count);
   int nfound(0);
   for (int i = 0 ; i < count ; i++) {
     SpiceChar file[128];
     SpiceChar ktype[32];
     SpiceChar source[128];
     SpiceInt  handle;
     SpiceBoolean found;
     kdata_c(i, "ALL", sizeof(file), sizeof(ktype), sizeof(source),
             file, ktype,source, &handle, &found);
     if (found == SPICETRUE) {
       _kernels.push_back(examine(file, false));
       nfound++;
     }
   }
   return (nfound);
 }
Exemple #8
0
/* non-blocking function writing out a current encrypted packet */
void write_packet() {

	int len, written;
	buffer * writebuf;
	
	TRACE(("enter write_packet"));
	assert(!isempty(&ses.writequeue));

	/* Get the next buffer in the queue of encrypted packets to write*/
	writebuf = (buffer*)examine(&ses.writequeue);

	len = writebuf->len - writebuf->pos;
	assert(len > 0);
	/* Try to write as much as possible */
	written = write(ses.sock, buf_getptr(writebuf, len), len);

	if (written < 0) {
		if (errno == EINTR) {
			TRACE(("leave writepacket: EINTR"));
			return;
		} else {
			dropbear_exit("error writing");
		}
	} 

	if (written == 0) {
		dropbear_close("remote host closed connection");
	}

	if (written == len) {
		/* We've finished with the packet, free it */
		dequeue(&ses.writequeue);
		buf_free(writebuf);
	} else {
		/* More packet left to write, leave it in the queue for later */
		buf_incrpos(writebuf, written);
	}

	TRACE(("leave write_packet"));
}
Exemple #9
0
Common::Error TeenAgentEngine::run() {
	Resources *res = Resources::instance();
	if (!res->loadArchives(_gameDescription))
		return Common::kUnknownError;

	Common::EventManager *_event = _system->getEventManager();

	initGraphics(320, 200, false);

	scene = new Scene;
	inventory = new Inventory;
	console = new Console(this);

	scene->init(this, _system);
	inventory->init(this);

	init();

	CursorMan.pushCursor(res->dseg.ptr(0x00da), 8, 12, 0, 0, 1);

	syncSoundSettings();

	_mixer->playStream(Audio::Mixer::kMusicSoundType, &_musicHandle, music, -1, Audio::Mixer::kMaxChannelVolume, 0, DisposeAfterUse::NO, false);
	setMusic(1);
	music->start();

	int load_slot = Common::ConfigManager::instance().getInt("save_slot");
	if (load_slot >= 0) {
		loadGameState(load_slot);
	} else {
		if (!showCDLogo())
			return Common::kNoError;
		if (!showLogo())
			return Common::kNoError;
		if (!showMetropolis())
			return Common::kNoError;
		scene->intro = true;
		scene_busy = true;
		processCallback(0x24c);
	}

	CursorMan.showMouse(true);

	uint32 game_timer = 0;
	uint32 mark_timer = 0;

	Common::Event event;
	Common::Point mouse;
	uint32 timer = _system->getMillis();

	do {
		Object *current_object = scene->findObject(mouse);

		while (_event->pollEvent(event)) {
			if (event.type == Common::EVENT_RTL) {
				deinit();
				return Common::kNoError;
			}

			if ((!scene_busy && inventory->processEvent(event)) || scene->processEvent(event))
				continue;

			//debug(0, "event");
			switch (event.type) {
			case Common::EVENT_KEYDOWN:
				if ((event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d) ||
					event.kbd.ascii == '~' || event.kbd.ascii == '#') {
					console->attach();
				} else if (event.kbd.hasFlags(0) && event.kbd.keycode == Common::KEYCODE_F5) {
					openMainMenuDialog();
				} if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_f) {
					_mark_delay = _mark_delay == 80? 40: 80;
					debug(0, "mark_delay = %u", _mark_delay);
				}
				break;
			case Common::EVENT_LBUTTONDOWN:
				if (scene->getId() < 0)
					break;
				examine(event.mouse, current_object);
				break;
			case Common::EVENT_RBUTTONDOWN:
				//if (current_object)
				//	debug(0, "%d, %s", current_object->id, current_object->name.c_str());
				if (scene->getId() < 0)
					break;

				if (current_object == NULL)
					break;

				if (res->dseg.get_byte(0) == 3 && current_object->id == 1) {
					processCallback(0x5189); //boo!
					break;
				}
				if (res->dseg.get_byte(0) == 4 && current_object->id == 5) {
					processCallback(0x99e0); //getting an anchor
					break;
				}
				use(current_object);
				break;
			case Common::EVENT_MOUSEMOVE:
				mouse = event.mouse;
				break;
			default:
				;
			}
		}

		//game delays: slow 16, normal 11, fast 5, crazy 1
		//mark delays: 4 * (3 - hero_speed), normal == 1
		//game delays in 1/100th of seconds
		uint32 new_timer = _system->getMillis();
		uint32 delta = new_timer - timer;
		timer = new_timer;

		bool tick_game = game_timer <= delta;
		if (tick_game)
			game_timer = _game_delay - ((delta - game_timer) % _game_delay);
		else
			game_timer -= delta;

		bool tick_mark = mark_timer <= delta;
		if (tick_mark)
			mark_timer = _mark_delay - ((delta - mark_timer) % _mark_delay);
		else
			mark_timer -= delta;

		if (tick_game || tick_mark) {
			bool b = scene->render(tick_game, tick_mark, delta);
			if (!inventory->active() && !b && action != kActionNone) {
				processObject();
				action = kActionNone;
				dst_object = NULL;
			}
			scene_busy = b;
		}
		_system->showMouse(scene->getMessage().empty() && !scene_busy);

		bool busy = inventory->active() || scene_busy;

		Graphics::Surface *surface = _system->lockScreen();

		if (!busy) {
			InventoryObject *selected_object = inventory->selectedObject();
			if (current_object || selected_object) {
				Common::String name;
				if (selected_object) {
					name += selected_object->name;
					name += " & ";
				}
				if (current_object)
					name += current_object->name;

				uint w = res->font7.render(NULL, 0, 0, name, 0xd1);
				res->font7.render(surface, (320 - w) / 2, 180, name, 0xd1, true);
#if 0
				if (current_object) {
					current_object->rect.render(surface, 0x80);
					current_object->actor_rect.render(surface, 0x81);
				}
#endif
			}
		}

		inventory->render(surface, tick_game? 1: 0);

		_system->unlockScreen();

		_system->updateScreen();

		console->onFrame();

		uint32 next_tick = MIN(game_timer, mark_timer);
		if (next_tick > 0) {
			_system->delayMillis(next_tick > 40? 40: next_tick);
		}
	} while (!shouldQuit());

	deinit();
	return Common::kNoError;
}
Exemple #10
0
/**
 * Cast a spell.
 * @param op The creature that is owner of the object that is casting the
 * spell.
 * @param caster The actual object (wand, potion) casting the spell. Can
 * be same as op.
 * @param dir Direction to cast in.
 * @param type Spell ID.
 * @param ability If true, the spell is the innate ability of a monster
 * (ie, don't check for blocks_magic(), and don't add AT_MAGIC to attacktype).
 * @param item The type of object that is casting the spell.
 * @param stringarg Any options that are being used.
 * @return 0 on failure, non-zero on success and is used by caller to
 * drain mana/grace. */
int cast_spell(object *op, object *caster, int dir, int type, int ability, SpellTypeFrom item, char *stringarg)
{
	spell *s = find_spell(type);
	shstr *godname = NULL;
	object *target = NULL;
	int success = 0, duration, spell_cost = 0;

	if (!s)
	{
		LOG(llevBug, "BUG: cast_spell(): Unknown spell: %d\n", type);
		return 0;
	}

	/* Get the base duration */
	duration = spells[type].bdur;

	if (!op)
	{
		op = caster;
	}

	/* Script NPCs can ALWAYS cast - even in no spell areas! */
	if (item == spellNPC)
	{
		/* If spellNPC, this usually comes from a script,
		 * and caster is the NPC and op the target. */
		target = op;
		op = caster;
	}
	else
	{
		/* It looks like the only properties we ever care about from the casting
		 * object (caster) is spell paths and level. */
		object *cast_op = op;

		if (!caster)
		{
			if (item == spellNormal)
			{
				caster = op;
			}
		}
		else
		{
			/* Caster has a map? Then we use caster */
			if (caster->map)
			{
				cast_op = caster;
			}
		}

		/* No magic and not a prayer. */
		if (MAP_NOMAGIC(cast_op->map) && spells[type].type == SPELL_TYPE_WIZARD)
		{
			new_draw_info(NDI_UNIQUE, op, "Powerful countermagic cancels all spellcasting here!");
			return 0;
		}

		/* No prayer and a prayer. */
		if (MAP_NOPRIEST(cast_op->map) && spells[type].type == SPELL_TYPE_PRIEST)
		{
			new_draw_info(NDI_UNIQUE, op, "Powerful countermagic cancels all prayer spells here!");
			return 0;
		}

		/* No harm spell and not town safe. */
		if (MAP_NOHARM(cast_op->map) && !(spells[type].flags & SPELL_DESC_TOWN))
		{
			new_draw_info(NDI_UNIQUE, op, "Powerful countermagic cancels all harmful magic here!");
			return 0;
		}

		if (op->type == PLAYER)
		{
			CONTR(op)->praying = 0;

			/* Cancel player spells which are denied, but only real spells (not
			 * potions, wands, etc). */
			if (item == spellNormal)
			{
				if (caster->path_denied & s->path)
				{
					new_draw_info(NDI_UNIQUE, op, "It is denied for you to cast that spell.");
					return 0;
				}

				if (!(QUERY_FLAG(op, FLAG_WIZ)))
				{
					if (spells[type].type == SPELL_TYPE_WIZARD && op->stats.sp < SP_level_spellpoint_cost(caster, type, -1))
					{
						new_draw_info(NDI_UNIQUE, op, "You don't have enough mana.");
						return 0;
					}

					if (spells[type].type == SPELL_TYPE_PRIEST && op->stats.grace < SP_level_spellpoint_cost(caster, type, -1))
					{
						new_draw_info(NDI_UNIQUE, op, "You don't have enough grace.");
						return 0;
					}
				}
			}

			/* If it a prayer, grab the player's god - if we have none, we
			 * can't cast, except for potions. */
			if (spells[type].type == SPELL_TYPE_PRIEST && item != spellPotion)
			{
				if ((godname = determine_god(op)) == shstr_cons.none)
				{
					new_draw_info(NDI_UNIQUE, op, "You need a deity to cast a prayer!");
					return 0;
				}
			}
		}

		/* If it is an ability, assume that the designer of the archetype
		 * knows what they are doing. */
		if (item == spellNormal && !ability && SK_level(caster) < s->level && !QUERY_FLAG(op, FLAG_WIZ))
		{
			new_draw_info(NDI_UNIQUE, op, "You lack enough skill to cast that spell.");
			return 0;
		}

		if (item == spellPotion)
		{
			/* If the potion casts a self spell, don't use the facing
			 * direction. */
			if (spells[type].flags & SPELL_DESC_SELF)
			{
				target = op;
				dir = 0;
			}
		}
		else if (find_target_for_spell(op, &target, spells[type].flags) == 0)
		{
			new_draw_info_format(NDI_UNIQUE, op, "You can't cast that spell on %s!", target ? target->name : "yourself");
			return 0;
		}

		/* If valid target is not in range for selected spell, skip casting. */
		if (target)
		{
			rv_vector rv;

			if (!get_rangevector_from_mapcoords(op->map, op->x, op->y, target->map, target->x, target->y, &rv, RV_DIAGONAL_DISTANCE) || rv.distance > (unsigned int) spells[type].range)
			{
				new_draw_info(NDI_UNIQUE, op, "Your target is out of range!");
				return 0;
			}
		}

		if (op->type == PLAYER && target == op && CONTR(op)->target_object != op)
		{
			new_draw_info(NDI_UNIQUE, op, "You auto-target yourself with this spell!");
		}

		if (!ability && ((s->type == SPELL_TYPE_WIZARD && blocks_magic(op->map, op->x, op->y)) || (s->type == SPELL_TYPE_PRIEST && blocks_cleric(op->map, op->x, op->y))))
		{
			if (op->type != PLAYER)
			{
				return 0;
			}

			if (s->type == SPELL_TYPE_PRIEST)
			{
				new_draw_info_format(NDI_UNIQUE, op, "This ground is unholy! %s ignores you.", godname);
			}
			else
			{
				switch (CONTR(op)->shoottype)
				{
					case range_magic:
						new_draw_info(NDI_UNIQUE, op, "Something blocks your spellcasting.");
						break;

					case range_wand:
						new_draw_info(NDI_UNIQUE, op, "Something blocks the magic of your wand.");
						break;

					case range_rod:
						new_draw_info(NDI_UNIQUE, op, "Something blocks the magic of your rod.");
						break;

					case range_horn:
						new_draw_info(NDI_UNIQUE, op, "Something blocks the magic of your horn.");
						break;

					case range_scroll:
						new_draw_info(NDI_UNIQUE, op, "Something blocks the magic of your scroll.");
						break;

					default:
						break;
				}
			}

			return 0;
		}

		if (item == spellNormal && op->type == PLAYER)
		{
			/* Chance to fumble the spell by too low wisdom. */
			if (s->type == SPELL_TYPE_PRIEST && rndm(0, 99) < s->level / (float) MAX(1, op->chosen_skill->level) * cleric_chance[op->stats.Wis])
			{
				play_sound_player_only(CONTR(op), SOUND_FUMBLE_SPELL, SOUND_NORMAL, 0, 0);
				new_draw_info(NDI_UNIQUE, op, "You fumble the prayer because your wisdom is low.");

				/* Shouldn't happen... */
				if (s->sp == 0)
				{
					return 0;
				}

				return rndm(1, SP_level_spellpoint_cost(caster, type, -1));
			}

			if (s->type == SPELL_TYPE_WIZARD)
			{
				int failure = rndm(0, 199) - CONTR(op)->encumbrance + op->chosen_skill->level - s->level + 35;

				if (failure < 0)
				{
					new_draw_info(NDI_UNIQUE, op, "You bungle the spell because you have too much heavy equipment in use.");
					return rndm(0, SP_level_spellpoint_cost(caster, type, -1));
				}
			}
		}

		/* Now let's talk about action/shooting speed */
		if (op->type == PLAYER)
		{
			switch (CONTR(op)->shoottype)
			{
				case range_wand:
				case range_rod:
				case range_horn:
					op->chosen_skill->stats.maxsp = caster->last_grace;
					break;

				default:
					break;
			}
		}
	}

	/* A last sanity check: are caster and target *really* valid? */
	if ((caster && !OBJECT_ACTIVE(caster)) || (target && !OBJECT_ACTIVE(target)))
	{
		return 0;
	}

	/* We need to calculate the spell point cost before the spell actually
	 * does something, otherwise the following can happen (example):
	 * Player has 7 mana left, kills a monster with magic bullet (which costs 7
	 * mana) while standing right next to it, magic bullet kills the monster before
	 * we reach the return here, player levels up, cost of magic bullet increases
	 * from 7 to 8. So the function would return 8 instead of 7, resulting in the
	 * player's mana being -1. */
	if (item != spellNPC)
	{
		spell_cost = SP_level_spellpoint_cost(caster, type, -1);
	}

	switch ((enum spellnrs) type)
	{
		case SP_RESTORATION:
		case SP_CURE_CONFUSION:
		case SP_MINOR_HEAL:
		case SP_GREATER_HEAL:
		case SP_CURE_POISON:
		case SP_CURE_DISEASE:
			success = cast_heal(op, SK_level(caster), target, type);
			break;

		case SP_REMOVE_DEPLETION:
			success = remove_depletion(op, target);
			break;

		case SP_REMOVE_CURSE:
		case SP_REMOVE_DAMNATION:
			success = remove_curse(op, target, type, item);
			break;

		case SP_STRENGTH:
		case SP_PROT_COLD:
		case SP_PROT_FIRE:
		case SP_PROT_ELEC:
		case SP_PROT_POISON:
			success = cast_change_attr(op, caster, target, type);
			break;

		case SP_IDENTIFY:
			success = cast_identify(target, SK_level(caster), NULL, IDENTIFY_MODE_NORMAL);
			break;

		/* Spells after this use direction and not a target */
		case SP_ICESTORM:
		case SP_FIRESTORM:
			success = cast_cone(op, caster, dir, duration, type, spellarch[type]);
			break;

		case SP_PROBE:
			if (!dir)
			{
				examine(op, op);
				success = 1;
			}
			else
			{
				success = fire_arch_from_position(op, caster, op->x, op->y, dir, spellarch[type], type, NULL);
			}

			break;

		case SP_BULLET:
		case SP_CAUSE_LIGHT:
		case SP_MAGIC_MISSILE:
			success = fire_arch_from_position(op, caster, op->x, op->y, dir, spellarch[type], type, target);
			break;

		case SP_TOWN_PORTAL:
			success = cast_create_town_portal(op);
			break;

		case SP_WOR:
			success = cast_wor(op, caster);
			break;

		case SP_CREATE_FOOD:
			success = cast_create_food(op, caster, dir, stringarg);
			break;

		case SP_CHARGING:
			success = recharge(op);
			break;

		case SP_CONSECRATE:
			success = cast_consecrate(op);
			break;

		case SP_CAUSE_COLD:
		case SP_CAUSE_FLU:
		case SP_CAUSE_LEPROSY:
		case SP_CAUSE_SMALLPOX:
		case SP_CAUSE_PNEUMONIC_PLAGUE:
			success = cast_cause_disease(op, caster, dir, spellarch[type], type);
			break;

		case SP_FINGER_DEATH:
			success = finger_of_death(op, target);
			break;

		case SP_POISON_FOG:
		case SP_METEOR:
		case SP_ASTEROID:
			success = fire_arch_from_position(op, caster, op->x, op->y, dir, spellarch[type], type, NULL);
			break;

		case SP_METEOR_SWARM:
			success = 1;
			fire_swarm(op, caster, dir, spellarch[type], SP_METEOR, 3, 0);
			break;

		case SP_FROST_NOVA:
			success = 1;
			fire_swarm(op, caster, dir, spellarch[type], SP_ASTEROID, 3, 0);
			break;

		case SP_BULLET_SWARM:
			success = 1;
			fire_swarm(op, caster, dir, spellarch[type], SP_BULLET, 5, 0);
			break;

		case SP_BULLET_STORM:
			success = 1;
			fire_swarm(op, caster, dir, spellarch[type], SP_BULLET, 3, 0);
			break;

		case SP_DESTRUCTION:
			success = cast_destruction(op, caster, 5 + op->stats.Int, AT_MAGIC);
			break;

		case SP_BOMB:
			success = create_bomb(op, caster, dir, type);
			break;

		case SP_TRANSFORM_WEALTH:
			success = cast_transform_wealth(op);
			break;

		case SP_RAIN_HEAL:
		case SP_PARTY_HEAL:
			success = cast_heal_around(op, SK_level(caster), type);
			break;

		case SP_FROSTBOLT:
		case SP_FIREBOLT:
		case SP_LIGHTNING:
		case SP_FORKED_LIGHTNING:
		case SP_NEGABOLT:
			success = fire_bolt(op, caster, dir, type);
			break;

		default:
			LOG(llevBug, "BUG: cast_spell(): Invalid invalid spell: %d\n", type);
			break;
	}

	play_sound_map(op->map, op->x, op->y, spells[type].sound, SOUND_SPELL);

	if (item == spellNPC)
	{
		return success;
	}

	return success ? spell_cost : 0;
}
Exemple #11
0
int main(){
	int quit=0;
	world_t * clarkson;
	room_t * prev = NULL;
	char cmd[MAX_CMD_ARGS][BUF_LEN];
	char inp[BUF_LEN];
	inp[BUF_LEN-1] = 0;

	srand(time(NULL));

	clarkson = malloc(sizeof(world_t));
	worldInit(clarkson);

	/* Load data, create world */
	init(clarkson);

	/* This loop takes commands until one works */
	while(!quit) {
		/* Show room updates */
		if (prev != clarkson->room) {
			watsup(clarkson->room);
			prev = clarkson->room;
		}

		printf("What do? ");
		fgets(inp, BUF_LEN-1, stdin); /* Get commands */
		parse(inp, cmd);

		if (striEqu(cmd[0],"quit")) quit=1;
		else if (striEqu(cmd[0],"north")) go(NORTH, &clarkson->room);
		else if (striEqu(cmd[0],"south")) go(SOUTH, &clarkson->room);
		else if (striEqu(cmd[0],"east")) go(EAST, &clarkson->room);
		else if (striEqu(cmd[0],"west")) go(WEST, &clarkson->room);
		else if (striEqu(cmd[0],"up")) go(UP, &clarkson->room);
		else if (striEqu(cmd[0],"down")) go(DOWN, &clarkson->room);
		else if (striEqu(cmd[0],"go")) go(direction(cmd[1]), &clarkson->room);
		else if (striEqu(cmd[0],"take")) take(clarkson->room->items, clarkson->inventory, cmd[1]);
		else if (striEqu(cmd[0],"drop")) drop(clarkson->room->items, clarkson->inventory, cmd[1]);
		else if (striEqu(cmd[0],"look")) watsup(clarkson->room);
		else if (striEqu(cmd[0],"inv")) showinv(clarkson->inventory);
		else if (striEqu(cmd[0],"examine")) examine(clarkson->inventory, clarkson->room->items, cmd[1]);
		else idontunderstand(cmd[0]);

		trigVerify(clarkson);
	}

	/* free() everything */
	for (quit = 0; quit < clarkson->allItems->capacity; quit++) {
		free(clarkson->allItems->itemArray[quit]->name);
		free(clarkson->allItems->itemArray[quit]->description);
		free(clarkson->allItems->itemArray[quit]->examine);
		free(clarkson->allItems->itemArray[quit]);
	}
	free(clarkson->allItems->itemArray);
	free(clarkson->allItems);

	/* TODO Fix freeing of triggers. */
	/* This kludgery reduces it to 81 bytes per run */
	free(clarkson->allTrigs[0].res->param[0].s);
	free(clarkson->allTrigs);
	

	for (quit = 0; quit < clarkson->numRooms; quit++) {
		free(clarkson->allRooms[quit].items->itemArray);
		free(clarkson->allRooms[quit].items);
		free(clarkson->allRooms[quit].description);
	}
	free(clarkson->allRooms);
	free(clarkson->inventory->itemArray);
	free(clarkson->inventory);
	free(clarkson);

	return 0;
}
Exemple #12
0
/* deal with a new player command in countryside mode */
void p_country_process(void)
{
    int no_op;

    drawvision(Player.x,Player.y);
    do {
        no_op = FALSE;
        Cmd = mgetc();
        clear_if_necessary();
        switch (Cmd) {
        case ' ':
        case 13:
            no_op = TRUE;
            break;
        case 7:
            wizard();
            break; /* ^g */
        case 12:
            xredraw();
            no_op = TRUE;
            break; /* ^l */
#if !defined(WIN32)
        case 16:
            bufferprint();
            no_op = TRUE;
            break; /* ^p */
#else
        case 15:
            bufferprint();
            no_op = TRUE;
            break; /* ^o */
#endif
        case 18:
            redraw();
            no_op = TRUE;
            break; /* ^r */
        case 23:
            if (gamestatusp(CHEATED)) drawscreen();
            break; /* ^w */
        case 24:
            if (gamestatusp(CHEATED) ||
                    Player.rank[ADEPT]) wish(1);
            break; /* ^x */
        case 'd':
            drop();
            break;
        case 'e':
            eat();
            break;
        case 'i':
            do_inventory_control();
            break;
        case 's':
            countrysearch();
            break;
        case 'x':
            examine();
            break;
        case 'E':
            dismount_steed();
            break;
        case 'H':
            hunt(Country[Player.x][Player.y].current_terrain_type);
            break;
        case 'I':
            if (! optionp(TOPINV)) top_inventory_control();
            else {
                menuclear();
                display_possessions();
                inventory_control();
            }
            break;
        case 'O':
            setoptions();
            break;
        case 'P':
            show_license();
            break; /* actually show_license is in file.c */
        case 'Q':
            quit();
            break;
        case 'R':
            rename_player();
            break;
        case 'S':
            save(FALSE);
            break;
        case 'V':
            version();
            break;
        case '>':
            enter_site(Country[Player.x][Player.y].base_terrain_type);
            break;
        case '#':
            if (gamestatusp(CHEATED)) editstats();
            break; /* RAC - char editor */
        case '/':
            charid();
            no_op = TRUE;
            break;
        case '?':
            help();
            no_op = TRUE;
            break;
        case '4':
        case 'h':
            movepincountry(-1,0);
            break;
        case '2':
        case 'j':
            movepincountry(0,1);
            break;
        case '8':
        case 'k':
            movepincountry(0,-1);
            break;
        case '6':
        case 'l':
            movepincountry(1,0);
            break;
        case '1':
        case 'b':
            movepincountry(-1,1);
            break;
        case '3':
        case 'n':
            movepincountry(1,1);
            break;
        case '7':
        case 'y':
            movepincountry(-1,-1);
            break;
        case '9':
        case 'u':
            movepincountry(1,-1);
            break;
        default:
            commanderror();
            no_op = TRUE;
            break;
        }
    } while (no_op);
    screencheck(Player.x,Player.y);
}
Exemple #13
0
int main()
{
    examine([](bool a, int b) -> int { return 1; });
    examine([&](){});
}
Exemple #14
0
int main(int argc, char* argv[])
{
	if(argc < 3)
	{
		printf("\n34\n");
		syntax(argv[0]);
		return -1;
	}

	if(argv[1] == 0 || argv[2] == 0)
	{
		printf("\n41\n");
		syntax(argv[0]);
		return -1;
	}

	int sizeOfFirstArray =atoi(argv[1]);
	int sizeOfSecondArray =atoi(argv[2]);
	

	if( (sizeOfFirstArray + sizeOfSecondArray + 3) != argc)
	{
		printf("\n51\n");
		syntax(argv[0]);
		return -1;
	}

	int i, j, k, index;
	int fA[sizeOfFirstArray];
	int sA[sizeOfSecondArray];

	Result result[sizeOfFirstArray/2];

	// inialize data

	 for(i=0;i<sizeOfFirstArray;i++)
	 {
		 fA[i]=atoi(argv[3+i]);
	 }
	
	 j=3+sizeOfFirstArray;
	 for(i=0;i<sizeOfSecondArray;i++)
	 {
		 sA[i]=atoi(argv[j+i]);
	 }
	
	 memset(result, 0x00,sizeof(Result)*(sizeOfFirstArray/2));
	
	 index = -1;
	
	 //Do actual examination of task.
	 for(i=0;i<sizeOfFirstArray-1;i++)
	 {
	 	for(j=i+1;j<sizeOfFirstArray;j++)
	 	{
	 	k = examine(fA[i]+fA[j], sA, sizeOfSecondArray,i,j);
	 		if(-1 !=k)
	 		{
	 		index++;
	 		result[index].i = i;
			result[index].j = j;
	 		result[index].k = k;
	 		}
	 	}
	 }
	
	 // Print result
	 if(-1 == index)
	 {
		 printf("No result");
	 }

	 printf("\n");
	 return 0;
}
Exemple #15
0
// TODO if we draw inventory objects on screen, we need to load a new scene.
// Signal that the inventory has taken over the screen and stop processing mouse events after we have been called
bool Inventory::handleMouseEvent(const Common::Event &ev) {

	// Do not show inventory when on the menu screen
	if (getMenu()->isShown() || !_visible)
		return false;

	// Flag to know whether to restore the current cursor or not
	bool insideInventory = false;

	// Egg (menu)
	if (_menuRect.contains(ev.mouse)) {
		insideInventory = true;
		_engine->getCursor()->setStyle(kCursorNormal);

		// If clicked, show the menu
		if (ev.type == Common::EVENT_LBUTTONUP) {
			getSound()->playSound(kEntityPlayer, "LIB039");
			getMenu()->show(false, kSavegameTypeIndex, 0);

			// TODO can we return directly or do we need to make sure the state will be "valid" when we come back from the menu
			return true;
		} else {
			// Highlight if needed
			if (_highlightedItem != getMenu()->getGameId() + 39) {
				_highlightedItem = (InventoryItem)(getMenu()->getGameId() + 39);
				drawItem(608, 448, _highlightedItem, 100)

				askForRedraw();
			}
		}
	} else {
		// remove highlight if needed
		if (_highlightedItem == getMenu()->getGameId() + 39) {
			drawItem(608, 448, _highlightedItem, 50)
			_highlightedItem = kItemNone;
			askForRedraw();
		}
	}

	// Portrait (inventory)
	if (_inventoryRect.contains(ev.mouse)) {
		insideInventory = true;
		_engine->getCursor()->setStyle(kCursorNormal);

		// If clicked, show pressed state and display inventory
		if (ev.type == Common::EVENT_LBUTTONUP) {
			open();
		} else {
			// Highlight if needed
			if (_highlightedItem != (InventoryItem)getProgress().portrait && !_opened) {
				_highlightedItem = (InventoryItem)getProgress().portrait;
				drawItem(0, 0, getProgress().portrait, 100)

				askForRedraw();
			}
		}
	} else {
		// remove highlight if needed
		if (_highlightedItem == (InventoryItem)getProgress().portrait && !_opened) {
			drawItem(0, 0, getProgress().portrait, 50)
			_highlightedItem = kItemNone;
			askForRedraw();
		}
	}

	// If the inventory is open, check all items rect to see if we need to highlight one / handle click
	if (_opened) {

		// Always show normal cursor when the inventory is opened
		insideInventory = true;
		_engine->getCursor()->setStyle(kCursorNormal);

		bool selected = false;

		// Iterate over items
		int16 y = 44;
		for (int i = 1; i < 32; i++) {
			if (!hasItem((InventoryItem)i))
				continue;

			if (Common::Rect(0, y, 32, 32 + y).contains(ev.mouse)) {

				// If released with an item highlighted, show this item
				if (ev.type == Common::EVENT_LBUTTONUP) {
					if (_entries[i].isSelectable) {
						selected = true;
						_selectedItem = (InventoryItem)i;
						drawItem(44, 0, get(_selectedItem)->cursor, 100)
					}

					examine((InventoryItem)i);
					break;
				} else {
					if (_highlightedItem != i) {
						drawItem(0, y, _entries[i].cursor, 100)
						_highlightedItem = (InventoryItem)i;
						askForRedraw();
					}
				}
			} else {
				// Remove highlight if necessary
				if (_highlightedItem == i) {
Exemple #16
0
/* deal with a new player command in dungeon or city mode*/
void p_process(void)
{
    static int searchval=0;

    if (Player.status[BERSERK])
        if (goberserk()) {
            setgamestatus(SKIP_PLAYER);
            drawvision(Player.x,Player.y);
        }
    if (! gamestatusp(SKIP_PLAYER)) {
        if (searchval > 0) {
            searchval--;
            if (searchval == 0) resetgamestatus(FAST_MOVE);
        }
        drawvision(Player.x,Player.y);
        if (! gamestatusp(FAST_MOVE)) {
            searchval = 0;
            Cmd = mgetc();
            clear_if_necessary();
        }
        Command_Duration = 0;
        switch (Cmd) {
        case ' ':
        case 13:
            setgamestatus(SKIP_MONSTERS);
            break; /*no op on space or return*/
        case 6:
            abortshadowform();
            break; /* ^f */
        case 7:
            wizard();
            break; /* ^g */
        case 4:
            player_dump();
            break; /* ^d */
        case 9:
            display_pack();
            morewait();
            xredraw();
            break; /* ^i */
        case 11:
            if (gamestatusp(CHEATED)) frobgamestatus();
            break;
        case 12:
            xredraw();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^l */
#if !defined(WIN32)
        case 16:
            bufferprint();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^p */
#else
        case 15:
            bufferprint();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^o */
#endif
        case 18:
            redraw();
            setgamestatus(SKIP_MONSTERS);
            break; /* ^r */
        case 23:
            if (gamestatusp(CHEATED)) drawscreen();
            break; /* ^w */
        case 24: /* ^x */
            if (gamestatusp(CHEATED) ||
                    Player.rank[ADEPT])
                wish(1);
            Command_Duration = 5;
            break;
        case 'a':
            zapwand();
            Command_Duration = Player.speed*8/5;
            break;
        case 'c':
            closedoor();
            Command_Duration = Player.speed*2/5;
            break;
        case 'd':
            drop();
            Command_Duration = Player.speed*5/5;
            break;
        case 'e':
            eat();
            Command_Duration = 30;
            break;
        case 'f':
            fire();
            Command_Duration = Player.speed*5/5;
            break;
        case 'g':
            pickup();
            Command_Duration = Player.speed*10/5;
            break;
        case 'i':
            do_inventory_control();
            break;
        case 'm':
            magic();
            Command_Duration = 12;
            break;
        case 'o':
            opendoor();
            Command_Duration = Player.speed*5/5;
            break;
        case 'p':
            pickpocket();
            Command_Duration = Player.speed*20/5;
            break;
        case 'q':
            quaff();
            Command_Duration = 10;
            break;
        case 'r':
            peruse();
            Command_Duration = 20;
            break;
        case 's':
            search(&searchval);
            Command_Duration = 20;
            break;
        case 't':
            talk();
            Command_Duration = 10;
            break;
        case 'v':
            vault();
            Command_Duration = Player.speed*10/5;
            break;
        case 'x':
            examine();
            Command_Duration = 1;
            break;
        case 'z':
            bash_location();
            Command_Duration = Player.speed*10/5;
            break;
        case 'A':
            activate();
            Command_Duration = 10;
            break;
        case 'C':
            callitem();
            break;
        case 'D':
            disarm();
            Command_Duration = 30;
            break;
        case 'E':
            dismount_steed();
            Command_Duration = Player.speed*10/5;
            break;
        case 'F':
            tacoptions();
            break;
        case 'G':
            give();
            Command_Duration = 10;
            break;
        case 'I':
            if (! optionp(TOPINV)) top_inventory_control();
            else {
                display_possessions();
                inventory_control();
            }
            break;
        case 'M':
            city_move();
            Command_Duration = 10;
            break;
        case 'O':
            setoptions();
#if defined(WIN32)
            show_screen();
            xredraw();
#endif
            break;
        case 'P':
            show_license();
            break; /* actually show_license is in file.c */
        case 'Q':
            quit();
            break;
        case 'R':
            rename_player();
            break;
        case 'S':
            save(FALSE);
            break;
        case 'T':
            tunnel();
            Command_Duration =  Player.speed*30/5;
            break;
        case 'V':
            version();
            break;
        case 'Z':
            bash_item();
            Command_Duration = Player.speed*10/5;
            break;
        case '.':
            rest();
            Command_Duration = 10;
            break;
        case ',':
            Command_Duration = 10;
            nap();
            break;
        case '>':
            downstairs();
            break;
        case '<':
            upstairs();
            break;
        case '@':
            p_movefunction(Level->site[Player.x][Player.y].p_locf);
            Command_Duration = 5;
            break;
        case '#':
            if (gamestatusp(CHEATED)) editstats();
            break; /* RAC - char editor */
        case '/':
            charid();
            setgamestatus(SKIP_MONSTERS);
            break;
        case '?':
            help();
            setgamestatus(SKIP_MONSTERS);
            break;
        case '4':
        case 'h':
            moveplayer(-1,0);
            Command_Duration = Player.speed*5/5;
            break;
        case '2':
        case 'j':
            moveplayer(0,1);
            Command_Duration = Player.speed*5/5;
            break;
        case '8':
        case 'k':
            moveplayer(0,-1);
            Command_Duration = Player.speed*5/5;
            break;
        case '6':
        case 'l':
            moveplayer(1,0);
            Command_Duration = Player.speed*5/5;
            break;
        case '1':
        case 'b':
            moveplayer(-1,1);
            Command_Duration = Player.speed*5/5;
            break;
        case '3':
        case 'n':
            moveplayer(1,1);
            Command_Duration = Player.speed*5/5;
            break;
        case '7':
        case 'y':
            moveplayer(-1,-1);
            Command_Duration = Player.speed*5/5;
            break;
        case '9':
        case 'u':
            moveplayer(1,-1);
            Command_Duration = Player.speed*5/5;
            break;
        case '5':
            setgamestatus(SKIP_MONSTERS); /* don't do anything; a dummy turn */
            Cmd = mgetc();
            while ((Cmd != ESCAPE) &&
                    ((Cmd < '1') || (Cmd > '9') || (Cmd=='5'))) {
                print3("Run in keypad direction [ESCAPE to abort]: ");
                Cmd = mgetc();
            }
            if (Cmd != ESCAPE) 
                setgamestatus(FAST_MOVE);
            else
                clearmsg3();
            break;
        case 'H':
            setgamestatus(FAST_MOVE);
            Cmd = 'h';
            moveplayer(-1,0);
            Command_Duration = Player.speed*4/5;
            break;
        case 'J':
            setgamestatus(FAST_MOVE);
            Cmd = 'j';
            moveplayer(0,1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'K':
            setgamestatus(FAST_MOVE);
            Cmd = 'k';
            moveplayer(0,-1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'L':
            setgamestatus(FAST_MOVE);
            Cmd = 'l';
            moveplayer(1,0);
            Command_Duration = Player.speed*4/5;
            break;
        case 'B':
            setgamestatus(FAST_MOVE);
            Cmd = 'b';
            moveplayer(-1,1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'N':
            setgamestatus(FAST_MOVE);
            Cmd = 'n';
            moveplayer(1,1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'Y':
            setgamestatus(FAST_MOVE);
            Cmd = 'y';
            moveplayer(-1,-1);
            Command_Duration = Player.speed*4/5;
            break;
        case 'U':
            setgamestatus(FAST_MOVE);
            Cmd = 'u';
            moveplayer(1,-1);
            Command_Duration = Player.speed*4/5;
            break;
        default:
            commanderror();
            setgamestatus(SKIP_MONSTERS);
            break;
        }
    }
    if (Current_Environment != E_COUNTRYSIDE) roomcheck();
    screencheck(Player.x,Player.y);
}
Exemple #17
0
void player_act()
{
    switch(get_last_action()) {
        case ACTION_TILL:
            till(x, y, current_map);
            break;
        case ACTION_PICKUP: {
            item* it = get_item(items_at(x, y, current_map), item_count_at(x, y, current_map), PURPOSE_PICKUP, true);
            if(!it)
                break;
            printf_message(COLOR_DEFAULT, "Picked up %d %s", it->count, it->name);
            callback("picked_up", it->script_state);
            take_item(x, y, it, current_map);
            add_item(it);
        } break;
        case ACTION_DROP: {
            item* it = get_item(inventory, item_count, PURPOSE_DROP, false);
            if(!it)
                break;
            if(it->can_equip && equipment[it->slot] == it) {
                equipment[it->slot] = 0;
                printf_message(COLOR_DEFAULT, "You unequip the %s, and drop it on the ground.", it->name);
                callback("removed", it->script_state);
            }
            item* clone = clone_item(it);
            callback("dropped", clone->script_state);
            place_item(x, y, clone, current_map);
            remove_item(it, -1);
        } break;
        case ACTION_APPLY: {
            item* it = get_item(inventory, item_count, PURPOSE_APPLY, false);
            if(!it)
                break;
            callback("apply", it->script_state);
            remove_item(it, 1);
        } break;
        case ACTION_EQUIP: {
            item* it = get_item(inventory, item_count, PURPOSE_EQUIP, false);
            if(!it || it->slot == SLOT_INVALID)
                break;
            callback("equip", it->script_state);
            printf_message(COLOR_DEFAULT, "You equip the %s.", it->name);
            equipment[it->slot] = it;
        break; }
        case ACTION_REMOVE: {
            item* it = get_item(equipment, 3, PURPOSE_REMOVE, false);
            if(!it)
                break;
            callback("remove", it->script_state);
            equipment[it->slot] = 0;
            printf_message(COLOR_DEFAULT, "You unequip the %s.", it->name);
        break; }
        case ACTION_PLANT: {
            if(!can_plant(x, y, current_map, true))
                break;
            item* it = get_item(inventory, item_count, PURPOSE_PLANT, false);
            if(!it)
                break;
            if(spawn_plant(x, y, it->plant_id, current_map)) {
                printf_message(COLOR_DEFAULT, "You plant the %s in the tilled soil.", it->name);
                remove_item(it, 1);
            }
        break; }
        case ACTION_HARVEST: {
            add_item(harvest_plant(x, y, current_map));
        break; }
        case ACTION_HELP:
            show_controls();
            break;
        case ACTION_INVENTORY:
            get_item(inventory, item_count, PURPOSE_NONE, false);
            break;
        case ACTION_WATER:
            water_tile(x, y, current_map);
            break;
        case ACTION_EXAMINE: {
            int mx, my;
            get_last_mouse_position(&mx, &my);
            int xdiff = mx - pres_x;
            int ydiff = my - pres_y;
            if(mx < 1 || my < 1 || mx > 78 || my > 78)
                break;
            examine(x + xdiff, y +ydiff, current_map);
        } break;
    }
    if(ep_current <= 0)
        add_message(COLOR_EP_CRIT, "Out of energy, you fall to the ground.");
}