Example #1
0
File: player.c Project: cmr/iiag
void plyr_ev_act_fail(creature * p, void * how) {
	assert(p->act != NULL);

	switch ((action_fail)how) {
	case ACT_FAIL_PICKUP_HEAVY:
		memo("The %s is too heavy to pick up.", p->inv->itms[p->act->p.ind]->name);
		break;
	case ACT_FAIL_PICKUP_PRESENT:
	case ACT_FAIL_DROP_PRESENT:
	case ACT_FAIL_CONSUME_PRESENT:
	case ACT_FAIL_EQUIP_PRESENT:
	case ACT_FAIL_THROW:
		memo("It seems to have vanished!");
		break;
	case ACT_FAIL_DROP_HEAVY:
		memo("The %s is too heavy to drop, silly you.", p->inv->itms[p->act->p.ind]->name);
		break;
	case ACT_FAIL_CONSUME_ABLE:
		memo("Thats wierd... it seems that that is no longer consumable.");
		break;
	case ACT_FAIL_EQUIP_ABLE:
		memo("Thats wierd... it seems that that is no longer equipable.");
		break;
	default:
	}
}
Example #2
0
void crtr_step(creature * c, int step)
{
	int dam;
	int dx = 0, dy = 0;
	int x, y;
	zone * z;

	if (c->step != step) {
		// stamina upkeep
		c->stamina -= 1;
		if (c->stamina <= 0) {
			if (plyr_is_me(c)) {
				plyr_ev_death("starvation");
			} else {
				memo("%s dies of starvation", c->f->name);

				x = c->x;
				y = c->y;
				z = c->z;

				tileof(c)->crtr = NULL;
				crtr_free(c);
				zone_update(z, x, y);
				wrefresh(dispscr);
			}

			return;
		}

		// ai section
		if (!plyr_is_me(c)) {
			// this is pretty ugly

			if (c->x > world.plyr.x) dx = -1;
			else if (c->x < world.plyr.x) dx = 1;

			if (c->y > world.plyr.y) dy = -1;
			else if (c->y < world.plyr.y) dy = 1;

			if (PLYR.x == c->x + dx && PLYR.y == c->y + dy) {
				dam = crtr_attack(c, &PLYR);

				if (dam) {
					memo("%s hits you for %d damage", c->f->name, dam);
				} else {
					memo("%s misses you", c->f->name);
				}
			} else {
				if (!crtr_move(c, dx, dy) && dx && dy) {
					if (!crtr_move(c, dx, 0)) {
						crtr_move(c, 0, dy);
					}
				}
			}
		}

		c->step = step;
	}
}
Example #3
0
void EquipmentData::toObj(json_spirit::Object& eq)
{
    eq.push_back( Pair("id", id) );
    eq.push_back( Pair("name", name()) );
    eq.push_back( Pair("spic", baseid) );
    eq.push_back( Pair("type", type) );
    eq.push_back( Pair("level", qLevel) );
    eq.push_back( Pair("maxLevel", quality*20) );

    int cur = getvalue();
    int add2 = 0;
    int add = equipmentUpgrade::getInstance()->getUpgradeValue(up_quality, type, qLevel + 1, add2);
    eq.push_back( Pair("addNums", cur) );
    eq.push_back( Pair("nextNums", cur + add) );

    if (add2 > 0)
    {
        int cur2 = getvalue2();
        eq.push_back( Pair("addNums2", cur2) );
        eq.push_back( Pair("nextNums2", cur2 + add2) );
    }

    eq.push_back( Pair("quality", quality) );
    eq.push_back( Pair("up_quality", up_quality) );
    eq.push_back( Pair("price", sellPrice()) );
    eq.push_back( Pair("memo", memo()) );
    if (baseEq.get())
    {
        eq.push_back( Pair("needLevel", baseEq->needLevel) );
    }
}
Example #4
0
	int callWithParam(luaT::LuaRef& lobject, const char* func, const EventParam& param, int arg)
	{
		lua_State* L = lobject.getState();
		StackMemo memo(L);

		lobject.pushSelf();
		lua_getfield(L, -1, func);

		if (lua_isnil(L, -1)) return false;

		lobject.pushSelf();

		pushParam(L, param);
		lua_pushinteger(L, arg);
		if (lua_pcall(L, 3, 1, 0))
		{
			LuaUtil::outputErrorMessage(L, func);
			return false;
		}

		if (!lua_isnumber(L, -1))
		{
			cout << "WARNING: EXPLICITLY return integer in event handler" << endl;
			return 0;
		}

		return lua_tointeger(L, -1);
	}
	void LuaComponentSystemFactory::initScriptEnv(GameScene* scene, lua_State* L)
	{
		// export cpp library to lua
		luaopen_all(L);

		// set global environment
		{
			StackMemo memo(L);
			// set global variables
			lua_getglobal(L, "_G");

			// _G.scene 
			setField(L, -1, LUA_G_SCENE, scene);
			setField(L, -1, LUA_G_DISPATCHER, scene->getDispatcher());

			// _G.Time
			lua_createtable(L, 0, 3);
			{
				// _G.Time.change
				setField(L, -1, LUA_G_TIME_CHANGE, 0);
				// _G.Time.global
				setField(L, -1, LUA_G_TIME_GLOBAL, 0);
			}
			lua_setfield(L, -2, LUA_G_TIME);	// TODO: read-only?

			setField(L, -1, LUA_G_ENGINE, mEngine);
			setField(L, -1, LUA_G_WORLD, mEngine->getWorld());
			setField(L, -1, LUA_G_WINDOW, mEngine->getWindow());
		}
	}
