Exemplo n.º 1
0
  SExpr* SPrimScope::tryTypeCheck() {
    // for inlined prims, try to see if primitive will always fail
    if (!InlinePrimitives) return NULL;
    
    bool fail = false;
    switch (pd->type()) {
     case NotReallyAPrimitive:
     case InternalPrimitive:
      fatal("cannot call an internal primitive from Self code");
      return NULL;
     case IntComparisonPrimitive:
     case IntArithmeticPrimitive:
      // must have two smis
      fail = CHECK_INT(receiver) || CHECK_INT(args->last());
      break;

     case FloatArithmeticPrimitive:
     case FloatComparisonPrimitive:
      // must have two floats
      fail = CHECK_FLOAT(receiver) || CHECK_FLOAT(args->last());
      break;
      
     case AtPrimitive:
     case AtPutPrimitive:
      // must have array rcvr and smi arg
      fail = TYPECHECK(receiver, is_objVector()) || CHECK_INT(args->last());
      break;
     case SizePrimitive:
      // must have array rcvr
      fail = TYPECHECK(receiver, is_objVector());
      break;

     case ByteAtPutPrimitive:
      // stored value must be 0..255; for now, test only for integer
      fail = CHECK_INT(args->nth(0));
      // fall through
     case ByteAtPrimitive:
      // must have array rcvr and smi arg
      fail |= TYPECHECK(receiver, is_byteVector()) || CHECK_INT(args->last());
      break;
     case ByteSizePrimitive:
      // must have array rcvr
      fail = TYPECHECK(receiver, is_byteVector());
      break;

     default:
      return NULL;          
    }
    
    if (fail) {
      // primitive will always fail
      ConstPReg* error = new_ConstPReg(_sender, VMString[BADTYPEERROR]);
      Node* dummy;
      MergeNode* mdummy = NULL;
      return genPrimFailure(NULL, error, dummy, mdummy, resultPR, false);
    } else {
      return NULL;
    }
  }
