Ejemplo n.º 1
0
	def tick(self,light=True):
		self.lmap = []
		for x in range(0,self.size[0]):
			ycols = []
			for y in range(0,self.size[1]):	
				if not self.type == 'house' and self.flags['sunlit']:
					ycols.append(1)
				else:
					ycols.append(0)
			
			self.lmap.append(ycols)
		
		if not self.type == 'house' and self.flags['sunlit']: return True
		
		if not light: return True
		for y in range(-var.player.perception-(10-var.player.condition['eyes']),var.player.perception-(10-var.player.condition['eyes'])):
			for x in range(-24,25):
				if not 0 < var.player.room_loc[0]+x < self.size[0] and not 0 < var.player.room_loc[1]+y < self.size[1]: continue
				if (abs(var.player.room_loc[0]-(var.player.room_loc[0]+x))+abs(var.player.room_loc[1]-(var.player.room_loc[1]+y))) > 15: continue
				
				if (var.player.room_loc[0],var.player.room_loc[1]) == (var.player.room_loc[0]+x,var.player.room_loc[1]+y): continue
				
				l = ai.line((var.player.room_loc[0],var.player.room_loc[1]),(var.player.room_loc[0]+x,var.player.room_loc[1]+y))
					
				if not l.path[0] == (var.player.room_loc[0],var.player.room_loc[1]):
					l.path.reverse()
											
				done = False
				for lpos in l.path:
					if done: break				
					
					if lpos[0]>=0 and lpos[0]<self.size[0] and lpos[1]>=0 and lpos[1]<self.size[1]:
						if not self.map[lpos[0]][lpos[1]]=='wall':
							self.lmap[lpos[0]][lpos[1]] = 1
							if not self.fmap[lpos[0]][lpos[1]]: self.fmap[lpos[0]][lpos[1]] = True#self.fmap.append([lpos[0],lpos[1]])
						else:
							self.lmap[lpos[0]][lpos[1]] = 1
							if not self.fmap[lpos[0]][lpos[1]]: self.fmap[lpos[0]][lpos[1]] = True
							done = True
Ejemplo n.º 2
0
	def think(self):
		self.need = {'value':0,'obj':None}
		self.want = {'value':0,'obj':None}
		self.hate = {'value':0,'obj':None}
		#self.lhate = self.hate['obj']
		
		#Want/Need
		for o in self.owner.get_room().objects:
			if o.type == 'window': continue
			
			can_see = True
			if not self.owner.room_loc == o.room_loc:
				for pos in ai.line((self.owner.room_loc[0],self.owner.room_loc[1]),(o.room_loc[0],o.room_loc[1])).path:
					if self.owner.get_room().map[pos[0]][pos[1]] == 'wall':
						can_see = False
			
			if not can_see: break
			
			value = self.get_item_value(o)
			
			if value[0] == 'wants':
				if value[1] > self.want['value']:
					self.want = {'obj':o,'value':value[1]}
			elif value[0] == 'needs':
				if value[1] > self.need['value']:
					if self.need['obj']:
						self.need['obj'].in_use = False
						self.need['obj'].user = None
					
					self.need = {'obj':o,'value':value[1]}
		
		#Love/Hate
		for a in self.owner.get_room().guests:
			if not a == self.owner:
				_r = self.examine_person(a.brain)
				
				if _r[0] and _r[0] > self.love['value']:
					self.love = {'obj':a,'value':_r[0]}
				elif _r[1] and _r[1] < self.hate['value']:
					self.hate = {'obj':a,'value':_r[1]}
					
					if self.hate['obj'] == var.player:# and not self.lhate == self.hate['obj']:
						if not self.lhate == self.hate['obj']:
							self.owner.say('seems angered towards you',action=True)
							if self.hate['obj'].lastattacked == self.owner.spouse:

								if self.owner.spouse.male:
									self.owner.say('Get your hands off my husband!')
								else:
									self.owner.say('Get your hands off my wife!')
						
						self.lhate = self.hate['obj']
					
					elif not self.hate['obj'] == None and not self.hate['obj'] == var.player:
						self.owner.say('seems angered towards %s' % (self.hate['obj'].name[0]),action=True)
						self.lhate = self.hate['obj']
		
		if self.want['obj'] == None and self.need['obj'] == None and self.hate == None:
			#var._c.log('%s: I\'m bored...' % (self.owner.name[0]))
			return False
		
		if self.want['value'] > self.need['value'] and self.want['value'] > abs(self.hate['value']):
			#var._c.log(self.owner.name[0]+': I want that %s' % self.want['obj'].name)	
			if self.owner.room_loc[0] == self.want['obj'].room_loc[0] and self.owner.room_loc[1] == self.want['obj'].room_loc[1] and not self.want['obj'].owner:
				#var._c.log(self.owner.name[0]+': Picking up %s' % self.want['obj'].name)
				self.want['obj'].take(self.owner)
				
				self.want = {'value':0,'obj':None}
				
			else:
				if not self.owner.path or not self.owner.path[0] == self.want['obj'].room_loc:
					self.owner.walk_to_room((self.want['obj'].room_loc[0],self.want['obj'].room_loc[1]))

		elif self.want['value'] <= self.need['value'] and self.need['value'] > abs(self.hate['value']):	
			if self.owner.room_loc[0] == self.need['obj'].room_loc[0] and self.owner.room_loc[1] == self.need['obj'].room_loc[1] and not self.need['obj'].owner:
				self.need['obj'].take(self.owner)
				self.need = {'value':0,'obj':None}
			else:
				if not self.owner.path or not self.owner.path[0] == self.need['obj'].room_loc:
					self.owner.walk_to_room((self.need['obj'].room_loc[0],self.need['obj'].room_loc[1]))
		
		elif self.hate['obj']:
			#Can I fight him/her?
			if self.owner.hp >= 8:
				#Find out where he/she is
				#Check surroundings
				found = False
				for pos in [[-1,0],[1,0],[0,-1],[0,1]]:
					if [self.owner.room_loc[0]+pos[0],self.owner.room_loc[1]+pos[1]] == self.hate['obj'].room_loc:
						self.owner.attack([self.owner.room_loc[0]+pos[0],self.owner.room_loc[1]+pos[1]])
						self.owner.path = None
						found = True
				
				if not found:				
					self.owner.walk_to_room((self.hate['obj'].room_loc[0],self.hate['obj'].room_loc[1]))
			else:
				#Figure out what to do
				if not self.owner.drink_potion('health'):
					self.owner.walk_to_room((1,1))
					self.owner.say('flees in terror',action=True)
		
		#if self.love:
		#	var._c.log(self.owner.name[0]+': Love %s' % self.love['obj'].name[0])