Example #6
0
 int maxCoins(vector<int>& nums) 
 {
     nums.insert(nums.begin(), 1);
     nums.push_back(1);
     vector<vector<int>> memo(nums.size(), vector<int>(nums.size(), 0));
     return burst(nums, 0, (int)nums.size()-1, memo);
 }
Example #7
0
File: player.c Project: cmr/iiag
//
// The following functions are called through the command interface
//
void plyr_act_pickup(int argc, char ** argv) {
	int i;

	if (PLYRT.inv->weight == 0) {
		memo("There is nothing here to pick up.");
	} else {
		i = prompt_inv("Pick up what?", PLYRT.inv, NULL);

		if (PLYRT.inv->size > i && PLYRT.inv->itms[i] != NULL) {
			crtr_act_pickup(&PLYR, i);
		} else {
			memo("You try to pick it up, but then you realize it does not exist.");
		}

		redraw();
	}
}
void Run(BenchmarkInternal::Runner& runner)
{
    TMemoizer memo(testFunction);
    Lobatto l;
    while (runner.KeepRunningTime(1))
        for (const auto& ip : l.ips)
            memo.Get(ip);
}
Example #9
0
File: player.c Project: cmr/iiag
void plyr_act_equip(int argc, char ** argv) {
	int i;

	i = prompt_inv("What dost thou equip?", PLYR.inv, &PLYR);

	if (PLYR.inv->size > i && PLYR.inv->itms[i] != NULL) {
		if (PLYR.inv->itms[i]->type & ITEM_EQUIPABLE) {
			crtr_act_equip(&PLYR, i);
		} else {
			memo("It seems trying to equip that would prove fruitless.");
		}
	} else {
		memo("Such an item existeth not.");
	}

	redraw();
}
Example #10
0
File: player.c Project: cmr/iiag
void plyr_act_consume(int argc, char ** argv) {
	int i;

	i = prompt_inv("What dost thou consume?", PLYR.inv, &PLYR);

	if (PLYR.inv->size > i && PLYR.inv->itms[i] != NULL) {
		if (PLYR.inv->itms[i]->type & ITEM_CONSUMABLE) {
			crtr_act_consume(&PLYR, i);
		} else {
			memo("That would upset thy stomach.");
		}
	} else {
		memo("Such an item existeth not.");
	}

	redraw();
}
Example #11
0
File: player.c Project: cmr/iiag
void plyr_act_throw(int argc, char ** argv) {
	int i, dx, dy;

	i = prompt_inv("Throw what?", PLYR.inv, &PLYR);
	redraw();

	if (prompt_dir("Throw where?", &dx, &dy)) {
		if (PLYR.inv->size > i && PLYR.inv->itms[i] != NULL) {
			crtr_act_throw(&PLYR, i, dx, dy);
		} else {
			memo("Such an item existeth not.");
		}
	} else {
		memo("That is not a direction.");
	}

	redraw();
}
    bool isScramble(string s1, string s2) {
        int sz = s1.size();
        if (sz != s2.size())
            return false;

        vector<vector<vector<int>>> memo(
            sz, vector<vector<int>>(sz, vector<int>(sz, -1)));
        return isScramble(s1, 0, s2, 0, sz, memo);
    }
Example #13
0
  /*
   * @param A: An integer array
   * @param k: A positive integer (k <= length(A))
   * @param target: An integer
   * @return: An integer
   */
  int kSum(vector<int> &A, int k, int target)
  {
    if (A.empty() || target <= 0) return 0;

    sort(A.begin(), A.end());
    vector<vector<unordered_map<int, int>>> memo(
      A.size() + 1,
      vector<unordered_map<int, int>>(k + 1, unordered_map<int, int>()));
    return ksum_(A, k, target, 0, memo);
  }
Example #14
0
	LuaEventReceiver::LuaEventReceiver( const luaT::LuaRef& object ) :
		lobject(object)
	{
		setDebugName("LuaEventReceiver");
		XIHAD_MLD_NEW_OBJECT;

		StackMemo memo(lobject.getState());
		lobject.pushSelf();
		UserdataAllocator::makeInstance<UserEventReceiver>(lobject.getState(), -1, this);
	}