Exemplo n.º 2
0
int LuaGameObject::GossipSendPOI(lua_State* L, GameObject* /*ptr*/)
{
    Player* plr = CHECK_PLAYER(L, 1);
    float x = CHECK_FLOAT(L, 2);
    float y = CHECK_FLOAT(L, 3);
    int icon = static_cast<int>(luaL_checkinteger(L, 4));
    int flags = static_cast<int>(luaL_checkinteger(L, 5));
    int data = static_cast<int>(luaL_checkinteger(L, 6));
    const char* name = luaL_checkstring(L, 7);
    if (!plr)
        return 0;

    plr->Gossip_SendPOI(x, y, icon, flags, data, name);
    return 0;
}
Exemplo n.º 3
0
value sml_exp(value f)
{ double r;
  float_exn = SYS__EXN_OVERFLOW;
  r = exp(Double_val(f));
  CHECK_FLOAT(r);
  return copy_double(r);
}
Exemplo n.º 4
0
value sml_cosh(value f)
{ double r;
  float_exn = SYS__EXN_OVERFLOW;
  r = Double_val(f);
  r = cosh(r);
  CHECK_FLOAT(r);
  return copy_double(r);
}
Exemplo n.º 5
0
value sml_ln(value f)
{ double r;
  float_exn = SYS__EXN_DOMAIN;
  r = Double_val(f);
  RAISE_FLOAT_IF( r <= 0.0 );
  r = log(r);
  CHECK_FLOAT(r);
  return copy_double(r);
}
Exemplo n.º 6
0
value sml_tanh(value f)
{
	double r;
	float_exn = SYS__EXN_DOMAIN;
	r = Double_val(f);
	r = tanh(r);
	CHECK_FLOAT(r);
	return copy_double(r);
}
Exemplo n.º 7
0
int LuaTaxi_AddPathNode(lua_State * L, TaxiPath * tp)
{
	if(tp == NULL)
		RET_NIL(false);

	uint32 mapid = luaL_checkint(L, 1);
	float x = CHECK_FLOAT(L, 2);
	float y = CHECK_FLOAT(L, 3);
	float z = CHECK_FLOAT(L, 4);
	uint32 index = luaL_optnumber(L, 5, tp->GetNodeCount());

	TaxiPathNode* tpn = new TaxiPathNode();
	tpn->mapid = mapid;
	tpn->x = x;
	tpn->y = y;
	tpn->z = z;
	tp->AddPathNode(index, tpn);
	return 1;
}
Exemplo n.º 8
0
value sml_abs_real(value f)
{ double r;
  float_exn = SYS__EXN_OVERFLOW;
  r = Double_val(f);
  if( r >= 0.0 )
    return f;
  else
    r = -r;
  CHECK_FLOAT(r);
  return copy_double(r);
}
Exemplo n.º 9
0
value sml_atan2(value f1, value f2)
{ double r, r1, r2;
  float_exn = SYS__EXN_DOMAIN;
  r1 = Double_val(f1);
  r2 = Double_val(f2);
  if (r1 == 0.0 && r2 == 0.0)
    return copy_double(0.0);
  r = atan2(r1, r2);
  CHECK_FLOAT(r);
  RAISE_FLOAT_IF( r != r );
  return copy_double(r);
}
Exemplo n.º 10
0
value sml_pow(value f1, value f2)
{ double r, r1, r2;
  float_exn = SYS__EXN_DOMAIN;
  r1 = Double_val(f1);
  r2 = Double_val(f2);
  if (r1 == 0.0 && r2 == 0.0)
    return copy_double(1.0);
  if (   (r1 == 0.0 && r2 < 0.0)
      || (r1 < 0.0 && (   fabs(r2) > (double) (MAX_TAGGED_LONG)
		       || r2 != (double)(long)r2)))
    raiseprimitive0(float_exn);
  r = pow(r1, r2);
  float_exn = SYS__EXN_OVERFLOW;
  CHECK_FLOAT(r);
  float_exn = SYS__EXN_DOMAIN;
  RAISE_FLOAT_IF( r != r );
  return copy_double(r);
}
Exemplo n.º 11
0
int LuaGlobalFunctions_PerformIngameSpawn(lua_State * L)
{
	uint32 spawntype = luaL_checkint(L, 1);
	uint32 entry = luaL_checkint(L, 2);
	uint32 map = luaL_checkint(L, 3);
	float x = CHECK_FLOAT(L, 4);
	float y = CHECK_FLOAT(L, 5);
	float z = CHECK_FLOAT(L, 6);
	float o = CHECK_FLOAT(L, 7);
	uint32 faction = luaL_checkint(L, 8); //also scale as percentage
	uint32 duration = luaL_checkint(L, 9);
	uint32 equip1 = luaL_optint(L, 10, 1);
	uint32 equip2 = luaL_optint(L, 11, 1);
	uint32 equip3 = luaL_optint(L, 12, 1);
	//13: instance id
	uint32 save = luaL_optint(L, 14, 0);
	if(x && y && z && entry)
	{
		if (spawntype == 1) //Unit
		{ 
			CreatureProto *p = CreatureProtoStorage.LookupEntry(entry);
			CreatureInfo *i = CreatureNameStorage.LookupEntry(entry);
			if (p == NULL || i == NULL)
				RET_NIL(true);

			MapMgr *mapMgr = sInstanceMgr.GetMapMgr(map);
			if (mapMgr == NULL)
				RET_NIL(true);

			int32 instanceid = luaL_optint(L, 13, mapMgr->GetInstanceID());
			CreatureSpawn * sp = new CreatureSpawn();
			sp->entry = entry;
			sp->id = objmgr.GenerateCreatureSpawnID();
			sp->x = x;
			sp->y = y;
			sp->z = z;
			sp->o = o;
			sp->emote_state = 0;
			sp->flags = 0;
			sp->factionid = faction;
			sp->stand_state = 0;
			sp->phase = 1;
			sp->vehicle = p->vehicle_entry > 0 ? true : false;
			sp->Bytes = NULL;
			sp->ChannelData = NULL;
			sp->MountedDisplay = NULL;

			Creature * pCreature = NULL;
			if(sp->vehicle)
			{
				pCreature = TO_CREATURE(mapMgr->CreateVehicle(entry));
				TO_VEHICLE(pCreature)->Load(sp, mapMgr->iInstanceMode, NULL);
			}
			else
			{
				pCreature = mapMgr->CreateCreature(entry);
				pCreature->Load(sp, mapMgr->iInstanceMode, NULL);
			}

			pCreature->m_loadedFromDB = true;
			pCreature->SetFaction(faction);
			pCreature->SetInstanceID(instanceid);
			pCreature->SetMapId(map);
			pCreature->m_noRespawn = true;
			pCreature->PushToWorld(mapMgr);
			if (duration>0) 
				pCreature->Despawn(duration,0);
			if (save)
				pCreature->SaveToDB();
			Lunar<Unit>::push(L,TO_UNIT(pCreature));
		}
		else if (spawntype == 2) //GO
		{ 
			GameObjectInfo *n = GameObjectNameStorage.LookupEntry(entry);
			if (n == NULL)
				RET_NIL(true);

			MapMgr *mapMgr = sInstanceMgr.GetMapMgr(map);
			if (mapMgr == NULL)
				RET_NIL(true);

			int32 instanceid = luaL_optint(L, 13, mapMgr->GetInstanceID());

			GameObject *go = mapMgr->CreateGameObject(entry);
			go->SetInstanceID(instanceid);
			go->CreateFromProto(entry,map,x,y,z,o);

			// Create spawn instance
			GOSpawn * gs = new GOSpawn;
			gs->entry = go->GetEntry();
			gs->facing = go->GetOrientation();
			gs->faction = go->GetFaction();
			gs->flags = go->GetUInt32Value(GAMEOBJECT_FLAGS);
			gs->id = objmgr.GenerateGameObjectSpawnID();
			gs->scale = go->GetUInt32Value(OBJECT_FIELD_SCALE_X);
			gs->x = go->GetPositionX();
			gs->y = go->GetPositionY();
			gs->z = go->GetPositionZ();
			gs->state = go->GetByte(GAMEOBJECT_BYTES_1, 0);
			gs->phase = 0;

			go->m_spawn = gs;
			go->PushToWorld(mapMgr);
			if (duration)
				sEventMgr.AddEvent(go,&GameObject::ExpireAndDelete,EVENT_GAMEOBJECT_UPDATE,duration,1,EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT);
			if (save)
				go->SaveToDB();
			Lunar<GameObject>::push(L,go);
		}
		else
			RET_NIL(true);
	}
	else
		RET_NIL(true);
	return 1;
}