function NPC:spawn()
	local dummy = {
		-- This dummy contains defaults for all variables in the ent structure
		-- which should exist for all client-side scripts.
		id = 0,
		x = 0, y = 0, -- position
		mx = 0, my = 0, -- movement
		-- TODO: velocity? (movement gain/loss over time)
		-- May lead to prediction errors seen in SecondLife if not properly handled,
		-- but generally results in overall less information needed to be sent.
		offx = 0, offy = 0, -- frame offsets
		type = 0, -- NPC class
		flags = 0, -- NPC flags
		event = 0, -- may not be sent by server if unnecessary.
		anim = 1,
		frame = 1, -- frame of animation starts at 1, must reset each animation change
		ticks = 0, -- thinks since frame start, resets each frame/animation change
		life = 0 -- thinks since spawn
	}
	for k,v in pairs(dummy)
		if not self[k]
			self[k] = v
		end
	end
	self.info = NPC[self.type]
	if self.info.flags
		self.flags = self.flags | self.info.flags
	end
	if self.id == 0 -- client-side ents don't take up network slots.
		self.id = stage.ent_id
		stage.ents[self.id] = self
		stage.ent_id = self.id + 1
	else
		stage.ents[self.id] = self
	end
	return setmetatable(self,{__index=NPC})
end

function NPC:draw(screen,cx,cy)
	local info = NPC[self.type]
	if not info.anims return end
	if not graphics[info.sheet] return end
	local anim = self.anim
	if not info.anims[self.anim] anim = 1 end
	local frame = info.anims[anim][self.frame][1]
	if self.flags & NPC.FLIP ~= 0 and info.anims[anim][self.frame][2]
		frame = info.anims[anim][self.frame][2]
	end
	local fw = info.display[BBOX.LEFT]+info.display[BBOX.RIGHT]
	local fh = info.display[BBOX.TOP]+info.display[BBOX.BOTTOM]
	screen.draw(graphics[info.sheet],
		{frame[1]+self.offx,frame[2]+self.offy,fw,fh},
		{(math.floor(self.x)-info.display[BBOX.LEFT])-cx,(math.floor(self.y)-info.display[BBOX.TOP])-cy})
end

function NPC:set_anim(anim)
	if self.anim == anim
		return
	end
	self.anim = anim
	self.frame = 1
	self.ticks = 0
end

function NPC:die()
	stage.ents[self.id] = nil
end