Example #15
0
File: player.c Project: cmr/iiag
void plyr_act_enter(int argc, char ** argv) {
	int ox, oy;
	zone * oz;
	tile * t = tileof(&PLYR);

	if (t->linked) {
		// TODO generalize

		if (t->link_z == NULL) {
			ox = PLYR.x;
			oy = PLYR.y;
			oz = PLYR.z;

			// generate new zone
			vector_append(&world.zones, zone_new(150, 50)); // TODO why 150,50?
			t->link_z = world.zones.arr[world.zones.cnt - 1];

			// place player randomly
			crtr_spawn(&PLYR, t->link_z);
			t->link_x = PLYR.x;
			t->link_y = PLYR.y;

			// link back
			t = tileof(&PLYR);
			t->linked = 1;
			t->link_x = ox;
			t->link_y = oy;
			t->link_z = oz;
			t->ch = '@';
			t->show_ch = '@';
		} else {
			if (!crtr_tele(&PLYR, t->link_x, t->link_y, t->link_z)) {
				memo("Your way appears to be blocked?");
			}
		}

		update_vis();
		zone_draw(PLYR.z);
	} else {
		memo("I see no visible method of doing that.");
	}
}
Example #16
0
File: player.c Project: cmr/iiag
void plyr_act_drop(int argc, char ** argv) {
	int i = prompt_inv("You dropped what?", PLYR.inv, &PLYR);

	if (PLYR.inv->size > i && PLYR.inv->itms[i] != NULL) {
		crtr_act_drop(&PLYR, i);
	} else {
		memo("There is no such item.");
	}

	redraw();
}
Example #17
0
int main(int argc, char* argv[]) {
    assert(argc == 2);
    long long count = 0;
    int target = atoi(argv[1]);

    std::vector<int> memo(target + 1, -1);

    for (int i = 0; i <= target; ++i)
        std::cout << "[" << fib_rec(i, memo, ++count) << "]";

    std::cout << std::endl << "Function calls: " << count << std::endl;
}
Example #18
0
static void run_command(char * cmd, int argc, char ** argv)
{
	int i;

	for (i = 0; i < num_commands; i++) {
		if (!strcmp(cmd, command_list[i].cmdstr)) {
			command_list[i].command(argc, argv);
			return;
		}
	}
	memo("Command '%s' unrecognized!", cmd);

}
    int getMoneyAmount(int n) {
        vector<vector<int>> memo(n + 1, (vector<int>(n + 1, 0))); // the result from i to j

        for (int j = 2; j <= n; j++) {
            for (int i = j - 1; i > 0; i--) {
                int minMax = INT_MAX;
                for (int k = i + 1; k < j; k++) {
                    int kMax = k + max(memo[i][k - 1], memo[k + 1][j]);
                    minMax = min(minMax, kMax);
                }
                memo[i][j] = (i + 1 == j) ? i : minMax;
            }
        }
        return memo[1][n];
    }
Example #20
0
File: player.c Project: cmr/iiag
void plyr_ev_death(creature * p, const char * reasons) {
	int i, was_quaz = 0;
	for (i = 0; i < MAX_SLOTS; i++) {
		if (PLYR.slots[i] == NULL)
			continue;
		if (PLYR.slots[i]->mat == NULL)
			break;
		if (strcmp(PLYR.slots[i]->mat->name, "quaz") == 0) {
			was_quaz = 1;
			break;
		}
	}

	if (was_quaz) {
		memo("Quaz o quaz, wherefore art thou forsaking me!? Press q to exit.");
	} else {
		memo("You die of %s, how unfortunate. Press q to exit.", reasons);
	}

	while (wgetch(memoscr) != 'q')
		;
	end_disp();
	exit(0);
}
Example #21
0
File: player.c Project: cmr/iiag
void plyr_ev_act_comp(creature * p, item * it) {
	assert(p->act != NULL);

	switch (p->act->type) {
	case ACT_MOVE:
	case ACT_AA_MOVE:
		update_vis();
		break;
	case ACT_PICKUP:
		memo("Thou dost pickup the %s.", it->name);
		break;
	case ACT_DROP:
		memo("Thou dost drop the %s.", it->name);
		break;
	case ACT_CONSUME:
		memo("Thou dost consume the %s.", it->name);
		break;
	case ACT_EQUIP:
		memo("Thou dost equip the %s to thy %s.", it->name, slot_names[it->slot]);
		break;
	default:
		;
	}
}
Example #22
0
void execute(int keypress)
{
	int i;

	// OPTIMIZE: Change this to binary search?
	for (i = 0; i < num_commands; i++) {
		if (command_list[i].keyval == keypress) {
			command_list[i].command(0, NULL);
			return;
		}
	}

	memo("Unknown key press %d", keypress);
	return;
}
Example #23
0
	void LuaMessageListener::receive( GameObject& pSource, const Parameter& pEvent )
	{
		lua_State* L = mObject.getState();
		StackMemo memo(L);

		mObject.pushOnto(L);
		luaT::getField(L, -1, "onMessage");

		mObject.pushOnto(L);
		push<GameObject*>(L, &pSource);
		pEvent.getLuaObject().pushOnto(L);
		push<const char*>(L, pEvent.getTag().toString().c_str());

		if (lua_pcall(L, 4, 0, 0) != 0)
			LuaUtil::outputErrorMessage(L, "LuaMessageListener::onMessage");
	}
