Пример #1
0
void HomeLayer::healthBarLogic(Ref *sender)
{
	int level = GameData::shareGameData()->mlevel;
	int xp = GameData::shareGameData()->mxp;
	int totalxp = getExp(1.1, level);
	if (xp >= totalxp)
	{
		mxp -= totalxp;
		xp -= totalxp;
		level++;
		mlevel++;
	}

	__String *lelstr = __String::createWithFormat("%d", level);
	levellabel->setString(lelstr->getCString());
	healthBar->setPercentage(((float)xp / (float)totalxp) * 100);

	__String *exp = __String::createWithFormat("%d/%d", xp, totalxp);
	xpLabel->setString(exp->getCString());
	int money = GameData::shareGameData()->mMoney;
	__String *strMoney = __String::createWithFormat("%d", money);
	moneyLabel->setString(strMoney->getCString());

	int coin = GameData::shareGameData()->mCoin;
	__String *strCoin = __String::createWithFormat("%d", coin);
	coinLabel->setString(strCoin->getCString());
}
Пример #2
0
int main(int argc,char **argv){
	int width,height;
	int **pixel;
	int **out;
	float **tmp;
	pixel = readPNG(argv[1],&width,&height);
	
	writePNG("res_original.png",pixel,width,height);

	out = histEQ(pixel,width,height);
	writePNG("res_Equalized.png",out,width,height);
	FREE_PIXEL(out);

	out = getNegative(pixel,width,height);
	writePNG("res_Negative.png",out,width,height);
	FREE_PIXEL(out);

	out = halfIntensity(pixel,width,height);
	writePNG("res_HalfI.png",out,width,height);
	FREE_PIXEL(out);
	
	out = IRescale(pixel,width,height,min,max,0,100);
	writePNG("res_scaleto0100.png",out,width,height);
	FREE_PIXEL(out);

	out = IRescale(pixel,width,height,min,max,200,255);
	writePNG("res_scaleto200255.png",out,width,height);
	FREE_PIXEL(out);

	tmp = getExp(pixel,width,height,20,1.01);
	out = Normalize(tmp,width,height);
	writePNG("res_exp.png",out,width,height);
	FREE_PIXEL(out);

	tmp = getLog(pixel,width,height,20.2);
	out = Normalize(tmp,width,height);
	writePNG("res_log.png",out,width,height);
	FREE_PIXEL(out);
	
	tmp = getPower(pixel,width,height,1,0.5);
	out = Normalize(tmp,width,height);
	writePNG("res_powerg05.png",out,width,height);
	FREE_PIXEL(out);
	
	tmp = getPower(pixel,width,height,1,2);
	out = Normalize(tmp,width,height);
	writePNG("res_powerg2.png",out,width,height);
	FREE_PIXEL(out);

	tmp = getPower(pixel,width,height,1,2.5);
	out = Normalize(tmp,width,height);
	writePNG("res_powerg25.png",out,width,height);
	FREE_PIXEL(out);
	//printHist(out,width,height);

	free(pixel);
return 0;
}
Пример #3
0
int HomeLayer::getExp(float x, float n)
{
	if (n == 0)
	{
		return LEVELXP;
	}

	return x * getExp(x, n - 1);
}
Пример #4
0
void waitD() {
    uint16_t b = getBase();
    volatile uint16_t lb = b;
    char e = getExp();
    volatile char le = e;
    while(le-- != 0) {
        while(lb-- != 0);
        lb = b;
    }
}
Пример #5
0
MM::VOID MM::FlowEdge::toString(MM::String * buf, MM::UINT32 indent)
{
    MM::Edge::toString(buf, indent);
    getSourceName()->toString(buf);
    buf->space();
    buf->append((MM::CHAR*)MM::FlowEdge::MIN_STR, MM::FlowEdge::MIN_LEN);
    getExp()->toString(buf);
    buf->append((MM::CHAR*)MM::FlowEdge::MINGT_STR, MM::FlowEdge::MINGT_LEN);
    buf->space();
    getTargetName()->toString(buf);
}
Пример #6
0
void ch_att::getInfo()
{
	x=getX();
	y=getY();
	lev=getLevel();
	point=getPoint();
	exp=getExp();
	hp=getHP();
	maxhp=getMaxHP();
	att=getAtt();
	sp=getSp();
	getMap();
}
Пример #7
0
bool
flt (uint32_t a,uint32_t b)
{
  if (getExp (a) == 0 && getExp (b) == 0)
    return false;
  if (getSign (a) == 1 && getSign (b) == 1)
    {
      return a > b;  
    }  
  else if (getSign (a) == 1 && getSign (b) == 0)
    {
      return true;      
    }  
  else if (getSign (a) == 0 && getSign (b) == 1) 
    {
      return false;
    }  
  else 
    {
      return a < b;  
    }  		     
}
Пример #8
0
void getStmt(TypePoint returnType,TreeNode *head){
	TreeNode *child = head->firstChild;
	if(child->name == Exp){
		getExp(child);
	}
	else if(child->name == CompSt)
		getCompSt(returnType,child);
	else if(child->name == RETURN){
		TypePoint expType = getExp(child->nextSibling);
		if(testType(expType,returnType)==-1){
			printf("Error type 8 at Line %d: Type mismatched for return.\n",child->nextSibling->lineno);
			return;
		}
	}
	else if(child->name == WHILE){
		child = child->nextSibling->nextSibling;
		TypePoint p = getExp(child);
		if(!(p->kind==BASIC && p->data.basic==INT)){
			printf("Error type 7 at Line %d: Type mismatched for while condition.\n",child->lineno);
			return;
		}
		child = child->nextSibling->nextSibling;
		getStmt(returnType,child);
	}
	else{
		child = child->nextSibling->nextSibling;
		TypePoint p = getExp(child);
		if(!(p->kind == BASIC && p->data.basic == INT)){
			printf("Error type 7 at Line %d: Type mismatched for if condition.\n",child->lineno);
			return;
		}
		child = child->nextSibling->nextSibling;
		getStmt(returnType,child);
		child = child->nextSibling;
		if(child != NULL){
			getStmt(returnType,child->nextSibling);
		}
	}
}
Пример #9
0
local void moneyCommand(const char *command, const char *params, Player *p, const Target *target)
{
	if (target->type == T_PLAYER) //private command
	{
		Player *t = target->u.p;

		if (database->isLoaded(t))
		{
			if (strstr(params, "-d")) //wants details
			{
				int i;
				int total = 0;

				chat->SendMessage(p, "Player %s: money: %i, exp: %i", t->name, getMoney(t), getExp(t));

				for (i = 0; i < MONEY_TYPE_COUNT; i++)
				{
					chat->SendMessage(p, "%s money: $%i", moneyTypeNames[i], getMoneyType(t, i));
					total += getMoneyType(t, i);
				}

				chat->SendMessage(p, "Difference: $%i", getMoney(t) - total);
			}
			else //no details
			{
				chat->SendMessage(p, "Player %s has $%i in their account, and %i experience.", t->name, getMoney(t), getExp(t));
			}
		}
		else
		{
			chat->SendMessage(p, "Player %s has no data loaded.", t->name);
		}
	}
	else //not private, assume public
	{
		if (database->isLoaded(p))
		{
			chat->SendMessage(p, "You have $%i in your account and %i experience.", getMoney(p), getExp(p));
		}
		else
		{
			chat->SendMessage(p, "You have no data loaded.");
		}
	}
}
Пример #10
0
FieldListPoint getDef(TreeNode *head){
	TreeNode* child = head->firstChild;
	TypePoint type = getSpecifier(child);
	if(type == NULL)
		return NULL;
	FieldListPoint r = NULL;
	child = child->nextSibling->firstChild;//child->name = Dec
	for(;;){
		TreeNode *dec = child->firstChild;//dec->name = VarDec;
		FieldListPoint result = getVarDec(type,dec);//Here may exist error type 5:Type mismatched for assignment; Aslo  set dec inital.
		if(opType == 0 || opType == 1){
			if(dec->nextSibling!=NULL){//Dec->VarDec ASSIGNOP Exp{
				if(opType == 0){
					printf("Error type 15 at Line %d: Illegal initial in structure for variable \"%s\".\n",result->lineno,result->name);
					child = child->nextSibling;
					if(child != NULL)
						child = child->nextSibling->firstChild;
					else
						break;
					continue;
					printf("Never arrive this in %s at Line%d.\n",__FILE__,__LINE__);
				}
				else{
					TypePoint t = getExp(dec->nextSibling->nextSibling);
					if(t != NULL && testType(t,type) == -1){
						printf("Error type 7 at Line %d: Type mismatched for \"=\".\n",dec->lineno);
					}
				}
			}
			FieldListPoint newField = (FieldListPoint)malloc(sizeof(FieldList));
			newField->name = result->name;
			newField->type = result->type;
			newField->lineno = dec->lineno;
			newField->tail = r;
			r = newField;
		}
		child = child->nextSibling;
		if(child!=NULL){
			child = child->nextSibling->firstChild;
		}
		else
			break;
	}
	return r;
}
Пример #11
0
GACPforORGSolverGene::GACPforORGSolverGene( OneRelatorGroup& group , const Word& w1 , const Word& w2 ) :
  theWord1( w1 ), 
  theWord2( w2 ), 
  theGroup(group),
  curExp( 0 ),
  fit( -1 ), 
  chromosomes( new GACPforORGSolverChromosome**[ w2.length( ) ] ),
  sizes( new unsigned[ w2.length( ) ]),
  lengthes( new unsigned[ w2.length( ) ]),
  hasConjecture( false ),
  hasShorterWords( false ),
  nChr( 0 )
{ 
  exp = getExp( );
  for( unsigned i=0 ; i<w2.length( ) ; ++i ) {
    chromosomes[i] = 0;
    sizes[i] = 0;
    lengthes[i] = 0;
  }
}
Пример #12
0
local void showExpCommand(const char *command, const char *params, Player *p, const Target *target)
{
	if (target->type == T_PLAYER) //private command
	{
		Player *t = target->u.p;

		if (database->isLoaded(p))
		{
			chat->SendMessage(t, "Player %s has %i experience.", p->name, getExp(p));
			chat->SendMessage(p, "Sent exp status to %s", t->name);
		}
		else
		{
			chat->SendMessage(p, "You have no data loaded.");
		}
	}
	else //not private
	{
		chat->SendMessage(p, "You must target a player.");
	}
}
Пример #13
0
int Character::varExp(const int val){
    return setExp(getExp() + val);
}
Пример #14
0
extern "C" EXPORT_FUNCTION int getExpState(const char name[]) {
    return getExp(name).value("state");
}
Пример #15
0
void PetDetailInfoLayer::resetUI()
{
    auto pet = getCurrBag()->getPetByID(getUserID());//-----得到用户点击的宠物
    
    _islock = pet->isLocked();
    
    if (_islock)
    {
        _imglock->loadTexture("pet_look_b.png", Widget::TextureResType::PLIST);
    }
    else
    {
        _imglock->loadTexture("pet_look_a.png", Widget::TextureResType::PLIST);
    }
    
    auto stTimer = StrengthTimerManager::getInstance()->getTaskByPetID(pet->getUserId());
    stTimer->onTimerUpdate();
    
//-----------------------------------宠物图表信息-------------------------------------//
    _icon->loadTexture(_X(pet->getBigFrontIcon(), _icon));                               //------获取宠物的头像
    
    UIHelper::setStars(_stars[0]->getParent(), pet->getStarNum(), pet->getStarMax());

    _evaluate->loadTexture(pet->getUintIcon(), Widget::TextureResType::PLIST);                                                       //------品种(S, SS, A, 等待)
    
    
    
    //-----------------------------宠物数据信息--------------------------------------------//
    
    _petName->setString(StringUtils::format("Bahamu"));                                  //----宠物名字
    
    _attr->loadTexture(StringUtils::format("base_property%d.png", pet->getKeyPet()->attr), Widget::TextureResType::PLIST); //----宠物的属性(火、水.....)
    
    _lv->setString(StringUtils::format("%s.%d", "Lv", pet->getLevel()));                 //----等级显示
    
    auto monster = MonsterExpConfig::getMonsterExpBy(pet->getLevel());
    
    _lv_Text->setString(StringUtils::format("%d/%d", pet->getExp(), monster->expLvup));  //升级经验数值
    _lv_LoadingBar->setPercent(pet->getExp() * 100.0 / monster->expLvup);                //经验条
    
    _hp_Text->setString(StringUtils::format("%d/%d", pet->getHP(), pet->getHpMax()));    //hp数值
    _hp_LoadingBar->setPercent(pet->getHP() * 100.0 / pet->getHpMax());
    
    _energy_Text->setString(_T("%d/100", pet->getStrength()));                           //------能量值
    _energy_Text->runAction(UserPetTimer::create(_uid));
    _energy_LoadingBar->setPercent(pet->getStrength());                                  //------能量条显示为0
    _energy_LoadingBar->runAction(UserPetTimer::create(_uid));
    
    
    _hp_Value->setString(StringUtils::format("%d", pet->getBaseHp()));                   //-------血量
    _hp_add->setString(StringUtils::format("+%d", pet->getAddedHp()));                   //-------额外增加的
    
    _atk_Value->setString(StringUtils::format("%d", pet->getBaseAttack()));              //-------攻击
    _atk_add->setString(StringUtils::format("+%d", pet->getAddedAttack()));              //-------额外增加的
    
    _def_Value->setString(StringUtils::format("%d", pet->getBaseDefense()));             //-------防御力
    _def_add->setString(StringUtils::format("+%d", pet->getAddedDefense()));
    
    _atc_Value->setString(StringUtils::format("%d", pet->getBaseMAttack()));             //------魔攻
    _atc_add->setString(StringUtils::format("+%d", pet->getAddedMAttack()));
    
    _dec_Value->setString(StringUtils::format("%d", pet->getBaseMDefense()));            //------魔防
    _dec_add->setString(StringUtils::format("+%d", pet->getAddedMDefense()));
    
    _spe_Value->setString(StringUtils::format("%d", pet->getBaseSpeed()));               //------速度
    _spe_add->setString(StringUtils::format("+%d", pet->getAddedSpeed()));
    
}
Пример #16
0
DroidMemory& DroidMemory::operator<<(DroidMemory const& other)
{
    setExp(getExp() + other.getExp());
    setFingerPrint(getFingerPrint() ^ other.getFingerPrint());
    return *this;
}
Пример #17
0
local void setExp(Player *p, int amount)
{
	giveExp(p, amount - getExp(p));
}
Пример #18
0
local void setExpCommand(const char *command, const char *params, Player *p, const Target *target)
{
	int force = 0;
	int quiet = 0;
	char *next;
	char *message;
	int amount;

	while (params != NULL) //get the flags
	{
		if (strncmp(params, "-f", 2) == 0)
		{
			force = 1;
		}
		else if (strncmp(params, "-q", 2) == 0)
		{
			quiet = 1;
		}
		else
		{
			break;
		}

		params = strchr(params, ' ');
		if (params) //check so that params can still == NULL
		{
			params++; //we want *after* the space
		}
	}

	if (params == NULL)
	{
		chat->SendMessage(p, "Grantexp: invalid usage.");
		return;
	}

	amount = strtol(params, &next, 0);

	if (next == params)
	{
		chat->SendMessage(p, "Grantexp: bad amount.");
		return;
	}

	while (*next == ' ') next++; //remove whitespace before the message

	message = next;
	if (message[0] == '\0')
	{
		message = NULL;
	}

	//all the parsing is now complete

	if (target->type == T_PLAYER) //private command
	{
		Player *t = target->u.p;

		if (!force)
		{
			if (database->isLoaded(t))
			{
				int oldAmount = getExp(t);
				setExp(t, amount);

				if (quiet)
				{
					chat->SendMessage(p, "Quietly set player %s's exp to %i (from %i).", t->name, amount, oldAmount);
				}
				else
				{
					if (message == NULL)
					{
						chat->SendMessage(t, "Your exp was set to %i.", amount);
					}
					else
					{
						chat->SendMessage(t, "Your exp was set to %i %s", amount, message);
					}

					chat->SendMessage(p, "Set player %s's exp to %i (from %i).", t->name, amount, oldAmount);
				}
			}
			else
			{
				chat->SendMessage(p, "Player %s has no data loaded.", t->name);
			}
		}
		else
		{
			chat->SendMessage(p, "Whoa there, bud. The -f is only for arena and freq messages.");
		}
	}
	else //not private
	{
		if (force)
		{
			LinkedList set = LL_INITIALIZER;
			Link *link;
			int count;
			pd->TargetToSet(target, &set);

			for (link = LLGetHead(&set); link; link = link->next)
			{
				Player *t = link->data;

				if (database->isLoaded(t))
				{
					setExp(t, amount);

					if (!quiet)
					{
						if (message == NULL)
						{
							chat->SendMessage(t, "Your exp was set to %i.", amount);
						}
						else
						{
							chat->SendMessage(t, "Your exp was set to %i %s", amount, message);
						}
					}
				}
				else
				{
					chat->SendMessage(p, "Player %s has no data loaded.", t->name);
				}
			}

			count = LLCount(&set);

			LLEmpty(&set);

			chat->SendMessage(p, "You set %i players exp to %i.", count, amount);
		}
		else
		{
			chat->SendMessage(p, "For typo safety, the -f must be specified for arena and freq targets.");
		}
	}
}
Пример #19
0
local void showMoneyCommand(const char *command, const char *params, Player *p, const Target *target)
{
	if (target->type == T_PLAYER) //private command
	{
		Player *t = target->u.p;

		if (database->isLoaded(p))
		{
			if (strstr(params, "-e")) //wants exp too
			{
				chat->SendMessage(t, "Player %s has $%i in their account and %i experience.", p->name, getMoney(p), getExp(p));
				chat->SendMessage(p, "Sent money and exp status to %s", t->name);
			}
			else //no exp
			{
				chat->SendMessage(t, "Player %s has $%i in their account.", p->name, getMoney(p));
				chat->SendMessage(p, "Sent money status to %s", t->name);
			}
		}
		else
		{
			chat->SendMessage(p, "You have no data loaded.");
		}
	}
	else //not private
	{
		chat->SendMessage(p, "You must target a player.");
	}
}
Пример #20
0
void Player::save(){
	char sql[10000];
	sprintf_s(sql, 10000, "update keymap set ");
	for(int i=0; i<90; i++){
		char temp[100];
		if(i!=89)
			sprintf_s(temp, 100, "pos%d=%d, ", i, keys[i]);
		else
			sprintf_s(temp, 100, "pos%d=%d where charid=%d; ", i, keys[i], getPlayerid());
		strcat_s(sql, 10000, temp);
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "update characters set level=%d, job=%d, str=%d, dex=%d, intt=%d, luk=%d, chp=%d, mhp=%d, cmp=%d, mmp=%d, ap=%d, sp=%d, exp=%d, fame=%d, map=%d, gender=%d, skin=%d, eyes=%d, hair=%d, mesos=%d where id=%d", getLevel(), getJob(), getStr(), getDex(), getInt(), getLuk(), getHP(), getRMHP(), getMP(), getRMMP(), getAp(), getSp(), getExp(), getFame(), getMap(), getGender(), getSkin(), getEyes(), getHair(), inv->getMesos() ,getPlayerid());
	MySQL::insert(sql);
	char temp[1000];
	sprintf_s(sql, 10000, "delete from equip where charid=%d;", getPlayerid());
	MySQL::insert(sql);
	bool firstrun = true;
	for(int i=0; i<inv->getEquipNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO equip VALUES (%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", inv->getEquip(i)->id, Drops::equips[inv->getEquip(i)->id].type ,getPlayerid(), inv->getEquipPos(i), inv->getEquip(i)->slots, inv->getEquip(i)->scrolls,
				inv->getEquip(i)->istr, inv->getEquip(i)->idex, inv->getEquip(i)->iint, inv->getEquip(i)->iluk, inv->getEquip(i)->ihp, inv->getEquip(i)->imp, inv->getEquip(i)->iwatk, inv->getEquip(i)->imatk, inv->getEquip(i)->iwdef, 
				inv->getEquip(i)->imdef, inv->getEquip(i)->iacc, inv->getEquip(i)->iavo, inv->getEquip(i)->ihand, inv->getEquip(i)->ijump, inv->getEquip(i)->ispeed);
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d)", inv->getEquip(i)->id, Drops::equips[inv->getEquip(i)->id].type ,getPlayerid(), inv->getEquipPos(i), inv->getEquip(i)->slots, inv->getEquip(i)->scrolls,
				inv->getEquip(i)->istr, inv->getEquip(i)->idex, inv->getEquip(i)->iint, inv->getEquip(i)->iluk, inv->getEquip(i)->ihp, inv->getEquip(i)->imp, inv->getEquip(i)->iwatk, inv->getEquip(i)->imatk, inv->getEquip(i)->iwdef, 
				inv->getEquip(i)->imdef, inv->getEquip(i)->iacc, inv->getEquip(i)->iavo, inv->getEquip(i)->ihand, inv->getEquip(i)->ijump, inv->getEquip(i)->ispeed);
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "delete from skills where charid=%d;", getPlayerid());
	MySQL::insert(sql);
	firstrun = true;
	for(int i=0; i<skills->getSkillsNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO skills VALUES (%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d)", getPlayerid(), skills->getSkillID(i), skills->getSkillLevel(skills->getSkillID(i)));
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql);
	sprintf_s(sql, 10000, "DELETE FROM items WHERE charid=%d;", getPlayerid());
	MySQL::insert(sql);
	firstrun = true;
	for(int i=0; i<inv->getItemNum(); i++){
		if(firstrun == true){
			sprintf_s(sql, 10000, "INSERT INTO items VALUES (%d, %d, %d, %d, %d)", inv->getItem(i)->id, getPlayerid() ,inv->getItem(i)->inv, inv->getItem(i)->pos, inv->getItem(i)->amount);
			firstrun = false;
		}
		else{
			sprintf_s(temp, 1000, ",(%d, %d, %d, %d, %d)", inv->getItem(i)->id, getPlayerid() ,inv->getItem(i)->inv, inv->getItem(i)->pos, inv->getItem(i)->amount);
			strcat_s(sql, 10000, temp);
		}
	}
	MySQL::insert(sql);
}
Пример #21
0
extern "C" EXPORT_FUNCTION int getExpRank(const char name[]) {
    return getExp(name).value("rank");
}
Пример #22
0
TypePoint getExp(TreeNode *head){
	TreeNode *child = head->firstChild;
	if(child->name == Exp && child->nextSibling->name == LB){
		//Exp -> Exp LB Exp RB
		TypePoint type1 = getExp(child);
		if(type1 == NULL)
			return NULL;
		if(type1->kind != ARRAY){
			printf("Error type 10 at Line %d: The variable isn't an array.\n",child->lineno);
			return NULL;
		}
		else{
			child = child->nextSibling->nextSibling;
			TypePoint type2 = getExp(child);
			if(type2 == NULL)
				return NULL;
			if(!(type2->kind == BASIC && type2->data.basic == INT)){
				printf("Error type 12 at Line %d:Array index should be an integer.\n",child->lineno);
				return NULL;
			}
			else{
				return type1->data.array.elem;
			}
		}
	}
	else if(child->name == Exp && child->nextSibling->name == DOT){
		//Exp -> Exp DOT ID
		TypePoint type1 = getExp(child);
		if(type1 == NULL)
			return NULL;
		if(type1->kind != STRUCTURE){
			printf("Error type 13 at Line %d: Illegal use of \".\".\n",child->nextSibling->lineno);
			return NULL;
		}
		else{
			child = child->nextSibling->nextSibling;
			FieldListPoint field = type1->data.structure->type->data.structure;
			for(;field!=NULL;field = field->tail){
				if(strcmp(field->name,child->data)==0)
					break;
			}
			if(field == NULL){
				printf("Error type 14 at Line %d: Non-existent field \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			else{
				return field->type;
			}
		}
	}
	else if(child->name == Exp){
		if(child->nextSibling->name == ASSIGNOP){
			//Exp -> Exp ASSIGNOP Exp
			TreeNode *node = child->firstChild;
			if(!((node->name == ID && node->nextSibling == NULL)||(node->name == Exp && node->nextSibling->name == DOT)||(node->name == Exp && node->nextSibling->name  == LB && node->nextSibling->nextSibling->name == Exp))){//When the left is a variable, return NULL;
				printf("Error type 6 at Line %d: The left-hand side of an assignment must be a variable.\n",child->lineno);
				return NULL;
			}
		}
		TypePoint type1 = getExp(child), type2 = getExp(child->nextSibling->nextSibling);

		if(type1 == NULL || type2 == NULL)
			return NULL;

		if(testType(type1,type2)==-1){
			printf("Error type 5 at Line %d: Type mismatched for \"%s\".\n",child->lineno,getName(child->nextSibling->name));
			return NULL;
		}
		if(child->nextSibling->name == ASSIGNOP)
			return type1;
		child = child->nextSibling;
		if(child->name  == AND || child->name == OR){
			//Exp -> Exp AND Exp | Exp OR Exp
			if(!(type1->kind == BASIC && type1->data.basic == INT && type2->kind == BASIC && type2->data.basic == INT)){
				printf("Error type 6 at Line %d: Type mismatched for \"%s\". Two variables' type should be int.\n",child->lineno,child->data);
				return NULL;
			}
		}
		else{
			//Exp -> Exp RELOP Exp | Exp PLUS Exp | Exp MINUS Exp | Exp DIV Exp
			if(!(type1->kind == BASIC && type2->kind == BASIC && type1->data.basic == type2->data.basic)){
				printf("Error type 6 at Line %d: Type mismatched for \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			if(child->name == RELOP){//比较结果应该返回int型的值
				TypePoint newType = (TypePoint)malloc(sizeof(Type));
				newType->kind = BASIC;
				newType->data.basic = INT;
				return newType;
		 	}
		}

		return type1;
	}
	else if(child->name == LP){
		return getExp(child->nextSibling);
	}
	else if(child->name == MINUS || child->name == NOT){
		//Exp -> MINUS Exp | NOT Exp
		TypePoint p = getExp(child->nextSibling);
		if(!(p->kind == BASIC && p->data.basic == INT)){
			printf("Error type 6 at Line %d: Type mismatched for \"%s\".\n",child->lineno,(child->name==NOT)?"!":".");
			return NULL;
		}
		return p;
	}
	else if(child->name == ID){
		if(child->nextSibling != NULL){
			//Exp -> ID LP RP | ID LP Args RP
			TableNode* find = findTableNode(child->data);
			if(find == NULL){
				printf("Error type 2 at Line %d: Undefined function \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			else if(find->type->kind != FUNCTION){
				printf("Error type 11 at Line %d: \"%s\" is not a function.\n",child->lineno,child->data);
				return NULL;
			}
			else{
				TypePoint tempType = find->type;
				if(child->nextSibling->nextSibling->name == RP){
					if(tempType->data.structure->tail == NULL){
						return tempType->data.structure->type;
					}
					else{
						printf("Error type 9 at Line %d: Too few arguments for function \"%s\".\n",child->lineno,find->name);
						return NULL;
					}
				}
				else{
					FieldListPoint argList = tempType->data.structure->tail;
					if(argList == NULL){
						printf("Error type 9 at Line %d: Too many arguments for function \"%s\".\n",child->lineno,child->data);
						return NULL;
					}
					for(child = child->nextSibling->nextSibling->firstChild;;){
						TypePoint childType = getExp(child);
						if(childType == NULL){
							return NULL;
						}
						if(testType(childType,argList->type)==-1){
							printf("Error type 9 at Line %d: Arguments type mismatched.\n",child->lineno);
							return NULL;
						}
						argList = argList->tail;
						//child = child->nextSibling;
						if(argList == NULL && child->nextSibling != NULL){
							printf("Error type 9 at Line %d: Too many arguments for function \"%s\".\n",child->lineno,find->name);
							return NULL;
						}
						if(argList != NULL && child->nextSibling == NULL){
							printf("Error type 9 at Line %d: Too few arguments for function \"%s\".\n",child->lineno,find->name);
							return NULL;
						}
						if(argList == NULL && child->nextSibling == NULL)
							return find->type->data.structure->type;
						child = child->nextSibling->nextSibling->firstChild;
					}
				}
				printf("Should never arrivs this %s %d.\n",__FILE__,__LINE__);
			return tempType->data.structure->type;
			}
		}
		TableNode *find = findTableNode(child->data);
		if(find == NULL){
			if(child->nextSibling == NULL){
				printf("Error type 1 at Line %d: Undefined variable \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
			else{
				printf("Error type 2 at Line %d: Undefined function \"%s\".\n",child->lineno,child->data);
				return NULL;
			}
		}
		else{
			if(find->type->kind == STRUCTURE && find->type->data.structure->name != NULL && strcmp(find->type->data.structure->name,find->name)==0){
				printf("Error type 13 at Line %d: \"%s\" is a struct, isn't a variable.\n",child->lineno,find->name);
				return NULL;
			}
			return find->type;
		}
	}
	else if(child->name == INT){
		TypePoint t = (TypePoint)malloc(sizeof(Type));
		t->kind = BASIC;
		t->data.basic = INT;
		return t;
	}
	else {
		if(child->name != FLOAT){
			printf("Error in %s %d.\n",__FILE__,__LINE__);
		}
		TypePoint t = (TypePoint)malloc(sizeof(Type));
		t->kind = BASIC;
		t->data.basic = FLOAT;
		return t;
	}
}
Пример #23
0
bool HomeLayer::init()
{
	if (!Layer::init())
		return false;
	this->setKeyboardEnabled(true);

	auto ul = Layer::create();
	this->addChild(ul);

	Size winSize = Director::getInstance()->getWinSize();

	auto image = ui::ImageView::create("level.png");
	image->setPosition(Vec2(winSize.width / 2, winSize.height / 2 + 240));
	ul->addChild(image);

	mlevel = GameData::shareGameData()->mlevel;
	mxp = GameData::shareGameData()->mxp;
	char str[32];
	sprintf(str, "%d", mlevel);
	levellabel = Label::create();
	levellabel->setSystemFontSize(48);
	levellabel->setString(str);
	levellabel->setPosition(ccp(image->getPosition().x + 20, image->getPosition().y - 10));
	ul->addChild(levellabel);

	int totalxp = getExp(1.1, mlevel);
	auto timebg = ui::ImageView::create("xp2.png");
	timebg->setPosition(Vec2(winSize.width / 2, image->getPosition().y - image->getContentSize().height / 2 - 20));
	ul->addChild(timebg);

	auto sp = Sprite::create("xp1.png");
	healthBar = ProgressTimer::create(sp);
	ul->addChild(healthBar);
	healthBar->setPosition(Vec2(winSize.width / 2, image->getPosition().y - image->getContentSize().height / 2 - 20));
	healthBar->setType(kCCProgressTimerTypeBar);
	healthBar->setMidpoint(Vec2(0, 0.5));
	healthBar->setBarChangeRate(Vec2(1, 0));
	healthBar->setPercentage(((float)mxp / (float)totalxp) * 100);

	__String *exp = __String::createWithFormat("%d/%d", mxp, totalxp);
	xpLabel = LabelTTF::create(exp->getCString(), "Arial", 25);
	xpLabel->setColor(Color3B::BLUE);
	xpLabel->setPosition(healthBar->getPosition());
	ul->addChild(xpLabel);

	auto *moneyBg = ui::ImageView::create("coin1.png");
	moneyBg->setPosition(Vec2(winSize.width / 2 - 60, winSize.height / 2 - moneyBg->getPosition().y + 100));
	ul->addChild(moneyBg);

	auto *coinBg = ui::ImageView::create("money1.png");
	coinBg->setPosition(Vec2(winSize.width / 2 - 60, winSize.height / 2 - coinBg->getPosition().y));

	ul->addChild(coinBg);

	int money = GameData::shareGameData()->mMoney;
	__String *strMoney = __String::createWithFormat("%d", money);
	moneyLabel = LabelTTF::create();
	moneyLabel->setFontSize(32);
	moneyLabel->setPosition(Vec2(120 + moneyBg->getPosition().x, moneyBg->getPosition().y));
	moneyLabel->setString(strMoney->getCString());
	this->addChild(moneyLabel);

	int coin = GameData::shareGameData()->mCoin;
	__String *strCoin = __String::createWithFormat("%d", coin);
	coinLabel = LabelTTF::create();
	coinLabel->setFontSize(32);
	coinLabel->setPosition(Vec2(coinBg->getPosition().x + 120, coinBg->getPosition().y));
	coinLabel->setString(strCoin->getCString());
	addChild(coinLabel);

	auto *textButton = ui::Button::create();
	textButton->setEnabled(true);
	textButton->loadTextures("zhuangbei1.png", "zhuangbei2.png", "zhuangbei2.png");
	textButton->setPosition(Vec2(textButton->getContentSize().width / 2, winSize.height / 2 + 100));
	textButton->addClickEventListener(CC_CALLBACK_1(HomeLayer::menuCallback, this));
	textButton->setTag(11);
	ul->addChild(textButton);

	auto *textButton1 = ui::Button::create();
	textButton1->setEnabled(true);
	textButton1->loadTextures("yinxiong1.png", "yinxiong2.png", "");
	textButton1->setPosition(Vec2(textButton1->getContentSize().width / 2, winSize.height / 2));
	textButton1->addClickEventListener(CC_CALLBACK_1(HomeLayer::menuCallback, this));
	textButton1->setTag(12);
	ul->addChild(textButton1);

	auto *textButton2 = ui::Button::create();
	textButton2->setEnabled(true);
	textButton2->loadTextures("login1.png", "login2.png", "");
	textButton2->setPosition(Vec2(winSize.width - textButton2->getContentSize().width / 2, winSize.height / 2 + 100));
	textButton2->addClickEventListener(CC_CALLBACK_1(HomeLayer::menuCallback, this));
	textButton2->setTag(13);
	ul->addChild(textButton2);

	auto *textButton3 = ui::Button::create();
	textButton3->setEnabled(true);
	textButton3->loadTextures("levelup1.png", "levelup2.png", "");
	textButton3->setPosition(Vec2(winSize.width - textButton3->getContentSize().width / 2, winSize.height / 2));
	textButton3->addClickEventListener(CC_CALLBACK_1(HomeLayer::menuCallback, this));
	textButton3->setTag(14);
	ul->addChild(textButton3);

	UserDefault *TextFieldV = UserDefault::getInstance();
	coinNum = TextFieldV->getIntegerForKey("coin", 20000);
	diamondsNum = TextFieldV->getIntegerForKey("money", 200);
	UserDefault::sharedUserDefault()->flush();

	healthBarLogic(NULL);
	return true;
}
Пример #24
0
void DroidMemory::setExp(size_t const value)
{
    _exp = value;
}

DroidMemory& DroidMemory::operator<<(DroidMemory const& other)
{
    setExp(getExp() + other.getExp());
    setFingerPrint(getFingerPrint() ^ other.getFingerPrint());
    return *this;
}

DroidMemory& DroidMemory::operator>>(DroidMemory& other) const
{
    other.setExp(getExp() + other.getExp());
    other.setFingerPrint(getFingerPrint() ^ other.getFingerPrint());
    return other;
}

DroidMemory& DroidMemory::operator+=(DroidMemory const& other)
{
    setExp(getExp() + other.getExp());
    setFingerPrint(getFingerPrint() ^ other.getFingerPrint());
    return *this;
}

DroidMemory& DroidMemory::operator+=(size_t const& val)
{
    setExp(getExp() + val);
    setFingerPrint(getFingerPrint() ^ val);
Пример #25
0
void MainWindow::getNextCommande(QString repet)
  {
    pile->setMessage("");
    QString source ;

    if (repet.isEmpty())
        source =commande->text() ;
    else
        source = repet ;

    QString c ;
    QTextStream s (&source) ;
    s>> c ;

    while (c != "") {
        if(c.startsWith('\'')) {//regarde s'il y a une quote
            source = s.readAll() ; //on prend tout ce qu'il y a dans la textStream
            source.push_front(c); //on remet c

            c = getExp(source) ;
            if (!c.isEmpty()){ //si c contient qqch
                controleur->commande(c) ; //on la traite
                commande->clear() ;
                controleur->sauvegarde();
                refresh() ;
                source.remove(c)  ; //on l'enlève de source
                getNextCommande(source) ; //on rappelle la fct avec l'exp en moins
                return ;
            }
            //sinon, alors l'expression est mal écrite, et on annule toute la suite.
            message->setText("exp fausse");
            commande->clear() ;
            return ;
        }

        if(c.startsWith('[')) {//regarde s'il y a [
            source = s.readAll() ; //on prend tout ce qu'il y a dans la textStream
            source.push_front(c); //on remet c

            c = getProg(source) ;
            if (!c.isEmpty()){ //si c contient qqch
                controleur->commande(c) ; //on la traite
                commande->clear() ;
                controleur->sauvegarde();
                refresh() ;
                source.remove(c)  ; //on l'enlève de source
                getNextCommande(source) ; //on rappelle la fct avec l'exp en moins
                return ;
            }

            //sinon, c'est faux, on annule la suite
            message->setText("prog faux");
            commande->clear() ;
            return ;
        }

        controleur->commande(c) ;
        commande->clear() ;
        s>>c ;


    }
    controleur->sauvegarde();
    refresh() ;
    controleur->erreur(false) ;
}
Пример #26
0
bool UserCharacter::handleMessage(const Telegram& msg)
{
	int damage = 0;
	//first see if the current goal accepts the message
	if (getBrain()->handleMessage(msg)) return true;

	//handle any messages not handles by the goals
	switch (msg.msg)
	{
	case MSG_GET_DAMAGED:

		if(isAlive())
		{
			damage = dereferenceToType<int>(msg.extra_info);

			//the extra info field of the telegram carries the amount of damage
		
			// 아직 유저가 죽는것 안함.
			reduceHealth(dereferenceToType<int>(msg.extra_info));

			AbstCharacter* attacker =
				(AbstCharacter*)EntityMgr.getEntityFromID(msg.sender);
			getSensoryMemory()->updateWithDamageSource(attacker, damage);

			//if this bot is now dead let the shooter know
			if (!isAlive())
			{
				int gold_worth = getGoldWorth();
				Dispatcher.dispatchMsg(
					SEND_MSG_IMMEDIATELY,
					getId(),
					msg.sender,
					MSG_GIVE_GOLD,
					(void*)&gold_worth);  // 내 가치를 죽인애한테 gold로 준다.

				Dispatcher.dispatchMsg(
					SEND_MSG_IMMEDIATELY,
					getId(),
					msg.sender,
					MSG_YOU_GOT_ME,
					NULL);  // 내 가치를 죽인애한테 gold로 준다.

				for (auto iter = std::begin(_game_world->getUserCharacters());
					iter != std::end(_game_world->getUserCharacters());
					iter++)
				{
					if (getTeam() != iter->second->getTeam())
					{
						//int damage = _owner_skill->getDamage() + _shooter->getMDamage();
						int exp = getExpWorth();
						//send a message to the bot to let it know it's been hit, and who the
						//shot came from.
						Dispatcher.dispatchMsg(
							SEND_MSG_IMMEDIATELY,
							getId(),
							iter->second->getId(),
							MSG_GIVE_EXP,
							(void*)&exp);
					}
				}
			}
			// hit animation
			float noise_x = util::genRand(0, 30) - 15;
			float noise_y = util::genRand(0, 30) - 15;
			_game_world->getAnimationQ()
				.push(std::make_tuple("damage", _pos.x + noise_x, _pos.y + noise_y));
		}

		return true;

	case MSG_GIVE_GOLD:

		setGold(getGold() + dereferenceToType<int>(msg.extra_info));

		return true;

	case MSG_GIVE_EXP:

		setExp(getExp() + dereferenceToType<int>(msg.extra_info));
		if (getExp() >= _level_up_need_exp)  // level up
		{
			setLevel(getLevel() + 1);
			setExp(getExp() - _level_up_need_exp);
			levelUp();
		}

		return true;

	case MSG_YOU_GOT_ME:  // 내가 누굴 죽였다고 메시지를 받음

		setScore(getScore() + 1);

		//the bot this bot has just killed should be removed as the target
		_target_system->clearTarget();

		return true;

	case MSG_GUN_SHOT_SOUND:

		//add the source of this sound to the bot's percepts
		getSensoryMemory()->updateWithSoundSource((AbstCharacter*)msg.extra_info);

		return true;

	case MSG_USER_HAS_REMOVED_BOT:
	{

		AbstCharacter* pRemovedBot = (AbstCharacter*)msg.extra_info;

		getSensoryMemory()->removeBotFromMemory(pRemovedBot);

		//if the removed bot is the target, make sure the target is cleared
		if (pRemovedBot == getTargetSys()->getTarget())
		{
			getTargetSys()->clearTarget();
		}

		return true;
	}
	case MSG_GAME_OVER:
		GameServerManager::getInstance().sendAll(
			PacketFactory::getInstance().createPacketGameOver(_client_name, _team));
		return true;


	default: return false;
	}
}