Example #24
0
	LuaMessageListener::LuaMessageListener( luaT::LuaRef& obj ) :
		mObject(obj)
	{
		setDebugName("LuaMessageListener");
		XIHAD_MLD_NEW_OBJECT;

		lua_State* L = mObject.getState();
		StackMemo memo(L);

		mObject.pushSelf();
		xassert(lua_istable(L, -1));

		lua_pushlightuserdata(L, static_cast<MessageListener*>(this));
		lua_setfield(L, -2, luaT::ReservedKeyword::__UDKEY);
		Metatable::bind<MessageListener>(L, -1);
	}
Example #25
0
void toRollbackDialog::displaySQL(void)
{
    std::list<QString> lines = sql();
    QString res;
    for (std::list<QString>::iterator i = lines.begin(); i != lines.end(); i++)
    {
        res += *i;
        res += QString::fromLatin1(";\n");
    }
    if (res.length() > 0)
    {
        toMemoEditor memo(this, res, -1, -1, true, true);
        memo.exec();
    }
    else
        Utils::toStatusMessage(tr("No changes made"), false, false);
}
    int findPaths(int m, int n, int N, int i, int j) {
        if(m == 0 || n == 0 || N == 0) return 0;
        vector<vector<vector<LL>>> memo(N + 1, vector<vector<LL>>(m, vector<LL>(n, -1)));
        for(int step = 0; step < 2; step++) {
            for(auto &row: memo[step])
                fill(row.begin(), row.end(), 0);
        }
        auto &last = memo[1];
        for(int j = 0; j < n; j++) {
            last[0][j]++;
            last[m-1][j]++;
        }
        for(int i = 0; i < m; i++) {
            last[i][0]++;
            last[i][n-1]++;
        }

        return dfs(i, j, N, memo, m, n);
    }
Example #27
0
 int numSquares(int n) {
     
     vector <int> memo(n+1,n+1);
     
     for(int i=1; i*i<=n; i++)
     {
         memo[i*i] = 1;
     }
     
     for(int i=1; i<=n; i++)
     {
         for(int j=1; j*j+i<=n; j++)
         {
             memo[i+j*j] = min(memo[i]+memo[1],memo[i+j*j]);
         }
     }
     
     return memo[n];
 }
Example #28
0
int main () {
    int coins [] = {1, 2, 4, 10, 20, 40, 100, 200, 400, 1000, 2000};
    double ways [7000];
    memo (ways, 0);
    ways [0] = 1;
    for ( int i = 0; i < 11; i++ ) {
        for ( int j = 1; j <= 6000; j++ ) {
            if ( j - coins [i] >= 0 )
                ways [j] += ways [j - coins [i]];
        }
    }
    double c;
    while ( scanf ("%lf", &c) == 1) {
        if (c == 0) break;
        int index = c * 20;
        printf ("%6.2lf%17.lf\n", c, ways [index]);
    }
    return 0;
}
Example #29
0
 bool wordBreak(string s, vector<string>& wordDict) {
     
     int n = s.size();
     vector<bool> memo(n+1,false);
     memo[0] = true;
     for(int i=1; i<=n; i++)
     {
         for(int j=0; j<=i-1; j++)
         {
             if(memo[j]==true)
             {
                 string temp = s.substr(j,i-j);
                 if(findword(temp,wordDict))
                 {
                     memo[i] = true;
                     break;
                 }
             }
         }
     }
     return memo[n];
 }
Example #30
0
static void
list_pivot(data_t pivot, list_t in, list_tl_t* d1, list_tl_t* d2) {

  if(! in ) {
    *d1 = NULL;
    *d2 = NULL;
  }
  else {
    data_t hd = cons_hd(in);
    list_t c  = memo(cons(hd));
    
    if(DATA_COMP(hd, pivot)) {
      memo;
      *d1 = c;
      list_pivot(pivot, *cons_tl(in), cons_tl(c), d2);
    }
    else {
      memo;
      *d2 = c;
      list_pivot(pivot, *cons_tl(in), d1, cons_tl(c));
    }
  }
}