def bug_vector_y(percept, dist, scale, theta, p): r = percept.getRadius() / 2 return ( Math.sin(deg2pi(180 + self.towards(percept.getX() + r, percept.getY() + r))) * theta / Math.pow((dist / scale), p) )
def tick(self): if self.t == 0: if self.player.hasPotionEffect(PotionEffectType.INVISIBILITY): self.castSpell('ASSASSIN', 5) if self.clone: self.sound(Sound.ENTITY_EVOKER_CAST_SPELL, .5, 1.6) self.sound(Sound.ENTITY_BLAZE_AMBIENT, .2, 1.5) l = self.player.getEyeLocation().clone().add( Math.sin(self.t * -22.5 * DEG2RAD) * 5, 0, Math.cos(self.t * -22.5 * DEG2RAD) * 5) for e in self.nearbyMobs(l, 3, 3, 3): if e in self.hit: continue self.hit.add(e) self.damage(e, False, 1.5, .7, 0, .3, 0, 0, 0) PySpell.knockback(e, VectorUP, .5) e.addPotionEffect(PotionEffect(PotionEffectType.BLINDNESS, 100, 1)) e.addPotionEffect(PotionEffect(PotionEffectType.SLOW, 20, 8)) self.particle(l.clone().subtract(0, .5, 0), Particle.SWEEP_ATTACK, 4, .5, .5, .5, 0) self.particle(l, Particle.CLOUD if self.clone else Particle.SQUID_INK, 5, .5, .5, .5, .1) self.particle( l, Particle.SPELL_WITCH if self.clone else Particle.CRIT_MAGIC, 10, .5, .5, .5, .2) self.sound(l, Sound.ENTITY_PLAYER_ATTACK_SWEEP, 1, 1.2) self.sound(l, Sound.ITEM_FLINTANDSTEEL_USE, 1, 1.3)
def move(this): if not this._first_time and this._explore_ttl: this._explore_ttl -=1 if not this._explore_ttl % 50: d('explore: '+str(this._explore_ttl)) if not this._explore_ttl: this.me.setBehavior(exploring) return if this._join_ttl: this._join_ttl -= 1 if this._join_ttl: return else: sumx = sumy = 0 for p in this._join_points: sumx += p[0] sumy += p[1] this._join_direction = self.towards(sumx/len(this._join_points), sumy/len(this._join_points)) this._first_time = 0 if not this._cached and len(this.me._killers) > 0: if this._first_time: for pos in this.resolve(this.me._killers, this.getCircle(len(this.me._killers), security_radius)): k = this.me.getKillerByName(pos[0].getName()) k.setPosition(pos[1][0], pos[1][1]) this._cached = 1 else: x = Math.cos(this._join_direction*Math.PI/180) * security_radius y = Math.sin(this._join_direction*Math.PI/180) * security_radius for pos in this.resolve(this.me._killers, this.getHalfCircle(len(this.me._killers), security_radius, x, y)): k = this.me.getKillerByName(pos[0].getName()) k.setPosition(pos[1][0], pos[1][1]) this._cached = 1 this.sendCache()
def update_distances(): covered=self.getCoveredDistance() last_angle=mvt_mem.last_heading - deg_val(mvt_mem.direction) toterm("la"+str(last_angle)+"lh"+str(mvt_mem.last_heading)+"di"+str(deg_val(mvt_mem.direction))) ortho_increment=covered*Math.sin(last_angle) dist_increment=covered*Math.cos(last_angle) mvt_mem.valuable_distance += dist_increment mvt_mem.orthogonal_error += ortho_increment
def update_distances(): covered = self.getCoveredDistance() last_angle = mvt_mem.last_heading - deg_val(mvt_mem.direction) toterm("la" + str(last_angle) + "lh" + str(mvt_mem.last_heading) + "di" + str(deg_val(mvt_mem.direction))) ortho_increment = covered * Math.sin(last_angle) dist_increment = covered * Math.cos(last_angle) mvt_mem.valuable_distance += dist_increment mvt_mem.orthogonal_error += ortho_increment
def tick(self): if self.t == 0: if not self.player.getWorld().getBlockAt( self.player.getLocation().clone().subtract( 0, 1, 0)).isEmpty() or not self.player.getWorld().getBlockAt( self.player.getLocation().clone().subtract( 0, 2, 0)).isEmpty(): #self.player.addScoreboardTag('escape') eye_dir = self.player.getEyeLocation().getDirection() self.player.setVelocity( eye_dir.setY(Math.min(-.4 * Math.abs(eye_dir.getY()), -.4)).multiply(-4)) self.sound(self.player.getLocation(), Sound.ENTITY_BLAZE_SHOOT, 1, 1.2) self.particle( self.player.getLocation().clone().add(0, 1, 0), Particle.VILLAGER_HAPPY if self.clone else Particle.SQUID_INK, 10 if self.clone else 5, .3, 2, .3, .2) if self.clone: self.particle( self.player.getLocation().clone().add(0, 1, 0), Particle.CLOUD, 5, .3, 2, .3, .1) else: self.cancel() return if not self.player.isOnGround(): self.delay() if self.player.isSneaking(): self.player.setVelocity( self.player.getVelocity().clone().subtract(Vector(0, 1, 0))) elif self.player.getVelocity().getY() <= -.5: self.player.getVelocity().setY(-.5) else: if self.player.isSneaking(): for i in range(0, 360, 60): for j in range(9): l = self.player.getLocation().clone().add( Math.sin(i * DEG2RAD) * j, 0, Math.cos(i * DEG2RAD) * j) self.particle(l, Particle.SQUID_INK, 2, 0, 0, 0, .2) self.particle(l, Particle.CLOUD, 2, 0, 0, 0, .2) self.particle(l, Particle.CRIT, 2, 0, 0, 0, .3) self.sound(Sound.ENTITY_GENERIC_EXPLODE, .5, 1.2) self.sound(Sound.ENTITY_IRON_GOLEM_DEATH, 1, 1) for e in self.nearbyMobs(8, 10, 8): self.damage(e, 4) self.player.addPotionEffect( PotionEffect(PotionEffectType.SPEED, 3600, 2, True, False, True))
def miseAJourMouvement(): # Mouvement normal et mise a jour des coordonnees alpha = self.getHeading() * Math.PI / 180 depl_x = 2*Math.cos(alpha) depl_y = 2*Math.sin(alpha) if not self.isMoving(): self.randomHeading() else: coordonnees.setCoord(coordonnees.getX() + depl_x, coordonnees.getY() + depl_y)
def compute_heading(): if (mvt_mem.direction == "EAST"): x_modifier = 2000 y_modifier = 0 elif (mvt_mem.direction == "WEST"): x_modifier = -2000 y_modifier = 0 elif (mvt_mem.direction == "SOUTH"): x_modifier = 0 y_modifier = +2000 elif (mvt_mem.direction == "NORTH"): x_modifier = 0 y_modifier = -1000 # on construit une liste de TOUS les objets répulsifs repulsives = percepts.attackers.items () + \ percepts.explorers.items () + \ percepts.homes.items () + \ percepts.friends.items () + \ percepts.obstacles.items () # valeurs magiques theta = 140 scale = 25 p = 2 u = 30 # composantes X et Y du vecteur direction final X = 0 Y = 0 if repulsives: for it, dist in repulsives: X = X + Math.cos(deg2pi(180 + self.towards(it.getX(), it.getY())) ) * theta / Math.pow(dist / scale, p) Y = Y + Math.sin(deg2pi(180 + self.towards(it.getX(), it.getY())) ) * theta / Math.pow(dist / scale, p) toterm("AFTER REPULSION:" + str(X) + " " + str(Y)) X = X + Math.cos(deg2pi(self.getHeading())) * u Y = Y + Math.sin(deg2pi(self.getHeading())) * u toterm("AFTER ATTRACTION:" + str(X) + " " + str(Y)) X += x_modifier Y += y_modifier toterm("NEW HEADING : " + str(self.towards(X, Y))) self.setHeading(self.towards(X, Y))
def miseAJourMouvement(): # Mouvement normal et mise a jour des coordonnees alpha = self.getHeading() * Math.PI / 180 depl_x = 2 * Math.cos(alpha) depl_y = 2 * Math.sin(alpha) if not self.isMoving(): self.randomHeading() else: coordonnees.setCoord(coordonnees.getX() + depl_x, coordonnees.getY() + depl_y)
def compute_heading (): if (mvt_mem.direction=="EAST"): x_modifier=2000 y_modifier=0 elif (mvt_mem.direction=="WEST"): x_modifier=-2000 y_modifier=0 elif (mvt_mem.direction=="SOUTH"): x_modifier=0 y_modifier=+2000 elif (mvt_mem.direction=="NORTH"): x_modifier=0 y_modifier=-1000 # on construit une liste de TOUS les objets répulsifs repulsives = percepts.attackers.items () + \ percepts.explorers.items () + \ percepts.homes.items () + \ percepts.friends.items () + \ percepts.obstacles.items () # valeurs magiques theta = 140 scale = 25 p = 2 u = 30 # composantes X et Y du vecteur direction final X = 0 Y = 0 if repulsives: for it, dist in repulsives: X = X + Math.cos (deg2pi (180 + self.towards (it.getX(), it.getY()))) * theta / Math.pow (dist/scale, p) Y = Y + Math.sin (deg2pi (180 + self.towards (it.getX(), it.getY()))) * theta / Math.pow (dist/scale, p) toterm ("AFTER REPULSION:"+str(X) +" "+ str(Y)) X = X + Math.cos (deg2pi ( self.getHeading() ))*u Y = Y + Math.sin (deg2pi ( self.getHeading() ))*u toterm ("AFTER ATTRACTION:"+str(X) +" "+ str(Y)) X+=x_modifier Y+=y_modifier toterm ("NEW HEADING : "+str(self.towards (X, Y))) self.setHeading (self.towards (X, Y))
def getHalfCircle(this, num, radius, x, y): if num == 1: return [[x,y]] axe = self.towards(x, y) rayon = radius * (1 - Math.exp(-num/3)) offset = Math.PI / (num-1) points = [] for i in range(num): X = rayon*Math.cos(i*offset+Math.PI/2+axe*Math.PI/180)+x Y = rayon*Math.sin(i*offset+Math.PI/2+axe*Math.PI/180)+y points.append([X,Y]) return points
def tick(self): if self.t < 10: for i in range(3): l = self.player.getLocation().clone().add( Math.sin((10 * self.t + 60 * (i - 1)) * DEG2RAD) * (1.5 - .15 * self.t), self.t, Math.cos((10 * self.t + 60 * (i - 1)) * DEG2RAD) * (1.5 - .15 * self.t)) self.particle( l, Particle.FIREWORKS_SPARK if self.clone else Particle.CRIT, 5, 0, 0, 0, .1 if self.clone else .3) self.particle(l, Particle.SQUID_INK, 3, 0, 0, 0, 0) self.sound(l, Sound.ENTITY_ARROW_SHOOT, 1, 1 + self.t / 20) return l = self.player.getLocation().clone().add(0, 10, 0) self.sound(l, Sound.ENTITY_ARROW_SHOOT, 1, .8) self.sound( l, Sound.ITEM_ARMOR_EQUIP_GOLD if self.clone else Sound.ENTITY_GENERIC_EXPLODE, .8, 1 if self.clone else 1.8) if self.clone: self.sound(l, Sound.ITEM_TOTEM_USE, .8, .8) for i in range(0, 360, 30): for j in range(3): arrow = self.player.getWorld().spawnArrow( l, Vector(Math.sin(i * DEG2RAD), .5 * (j - 1) - 1, Math.cos(i * DEG2RAD)), 3, 1) if self.clone: snowball = self.player.getWorld().spawnEntity( arrow.getLocation(), EntityType.SNOWBALL) snowball.setVelocity(arrow.getVelocity()) snowball.setItem(ItemStack(Material.FLINT)) arrow.remove() arrow = snowball arrow.setShooter(self.player) arrow.addScoreboardTag('rain_arrow')
def __init__(self): Object.__init__(self) # Define low and high tone waveforms. self.low_tone = [] self.high_tone = [] self.gap = [] i = 0 dx = 2 * Math.PI / self.SAMPLES_PER_BIT while i < self.SAMPLES_PER_BIT: low = Math.sin(i * dx) if low >= 0: self.low_tone.add(short(16384)) else: self.low_tone.add(short(-16384)) high = Math.sin(2 * i * dx) if high >= 0: self.high_tone.add(short(16384)) else: self.high_tone.add(short(-16384)) self.gap.add(short(0)) i += 1 # Define a track with a capacity large enough to fit five bytes of # encoded data. # data (bits) bytes per short capacity = 60 * self.SAMPLES_PER_BIT * 2 self.track = AudioTrack(AudioManager.STREAM_MUSIC, self.SAMPLE_RATE, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT, capacity, AudioTrack.MODE_STREAM) self.track.play()
def getCircle(this, num, radius): if num == 0: return None if num == 1: return [[50, 50]] rayon = radius * (1 - Math.exp(-num / 3)) offset = 2 * Math.PI / num points = [] for i in range(num): X = rayon * Math.cos(i * offset) Y = rayon * Math.sin(i * offset) points.append([X, Y]) return points
def getCircle(this, num, radius): if num == 0: return None if num == 1: return [[50,50]] rayon = radius * (1 - Math.exp(-num/3)) offset = 2*Math.PI / num points = [] for i in range(num): X = rayon*Math.cos(i*offset) Y = rayon*Math.sin(i*offset) points.append([X,Y]) return points
def getHalfCircle(this, num, radius, x, y): if num == 1: return [[x, y]] axe = self.towards(x, y) rayon = radius * (1 - Math.exp(-num / 3)) offset = Math.PI / (num - 1) points = [] for i in range(num): X = rayon * Math.cos(i * offset + Math.PI / 2 + axe * Math.PI / 180) + x Y = rayon * Math.sin(i * offset + Math.PI / 2 + axe * Math.PI / 180) + y points.append([X, Y]) return points
def move(this): if this._retreat_ttl: this._retreat_ttl -= 1 if not this._retreat_ttl: this.me.setBehavior(defensing) return if len(this.me._killers) == 0 or not this._enemyX: return x = Math.cos(self.towards(this._enemyX, this._enemyY)*Math.PI/180) * security_radius y = Math.sin(self.towards(this._enemyX, this._enemyY)*Math.PI/180) * security_radius for pos in this.resolve(this.me._killers, this.getHalfCircle(len(this.me._killers), security_radius, x, y)): k = this.me.getKillerByName(pos[0].getName()) #k.setPosition(pos[1][0], pos[1][1]) self.send(k.getAddress(), 'move', str(pos[1][0]), str(pos[1][1]))
def skitter(_field): _maxangle = 2 * Math.PI _ordering = sortBy(_field) _increment = _maxangle / len(_ordering) _curangle = 0 g.nodes[0].outdegree _maxdeg = outdegree.max + 1.0 for _n in _ordering: _radius = 1 - Math.log((_n.outdegree + 1.0) / _maxdeg) _radius = _radius * 500.0 _x = 500.0 + _radius * Math.cos(_curangle) _y = 500.0 + _radius * Math.sin(_curangle) _n.setX(_x) _n.setY(_y) _curangle += _increment
def gene(cible, p): taille = 12 if p.getPerceptType() == "Home": taille = 20 # Distance par rapport au tir angle = self.towards(cible.getX(), cible.getY()) angle = Math.PI * angle / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) dist_x = ( p.getX() + t* p.getY()) / (c + s * t) dist_y = -p.getY()/c + t * dist_x #print self.getAddress().getName() + " --> " + str(dist_x) + " --- " + str(dist_y) return abs(dist_y) < taille and dist_x > 0 and dist_x< cible.distanceTo(Point())
def gene(cible, p): taille = 12 if p.getPerceptType() == "Home": taille = 20 # Distance par rapport au tir angle = self.towards(cible.getX(), cible.getY()) angle = Math.PI * angle / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) dist_x = (p.getX() + t * p.getY()) / (c + s * t) dist_y = -p.getY() / c + t * dist_x #print self.getAddress().getName() + " --> " + str(dist_x) + " --- " + str(dist_y) return abs(dist_y) < taille and dist_x > 0 and dist_x < cible.distanceTo( Point())
def eviteObstacles(percepts): dist1 = dist2 = 500 taille_robot = 20 liste_obstacles = [] for p in percepts: centre = Point() centre.setCoord(p.getX(), p.getY()) liste_obstacles.append(centre) # on dessine 2 droite paralleles a la direction # qui partent des bords du robot -> d1 : y = 12 et d2 : y = -12 # Dans nouveau repere : origine = self # rotation du repere de l'angle de direction courant direction = self.getHeading() angle = Math.PI * direction / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) for p in liste_obstacles: # centre_x, centre_y : centre de l'obstacle dans le repere centre_x = (p.getX() + t * p.getY()) / (c + s * t) centre_y = -p.getY() / c + t * centre_x # savoir quelle droite prendre if centre_x > 0: if centre_y >= 0 and centre_y <= 2 * taille_robot: y = centre_y - taille_robot dist1 = min( dist1, -Math.sqrt(taille_robot * taille_robot - y * y) + centre_x) elif centre_y < 0 and centre_y >= -(2 * taille_robot): y = centre_y + taille_robot dist2 = min( dist2, -Math.sqrt(taille_robot * taille_robot - y * y) + centre_x) if min(dist1, dist2) <= 100 and abs(dist1 - dist2) > 2: if dist1 < dist2: direction += 100 / dist1 else: direction -= 100 / dist2 self.setHeading(direction)
def singleCS(self, vs, into, node, angle): angle += 0.5 * Math.PI angle %= 2.0 * Math.PI wi, h = vs.size.width, vs.size.height a, b = wi / 2.3, h / 2.3 x0, y0 = wi / 2.0, h / 2.0 bx, by = 1, 1 e = Math.sqrt(1 - b**2 / a**2) r = a * Math.sqrt((1 - e**2) / (1 - e**2 * Math.cos(angle)**2)) x = r * Math.cos(angle) + x0 y = -r * Math.sin(angle) + y0 cs = vs.orthoBoxCS(into, node + "_FILLET", -100, x - bx / 2, y - by / 2, 1, 1, bx, by) return cs
def move(this): if not this._first_time and this._explore_ttl: this._explore_ttl -= 1 if not this._explore_ttl % 50: d('explore: ' + str(this._explore_ttl)) if not this._explore_ttl: this.me.setBehavior(exploring) return if this._join_ttl: this._join_ttl -= 1 if this._join_ttl: return else: sumx = sumy = 0 for p in this._join_points: sumx += p[0] sumy += p[1] this._join_direction = self.towards( sumx / len(this._join_points), sumy / len(this._join_points)) this._first_time = 0 if not this._cached and len(this.me._killers) > 0: if this._first_time: for pos in this.resolve( this.me._killers, this.getCircle(len(this.me._killers), security_radius)): k = this.me.getKillerByName(pos[0].getName()) k.setPosition(pos[1][0], pos[1][1]) this._cached = 1 else: x = Math.cos( this._join_direction * Math.PI / 180) * security_radius y = Math.sin( this._join_direction * Math.PI / 180) * security_radius for pos in this.resolve( this.me._killers, this.getHalfCircle(len(this.me._killers), security_radius, x, y)): k = this.me.getKillerByName(pos[0].getName()) k.setPosition(pos[1][0], pos[1][1]) this._cached = 1 this.sendCache()
def move(this): if this._retreat_ttl: this._retreat_ttl -= 1 if not this._retreat_ttl: this.me.setBehavior(defensing) return if len(this.me._killers) == 0 or not this._enemyX: return x = Math.cos(self.towards(this._enemyX, this._enemyY) * Math.PI / 180) * security_radius y = Math.sin(self.towards(this._enemyX, this._enemyY) * Math.PI / 180) * security_radius for pos in this.resolve( this.me._killers, this.getHalfCircle(len(this.me._killers), security_radius, x, y)): k = this.me.getKillerByName(pos[0].getName()) #k.setPosition(pos[1][0], pos[1][1]) self.send(k.getAddress(), 'move', str(pos[1][0]), str(pos[1][1]))
def compute_heading(target, mode): # composantes X et Y du vecteur direction final X = Y = 0 for it, dist in percepts.friends.items(): # percept, dist, scale, theta, p X = X + vector_x(it, dist, 50, 60, 2) Y = Y + vector_y(it, dist, 50, 60, 2) for it, dist in percepts.bases.items(): # Les bases sont boguées : repère sur le coin # supérieur gauche X = X + bug_vector_x(it, dist, 60, 70, 2) Y = Y + bug_vector_y(it, dist, 60, 70, 2) for it, dist in percepts.attackers.items(): # devrait être négligeable... X = X + vector_x(it, dist, 30, 70, 2) Y = Y + vector_y(it, dist, 30, 70, 2) for it, dist in percepts.explorers.items(): X = X + vector_x(it, dist, 20, 60, 1) Y = Y + vector_y(it, dist, 20, 60, 1) for it, dist in percepts.homes.items(): X = X + bug_vector_x(it, dist, 60, 70, 2) Y = Y + bug_vector_y(it, dist, 60, 70, 2) for it, dist in percepts.obstacles.items(): radius = it.getRadius() X = X + vector_x(it, dist, 50 + radius, 60, 2) Y = Y + vector_y(it, dist, 50 + radius, 60, 2) # pour la cible if mode == 'flee': offset = 180 u = 12 # on s'arrache viiiiite !! else: offset = 0 u = 8 X = X + Math.cos( deg2pi(offset + self.towards(target.getX(), target.getY())) ) * u * target.getDistance() Y = Y + Math.sin( deg2pi(offset + self.towards(target.getX(), target.getY())) ) * u * target.getDistance() if immobile(): toterm("immobile") self.setHeading(self.towards(X, Y))
def eviteAmis(percepts): dist1 = dist2 = 500 taille_robot = 20 liste_obstacles = [] for p in percepts: centre = Point() centre.setCoord(p.getX(), p.getY()) liste_obstacles.append(centre) # on dessine 2 droite paralleles a la direction # qui partent des bords du robot -> d1 : y = 12 et d2 : y = -12 # Dans nouveau repere : origine = self # rotation du repere de l"angle de direction courant direction = self.getHeading() angle = Math.PI * direction / 180 t = Math.tan(angle) s = Math.sin(angle) c = Math.cos(angle) for p in liste_obstacles: # centre_x, centre_y : centre de l"obstacle dans le repere centre_x = ( p.getX() + t* p.getY()) / (c + s * t) centre_y = -p.getY()/c + t * centre_x # savoir quelle droite prendre if centre_x > 0: if centre_y >= 0 and centre_y <= 2*taille_robot: y = centre_y - taille_robot dist1 = min(dist1,-Math.sqrt(taille_robot*taille_robot - y*y) + centre_x) elif centre_y < 0 and centre_y >= -(2*taille_robot): y = centre_y + taille_robot dist2 = min(dist2,-Math.sqrt(taille_robot*taille_robot - y*y) + centre_x) if min(dist1, dist2) <= 100 and abs(dist1 - dist2) > 2: if dist1 < dist2: direction += 100/dist1 else: direction -= 100/dist2 self.setHeading(direction)
def tick(self): if self.t == 0: self.bash_loc = self.player.getLocation().clone().add( self.player.getEyeLocation().getDirection().multiply(2).setY( 1)) self.bash() self.sound(self.bash_loc, Sound.ENTITY_GHAST_SHOOT, 1, 1) if self.clone: self.sound(self.bash_loc, Sound.ENTITY_EVOKER_CAST_SPELL, 1, .4) elif self.t == 10: self.bash_loc.add( self.player.getEyeLocation().getDirection().multiply(4).setY( 0)) self.bash() self.sound(self.bash_loc, Sound.ENTITY_WITHER_BREAK_BLOCK, .4 if self.clone else .8, 1.8 if self.clone else .8) if self.clone: self.sound(self.bash_loc, Sound.BLOCK_GLASS_BREAK, 1, 1) self.sound(self.bash_loc, Sound.ENTITY_BLAZE_AMBIENT, .2, .8) for i in range(0, 360, 36): block_loc = self.bash_loc.clone().add( Math.sin(i * DEG2RAD) * 3, .5, Math.cos(i * DEG2RAD) * 3) block_data = (Material.GLOWSTONE if self.clone else Material.DIRT).createBlockData() self.particle(block_loc, Particle.BLOCK_CRACK, 10, .5, .5, .5, .2, block_data) block = self.player.getWorld().spawnFallingBlock( block_loc, block_data) block.setDropItem(False) block.setVelocity( block_loc.subtract( self.bash_loc).toVector().multiply(.05).setY(.4))
def tick(self): if self.t == 0: self.sound(Sound.ENTITY_PLAYER_ATTACK_KNOCKBACK, .5, .5) self.sound(Sound.ENTITY_ENDER_DRAGON_FLAP, 1, 1) self.sound(Sound.ENTITY_ENDER_DRAGON_GROWL, .4, 1) for p in self.player.getWorld().getNearbyEntities( self.player.getLocation(), 8, 8, 8): if not isinstance(p, Player): continue p.addPotionEffect( PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, 4800, 2, True, False, True)) p.addPotionEffect( PotionEffect(PotionEffectType.INCREASE_DAMAGE, 4800, 1, True, False, True)) if self.t <= 8: for i in range(0, 360, 45): l = self.player.getLocation().clone().add( Math.sin(i * DEG2RAD) * (self.t + 1), .2, Math.cos(i * DEG2RAD) * (self.t + 1)) self.particle( l, Particle.CLOUD if self.clone else Particle.SQUID_INK, 3, .1, 0, .1, .1) self.particle(l, Particle.CRIT, 3, .1, 0, .1, .1) self.particle( l, Particle.SPELL_MOB if self.clone else Particle.LAVA, 5 if self.clone else 1, .2, .2, .2, .5) self.scream_loc.add(self.scream_dir) if self.t >= 2: self.particle(self.scream_loc, Particle.EXPLOSION_LARGE, 1, 0, 0, 0, 0) for e in self.nearbyMobs(self.scream_loc, 3, 3, 3): self.damage(e, False, .3, 0, 0, 0, 0, .75, .25)
def compute_heading (target, mode): # composantes X et Y du vecteur direction final X = Y = 0 for it, dist in percepts.friends.items (): # percept, dist, scale, theta, p X = X + vector_x (it, dist, 50, 60, 2) Y = Y + vector_y (it, dist, 50, 60, 2) for it, dist in percepts.bases.items (): # Les bases sont boguées : repère sur le coin # supérieur gauche X = X + bug_vector_x (it, dist, 60, 70, 2) Y = Y + bug_vector_y (it, dist, 60, 70, 2) for it, dist in percepts.attackers.items (): # devrait être négligeable... X = X + vector_x (it, dist, 30, 70, 2) Y = Y + vector_y (it, dist, 30, 70, 2) for it, dist in percepts.explorers.items (): X = X + vector_x (it, dist, 20, 60, 1) Y = Y + vector_y (it, dist, 20, 60, 1) for it, dist in percepts.homes.items (): X = X + bug_vector_x (it, dist, 60, 70, 2) Y = Y + bug_vector_y (it, dist, 60, 70, 2) for it, dist in percepts.obstacles.items (): radius = it.getRadius () X = X + vector_x (it, dist, 50+radius, 60, 2) Y = Y + vector_y (it, dist, 50+radius, 60, 2) # pour la cible if mode == 'flee': offset = 180 u = 12 # on s'arrache viiiiite !! else: offset = 0 u = 8 X = X + Math.cos (deg2pi (offset + self.towards (target.getX(), target.getY()))) * u * target.getDistance () Y = Y + Math.sin (deg2pi (offset + self.towards (target.getX(), target.getY()))) * u * target.getDistance () if immobile (): toterm ("immobile") self.setHeading (self.towards (X, Y))
def isMasqued(x, y): # on ne tire pas si un #@! de copain se trouve devant (verification des percepts seulement ?) for p in self.getPercepts(): if p.getTeam() == self.getTeam() and p.getPerceptType() != 'Rocket': if distance(p.getX(), p.getY()) > distance(x, y): continue a = self.towards(p.getX(), p.getY())*Math.PI/180 b = self.towards(x, y) r = p.getRadius() + security_distance cos = Math.cos(a - Math.PI/2) sin = Math.sin(a - Math.PI/2) inf = self.towards(p.getX() + r*cos, p.getY() + r*sin) sup = self.towards(p.getX() - r*cos, p.getY() - r*sin) #~ d('ene: x: '+str(x)+' y: '+str(y)+' A: '+str(b)+' a: '+str(b*Math.PI/180)) #~ d(' s: '+str(p.getX() + r*cos)+':'+str(p.getY() + r*sin)+' t: '+str(p.getX() - r*cos)+':'+str(p.getY() - r*sin)) #~ d('ami: x: '+str(p.getX())+' y: '+str(p.getY())+' A: '+str(a*180/Math.PI)+' a: '+str(a)+' r: '+str(r)) #~ d('ne pas tirer ene(A) entre '+str(inf)+' et '+str(sup)) #~ d('angles relatifs: ami: '+str((sup - inf) % 360)+' enemy: '+str((b - inf) % 360 )) if ((b - inf) % 360 ) > ((sup - inf) % 360): #~ d('boom!') continue #~ d('un ami me cache la cible!') return 1 return 0
def bug_vector_y(percept, dist, scale, theta, p): r = percept.getRadius() / 2 return Math.sin( deg2pi(180 + self.towards(percept.getX() + r, percept.getY() + r))) * theta / Math.pow( (dist / scale), p)
def tick(self): if self.t == 0: # Find totem totem_id = PersistentDataAPI.getInt( PersistentDataAPI.getData(self.player), 'totem', None) for e in self.player.getNearbyEntities(16, 16, 16): if e.getEntityId() == totem_id: self.totem = e if self.totem is None: PlayerAPI.sendWynnMessage(self.player, 'messages.totem_out') self.cancel() return self.sound(self.totem.getLocation(), Sound.ENTITY_PLAYER_ATTACK_STRONG, .4, 1) self.sound(self.totem.getLocation(), Sound.ENTITY_SHULKER_SHOOT, .9, .7) self.sound(self.totem.getLocation(), Sound.ENTITY_EVOKER_CAST_SPELL, 1, 1.3) self.sound(self.totem.getLocation(), Sound.ENTITY_EVOKER_PREPARE_SUMMON, .7, .5) if self.clone: self.sound(self.totem.getLocation(), Sound.ENTITY_BLAZE_SHOOT, .7, .7) self.sound(self.totem.getLocation(), Sound.ENTITY_FIREWORK_ROCKET_LAUNCH, .4, .6) elif self.t <= 10: i = 0 while i < 360: l = self.totem.getLocation().clone().add( Math.sin(i * DEG2RAD) * (self.t + 1), .4, Math.cos(i * DEG2RAD) * (self.t + 1)) self.particle( l, Particle.SPELL_MOB if self.clone else Particle.CRIT_MAGIC, 0 if self.clone else 1, self.clone, self.clone, self.clone, self.clone) self.damageAndPull(l) i += 15 - self.t elif 15 < self.t <= 25: i = 0 while i < 360: l = self.totem.getLocation().clone().add( Math.sin(i * DEG2RAD) * (26 - self.t), .4, Math.cos(i * DEG2RAD) * (26 - self.t)) self.particle( l, Particle.SPELL_MOB if self.clone else Particle.CRIT_MAGIC, 0 if self.clone else 1, self.clone, self.clone, self.clone, self.clone) self.damageAndPull(l) i += self.t - 14 if self.t % 10 == 0: for i in range(0, 360, 20): self.particle( self.totem.getLocation().clone().add( Math.sin(i * DEG2RAD) * 2, 1.6, Math.cos(i * DEG2RAD) * 2), Particle.FIREWORKS_SPARK, 1, 0, 0, 0, 0) for e in self.nearbyMobs(self.totem.getLocation(), 1, 1, 1): e.addPotionEffect( PotionEffect(PotionEffectType.SLOW, 20, 9, True, False)) if self.t == 10 or self.t == 25: self.hit = set()
def doIt(): global moi global cibles_observees global launcher_vu global liste_rockets global adr_objectif miseAJourMouvement() # Phase de detection percepts = self.getPercepts() liste_obs = [] # Detection des ennemis zero_cible = (cibles_observees == []) nouvelles_cibles = [] cible_launcher = 0 for p in percepts: # On trouve le QG ennemi if p.getPerceptType() == 'Home': liste_obs.append(p) if p.getTeam() != self.getTeam(): b = Point(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) if not baseEnnemieConnue(b): base_ennemie.append(b) self.broadcast(groupName, 'info', 'INFO-QG', str(p.getX()), str(p.getY())) # On entre dans la zone de detection d'un rocket-launcher elif p.getPerceptType( ) == 'RocketLauncher' and p.getTeam() != self.getTeam(): if not launcher_vu: self.broadcast(groupName, 'explorer', 'LAUNCHER_VU') launcher_vu = 1 cible_launcher = 1 c = CibleObs(p) nouvelles_cibles.append(c) elif p.getPerceptType( ) == 'Explorer' and p.getTeam() != self.getTeam(): c = CibleObs(p) nouvelles_cibles.append(c) liste_obs.append(p) elif p.getPerceptType() == 'RocketLauncher' and p.getTeam( ) == self.getTeam(): liste_obs.append(p) if adr_objectif != None: if coordonnees.distanceTo(objectif) < 110: # or cible_launcher: objectif.setConnu(0) self.send(adr_objectif, 'ROCKET-FIN') adr_objectif = None else: self.setHeading( self.towards(objectif.getX() - coordonnees.getX(), objectif.getY() - coordonnees.getY())) # Mise a jour des cibles vues par plusieurs explorateurs nb_vus_par_autre = 0 longueur = len(cibles_observees) for c in nouvelles_cibles: pos = Point() pos.setCoord(c.getX(), c.getY()) trouve = 0 i = 0 while not trouve and i < longueur: c_anc = cibles_observees[i] if c_anc.getVuParAutre() and pos.distanceTo(c_anc.getCoord()) < 10: trouve = 1 c.setVuParAutre(c_anc.getVuParAutre() - 1) nb_vus_par_autre += 1 i = i + 1 cibles_observees = nouvelles_cibles nb_ennemis = 0 centre = Point() for c in cibles_observees: #print str(c.distanceTo(Point())) if nb_ennemis < 5 and c.getType( ) == 'RocketLauncher' and not c.getVuParAutre(): mult = 130 - c.distanceTo(Point()) centre.setCoord(centre.getX() + c.getX() * mult, centre.getY() + c.getY() * mult) nb_ennemis += 1 elif c.getType() == 'RocketLauncher': mult = 200 - c.distanceTo(Point()) centre.setCoord(centre.getX() + c.getX() * mult, centre.getY() + c.getY() * mult) nb_ennemis += 1 if synchro.pret(): monEtat() elif zero_cible and cibles_observees != []: monEtat() synchro.decrementer() #self.setUserMessage(str(len(cibles_observees))) if nb_ennemis > 0: centre.setCoord(centre.getX() / nb_ennemis, centre.getY() / nb_ennemis) repuls = 180 self.setHeading(repuls + self.towards(centre.getX(), centre.getY())) # Evitement des obstacles divers evite = Point() evite_rockets = Point() nb_rockets = 0 nb_obs = 0 nb_murs = 0 nouvelles_rockets = [] #print '' for p in percepts: if p.getPerceptType() == 'Rocket': pos = Point() pos.setCoord(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) c = Rocket(pos) nouvelles_rockets.append(c) ecart_min = ecartMin(p) d = self.distanceTo(p) if d < ecart_min: if d > 0: mult = (ecart_min - d) / ecart_min evite.setCoord(evite.getX() - mult * p.getX() / d, evite.getY() - mult * p.getY() / d) nb_obs = nb_obs + 1 if p.getPerceptType() == 'Obstacle': nb_murs = nb_murs + 1 # Evitement des rockets en prenant en compte leur deplacement rockets = [] for r in liste_rockets: lg = len(nouvelles_rockets) i = 0 trouve = 0 if r.getDejaVu(): nouv_pos = r.getNextCoord() while not trouve and i < lg: r2 = nouvelles_rockets[i] if r2.getCoord().distanceTo(nouv_pos) < 0.5: r.setCoord(r2.getX(), r2.getY()) rockets.append(r) trouve = 1 nouvelles_rockets.remove(r2) else: i += 1 else: while not trouve and i < lg: r2 = nouvelles_rockets[i] dst = r2.getCoord().distanceTo(r.getCoord()) if abs(dst - 4) < 0.5: r.setCoord(r2.getX(), r2.getY()) rockets.append(r) trouve = 1 nouvelles_rockets.remove(r2) else: i += 1 for r in rockets: s = (r.getNextCoord().getY() - r.getY()) / 4 c = (r.getNextCoord().getX() - r.getX()) / 4 t = s / c x = r.getX() - coordonnees.getX() y = r.getY() - coordonnees.getY() centre_x = (x + t * y) / (c + s * t) centre_y = -y / c + t * centre_x centre = Point() centre.setCoord(x, y) distance = centre.distanceTo(Point()) #Si je suis sur la trajectoire if distance < 80 and centre_x < 0 and abs(centre_y < 16): nb_rockets += 1 mult = (80 - distance) / 80 if centre_y >= 0: evite_rockets.setCoord(evite_rockets.getX() + mult * y, evite_rockets.getY() - mult * x) else: evite_rockets.setCoord(evite_rockets.getX() - mult * y, evite_rockets.getY() + mult * x) #print str(int(centre_x*1000) / 1000), str(int(centre_y * 1000) / 1000) liste_rockets = rockets for r in nouvelles_rockets: liste_rockets.append(r) #print '' #for r in liste_rockets: # print r.getX(), r.getY() eviteObstacles(liste_obs) if nb_rockets > 0: direct = self.getHeading() * Math.PI / 180 but_virtuel = Point() but_virtuel.setCoord(2 * Math.cos(direct), 2 * Math.sin(direct)) self.setHeading( self.towards(but_virtuel.getX() + evite_rockets.getX(), but_virtuel.getY() + evite_rockets.getY())) if nb_obs > 0: direct = self.getHeading() * Math.PI / 180 but_virtuel = Point() but_virtuel.setCoord(1 * Math.cos(direct), 1 * Math.sin(direct)) self.setHeading( self.towards(but_virtuel.getX() + evite.getX(), but_virtuel.getY() + evite.getY())) # Reception des messages while not self.isMessageBoxEmpty(): message = self.readMessage() # Message de position de la base if message.getAct() == 'POS': coordonnees.setCoord(-message.getFromX(), -message.getFromY()) elif message.getAct() == 'INFO-QG': x_absolu = message.getFromX() + float( message.getArgN(1)) + coordonnees.getX() y_absolu = message.getFromY() + float( message.getArgN(2)) + coordonnees.getY() b = Point(x_absolu, y_absolu) if (not baseEnnemieConnue(b)): base_ennemie.append(b) elif message.getAct() == 'FIN-NUM': if int(message.getArg1()) < moi: moi = moi - 1 elif message.getAct() == 'NUM': liste_autres.append(message.getSender()) elif message.getAct() == 'FIN-QG': x = message.getFromX() + float( message.getArg1()) + coordonnees.getX() y = message.getFromY() + float( message.getArg2()) + coordonnees.getY() b = Point(x, y) baseEnnemieSuppr(b) elif message.getAct() == 'LAUNCHER_VU': launcher_vu = 1 elif message.getAct() == 'ROCKET-REQ': if adr_objectif == None and not cible_launcher: self.send(message.getSender(), 'ROCKET-OFFRE') adr_objectif = message.getSender() dest = Point() dest.setCoord( message.getFromX() + coordonnees.getX() + float(message.getArg1()), message.getFromY() + coordonnees.getY() + float(message.getArg2())) objectif.setCoord(dest.getX(), dest.getY()) elif message.getAct( ) == 'ROCKET-OK' and adr_objectif == message.getSender(): dest = Point() dest.setCoord( message.getFromX() + coordonnees.getX() + float(message.getArg1()), message.getFromY() + coordonnees.getY() + float(message.getArg2())) objectif.setCoord(dest.getX(), dest.getY()) elif message.getAct() == 'ROCKET-NON': if adr_objectif == message.getSender(): adr_objectif = None elif estMonSuperieur( message.getSender()) and (message.getAct() == 'HELP0' or message.getAct() == 'HELP1'): x = message.getFromX() + float(message.getArg1()) y = message.getFromY() + float(message.getArg2()) pos = Point() pos.setCoord(x, y) for c in cibles_observees: if pos.distanceTo(c.getCoord()) <= 10: c.setVuParAutre(6) # 6 tours avant fin ttl self.move()
def vector_y (percept, dist, scale, theta, p): return Math.sin (deg2pi (180 + self.towards (percept.getX(), percept.getY()))) * theta / Math.pow ((dist / scale), p)
def doIt(): mem.t += 1 if not self.isMoving(): self.setHeading(mem.go()) percepts = self.getPercepts() # Vecteurs d'evitement aurax = auray = 0 # nombre d'obstacles, explorers amis, rocketlauncher ennemis vus ob = expl = rl = 0 # objectif choisi (seulement nouriture) pmin = 0 for p in percepts: d = self.distanceTo(p)+.0001 t = p.getPerceptType() if d < 40: aurax += p.getX()/d *(40-d)/150 auray += p.getY()/d *(40-d)/150 if p.getTeam() != self.getTeam(): if t=='Home' or t=='Explorer': mem.send(self, p) elif t=='RocketLauncher': rl += 1 mem.send(self, p) if d < 150: aurax += p.getX()/d *(150-d)/70 auray += p.getY()/d *(150-d)/70 elif t=='Food' and (pmin==0 or d <= self.distanceTo(pmin)): pmin=p elif t=='Rocket': if d < 150: aurax += p.getX()/d *(150-d)/150 auray += p.getY()/d *(150-d)/150 elif t=='Obstacle': ob += 1 if d < 150: aurax += p.getX()/d *(150-d)/150 auray += p.getY()/d *(150-d)/150 elif t=='Explorer': if d < 150: aurax += p.getX()/d *(150-d)/150 auray += p.getY()/d *(150-d)/150 expl += 1 # Gestion de la nouriture (non teste) if pmin != 0: if self.distanceTo(pmin)<2: #if close enough self.eat(pmin) #eat it return else: #else go towards it self.setHeading(self.towards(pmin.getX(),pmin.getY())) self.move() return # Calcul du vecteur de deplacement en fonction des vecteurs de force # et du cap a maintenir aurax = Math.cos(mem.but*Math.PI/180) - aurax auray = Math.sin(mem.but*Math.PI/180) - auray t = self.towards(aurax,auray) # Changement de l'objectif if ob > 3 or expl > 0 or rl > 2: mem.but = t # Deplacement effectif self.setHeading(t) self.move()
def createWorld(self, world): bd = BodyDef() ground = world.createBody(bd) shape = EdgeShape() shape.set(Vector2(-20, 0), Vector2(20, 0)) ground.createFixture(shape, 0) shape.dispose() bd = BodyDef() ground = world.createBody(bd) shape = EdgeShape() shape.setRadius(0) shape.set(Vector2(-8, 1), Vector2(-6, 1)) ground.createFixture(shape, 0) shape.set(Vector2(-6, 1), Vector2(-4, 1)) ground.createFixture(shape, 0) shape.set(Vector2(-4, 1), Vector2(-2, 1)) ground.createFixture(shape, 0) shape.dispose() bd = BodyDef() ground = world.createBody(bd) shape = PolygonShape() shape.setAsBox(1, 1, Vector2(4, 3), 0) ground.createFixture(shape, 0) shape.setAsBox(1, 1, Vector2(6, 3), 0) ground.createFixture(shape, 0) shape.setAsBox(1, 1, Vector2(8, 3), 0) ground.createFixture(shape, 0) shape.dispose() bd = BodyDef() ground = world.createBody(bd) shape = EdgeShape() d = 2 * 2 * 0.005 shape.setRadius(0) shape.set(Vector2(-1 + d, 3), Vector2(1 - d, 3)) ground.createFixture(shape, 0) shape.set(Vector2(1, 3 + d), Vector2(1, 5 - d)) ground.createFixture(shape, 0) shape.set(Vector2(1 - d, 5), Vector2(-1 + d, 5)) ground.createFixture(shape, 0) shape.set(Vector2(-1, 5 - d), Vector2(-1, 3 + d)) ground.createFixture(shape, 0) shape.dispose() bd = BodyDef() bd.position.set(-3, 5) bd.type = BodyType.DynamicBody bd.fixedRotation = True bd.allowSleep = False body = world.createBody(bd) shape = PolygonShape() shape.setAsBox(0.5, 0.5) fd = FixtureDef() fd.shape = shape fd.density = 20.0 body.createFixture(fd) shape.dispose() bd = BodyDef() bd.position.set(-5, 5) bd.type = BodyType.DynamicBody bd.fixedRotation = True bd.allowSleep = False body = world.createBody(bd) angle = 0.0 delta = Math.PI / 3 vertices = [] for i in range(6): vertices.append( Vector2(0.5 * Math.cos(angle), 0.5 * Math.sin(angle))) angle += delta shape = PolygonShape() shape.set(vertices) fd = FixtureDef() fd.shape = shape fd.density = 20.0 body.createFixture(fd) shape.dispose() bd = BodyDef() bd.position.set(3, 5) bd.type = BodyType.DynamicBody bd.fixedRotation = True bd.allowSleep = False body = world.createBody(bd) shape = CircleShape() shape.setRadius(0.5) fd = FixtureDef() fd.shape = shape fd.density = 20.0 body.createFixture(fd) shape.dispose()
def doIt(): mem.t += 1 if mem.iMove: if not self.isMoving(): self.setHeading(mem.go()) else: # Calcul de la nouvelle position mem.origin.x += Math.cos(self.getHeading() * Math.PI / 180) * 2 mem.origin.y += Math.sin(self.getHeading() * Math.PI / 180) * 2 #if mem.t % 15 == 0: #print len(mem.buts),mem.origin.str(),'->',mem.current.str() mem.iMove = 0 # Latence de tir if mem.wait >= 0: mem.wait = mem.wait - 1 # Lecture des messages if not self.isMessageBoxEmpty(): while not self.isMessageBoxEmpty(): mem.message(self.readMessage()) if mem.fuite == 0: mem.newBut() percepts = self.getPercepts() c = 1 # Coequipiers - Ennemis (rockerLauncher) pmin = primin = 0 # Objectif et sa valeur aurax = auray = 0 # Vecteurs d'evitement des mechants auraxt = aurayt = 0 # Vecteurs d'evitement des gentils (team) for p in percepts: pri = 0 # Interet du percept courant d = self.distanceTo(p) + 0.0001 t = p.getPerceptType() if p.getTeam() != self.getTeam(): if t == 'Home': mem.send(p) pri = 1 if d < 80: aurax += p.getX() / d auray += p.getY() / d elif t == 'RocketLauncher': mem.send(p) pri = 4 c -= 1 if d < 70 or mem.fuite > 0: aurax += p.getX() / d auray += p.getY() / d elif t == 'Explorer': mem.send(p) pri = 3 if d < 70: aurax += p.getX() / d auray += p.getY() / d elif t == 'Food': pri = 2 # Mise a jour de l'objectif en fonction de la priorite et de son energie if pri > 0 and (pri > primin or (pri == primin and p.getEnergy() < pmin.getEnergy())): pmin = p primin = pri else: if d < 70: auraxt += p.getX() / d * (70 - d) / 120 aurayt += p.getY() / d * (70 - d) / 120 if t == 'RocketLauncher': c += 1 # Si pas d'objectif if pmin == 0: mem.pbak = mem.priminbak = 0 # Si but atteind if mem.current.x != 'abs' and mem.current.dist(mem.origin) < 70: self.broadcast(groupName, "launcher", "Next", str(mem.current.x - mem.origin.x), str(mem.current.y - mem.origin.y)) print "but ok ", mem.current.str() elif primin == 2: #food (non teste) mem.priminbak = primin d = self.distanceTo(pmin) + 0.0001 if d < 2: #if close enough self.eat(pmin) #eat it return else: #else go towards it self.setHeading(self.towards(pmin.getX(), pmin.getY())) self.move() return else: # Tir sur auelaue chose x = pmin.getX() y = pmin.getY() # Inference de tir (ou prediction a la louche) if primin == mem.priminbak: xx = x - mem.pbak.getX() yy = y - mem.pbak.getY() if xx * xx + yy * yy <= 50: d = self.distanceTo(pmin) / 25 + 0.0001 if primin == 4: d /= 4 x += xx * d * d y += yy * d * d mem.pbak = pmin mem.priminbak = primin if mem.wait <= 0 and mem.fuite == 0: # self.broadcast(groupName,"launcher","Help",str(x),str(y)) self.launchRocket(self.towards(x, y)) mem.wait = 3 return # Construction des roquettes si nombre faible if self.getRocketNumber( ) < 50 and rnd.nextDouble() * 50 > self.getRocketNumber(): self.buildRocket() return # Cas de fuite if self.getRocketNumber() < 10: # plus de balles mem.fuite = mem.t + 30 elif c < 0: # plein de mechant mem.fuite = mem.t + 20 # elif self.getShot(): # touche # mem.fuite = mem.t + 10 elif mem.fuite > 0 and mem.t > mem.fuite: # fuite finie mem.fuite = 0 if self.getEnergyLevel() > borneVie: mem.newBut() else: mem.nextBut() # Calcul du vecteur de but b = mem.toBut(mem.current) x = Math.cos(b * Math.PI / 180) y = Math.sin(b * Math.PI / 180) # les laches vont dans l'autre sens if mem.fuite > 0: x = -x * 2 y = -y * 2 # si du team est detecte if auraxt != 0 or aurayt != 0: if mem.current.x == 'abs': # si pas de but, changement de cap mem.current.y = self.towards(x - auraxt, y - aurayt) else: # si la priorite est forte, on se sert les coudes if mem.current.pri > 1: x *= 3 y *= 3 # calcul de la nouvelle direction b = self.towards(x - auraxt, y - aurayt) x = Math.cos(b * Math.PI / 180) y = Math.sin(b * Math.PI / 180) #print 'b(',x,y,') bb(',xx,yy,') aura(',aurax,auray,') t(',auraxt,aurayt,')' # les laches ont plus peur if mem.fuite > 0: x = x / 3 y = y / 3 # Deplacement effectif self.setHeading(self.towards(x - aurax, y - auray)) self.move() mem.iMove = 1
def getDeplY(): alpha = self.getHeading() * Math.PI / 180 return self.getCoveredDistance() * Math.sin(alpha)
def getParticle(pid, mom, theta, phi): px = mom*Math.sin(theta)*Math.cos(phi) py = mom*Math.sin(theta)*Math.sin(phi) pz = mom*Math.cos(theta) particle = Particle(pid,px,py,pz,0.0,0.0,0.0) return particle
def doIt(): global offre global tour tour = tour + 1 attendre = 0 coordonnees.setX(coordonnees.getX() + getDeplX()) coordonnees.setY(coordonnees.getY() + getDeplY()) # Time to live decremente aide.decrementer() if aide.besoin() and coordonnees.distanceTo(aide.getCoord()) <= 90 : aide.finAssistance() #Rechargement des roquettes? if not attenteRoquettes.pret(): attenteRoquettes.decrementer() lireMessages() if synchro.pret(): monEtat() synchro.decrementer() base_cible = Point() if base_ennemie != [] : for b in base_ennemie: if aide.setAssistance(coordonnees, self.getName(), b.getX(), b.getY(), 10000, AIDE_BASE_ENNEMIE,3, tour): base_cible = b # Deplacement normal if aide.besoin(): direct = self.towards(aide.getVisee().getX() - coordonnees.getX(), aide.getVisee().getY() -coordonnees.getY()) if coordonnees.distanceTo(aide.getCoord()) > 150 or (aide.besoin() > AIDE_LAUNCHER or aide.besoin() == AIDE_BASE_ENNEMIE): self.setHeading(direct) else: self.setHeading(180 + direct) # BaryCentre des unites ennemies proches centre = Point() percepts = self.getPercepts() nb_unites = 0 ennemi_perdu = ennemi_courant.existe() qg_ennemi_visible = not (base_cible.estConnu() and base_cible.distanceTo(coordonnees) <= 100) for p in percepts: team = p.getTeam() type_percept = p.getPerceptType() if ((type_percept =="Home") or (type_percept =="RocketLauncher") or (type_percept == "Explorer")) and team!=self.getTeam(): if p.getPerceptType() == "Home": base_abs = Point(p.getX() +coordonnees.getX(), p.getY() +coordonnees.getY()) if not baseEnnemieConnue(base_abs): base_ennemie.append(base_abs) self.broadcast(groupName, "info", "INFO-QG", str(p.getX()), str(p.getY())) qg_ennemi_visible = qg_ennemi_visible or base_abs.distanceTo(base_cible) <= 10 coord = Point(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) energie = p.getEnergy() if not ennemi_courant.existe() : ennemi_courant.setCible(type_percept, coord, energie, tour) #self.broadcast(groupName, "launcher", "FIN") args = [str(p.getX()), str(p.getY()), str(p.getEnergy())] if type_percept == "RocketLauncher": self.broadcast(groupName, "launcher", "HELP2", args) elif ennemi_courant.egal(type_percept, coord) : ennemi_courant.setCible(type_percept, coord, energie, tour) ennemi_perdu = 0 elif (ennemi_courant.getEnergy() > p.getEnergy()) and prioriteType(ennemi_courant.getType()) <= prioriteType(p.getPerceptType()): ennemi_courant.setCible(type_percept, coord, energie, tour) ennemi_perdu = 0 if base_cible.estConnu() and not qg_ennemi_visible: baseEnnemieSuppr(base_cible) self.broadcast(groupName, "mobile", "FIN-QG", str(base_cible.getX() - coordonnees.getX()), str(base_cible.getY() - coordonnees.getY())) # if ennemi_courant.existe(): # self.setUserMessage("TIR") # else: # self.setUserMessage(None) if ennemi_perdu: self.broadcast(groupName, "launcher", "FIN") self.broadcast(groupName, "launcher", "ETAT") self.broadcast(groupName, "explorer", "ETAT") self.setHeading(self.towards(ennemi_courant.getX() - coordonnees.getX(), ennemi_courant.getY() - coordonnees.getY())) ennemi_courant.delCible() elif (ennemi_courant.existe()): coord = ennemi_courant.viser(coordonnees) if tirer(coord): return # Manoeuvres d"evitement gentils = Point() mechants = Point() nb_mechants = 0 nb_gentils = 0 evite = Point() amis = Vector() tenaille = Point() # self.getName() liste_amis = [] liste_rockets = [] if aide.besoin(): dist_aide = aide.getVisee().distanceTo(coordonnees) else: dist_aide = 1000 for p in percepts: dist = self.distanceTo(p) if p.getPerceptType() == "RocketLauncher" and p.getTeam() == self.getTeam(): liste_amis.append(p) r = Mobile(coordonnees.getX() + p.getX(), coordonnees.getY() + p.getY()) amis.add(r) if aide.besoin() == AIDE_LAUNCHER : p_ami = Point(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) dist_ami = p_ami.distanceTo(aide.getVisee()) if dist_aide > 200 and dist_ami > dist_aide+20: attendre = 1 if p.getPerceptType() == "Rocket": liste_rockets.append(p) if p.getPerceptType() == "Home" and p.getTeam() == self.getTeam(): liste_amis.append(p) ecart_min = ecartMin(p) if dist > 0 and dist < ecart_min: mult = (ecart_min - dist)/ecart_min if p.getPerceptType() == "Obstacle" or (p.getTeam() == self.getTeam()): gentils.setCoord(gentils.getX() - p.getX()/dist *mult, gentils.getY() - p.getY()/dist*mult) nb_gentils +=1 else: nb_mechants += 1 mechants.setCoord(mechants.getX() - p.getX()/dist*mult, mechants.getY() - p.getY()/dist*mult) mon_groupe.amisVus(amis) if attendre: self.setHeading(self.getHeading() + 180) rocket_dangereuse = eviteRockets(liste_rockets) tirer_loin = aide.besoin() and aide.getVisee().distanceTo(coordonnees) < 200 # Si on voit une rocket sans voir d"ennemi if rocket_dangereuse != None and not tirer_loin: d = coordonnees.distanceTo(rocket_dangereuse) # Estimation de la pos de l"ennemi : a 150 de distance x = (rocket_dangereuse.getX() - coordonnees.getX()) / d * 150 y = (rocket_dangereuse.getY() - coordonnees.getY())/ d * 150 args = [str(x), str(y), str(10000)] self.broadcast(groupName, "launcher", "ROCKET", args) #Demande a un explorateur de venir voir s"il y a quelqu"un if offre == None: self.broadcast(groupName, "explorer", "ROCKET-REQ",str(x),str(y)) else: self.send(offre, "ROCKET-OK", str(x), str(y)) if rocket_dangereuse != None and attenteRoquettes.pret(): if tirer(rocket_dangereuse): return if tirer_loin: pos = Point() pos.setCoord(aide.getVisee().getX(), aide.getVisee().getY()) if tirer(pos): return # Besoin de construire des rockets? seuil_rocket = 50 if tirer_loin: seuil_rocket = 10 if (self.getRocketNumber() < seuil_rocket): # self.setUserMessage("Reconstruction Rockets") self.buildRocket() return #else: self.setUserMessage(self.getTeam()) if mon_groupe.nbVus() != 0 : centre = mon_groupe.barycentre() if not aide.besoin(): if coordonnees.distanceTo(centre) >60: direct = self.getHeading()*Math.PI/ 180 but_virtuel = Point() but_virtuel.setCoord(35*Math.cos(direct),35*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + centre.getX()-coordonnees.getX(),but_virtuel.getY() + centre.getY() - coordonnees.getY() )) formation = mon_groupe.vecteurMoyen() direct = self.getHeading()*Math.PI/ 180 but_virtuel = Point() but_virtuel.setCoord(1*Math.cos(direct),1*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + formation.getX() ,but_virtuel.getY() + formation.getY())) eviteAmis(liste_amis) if nb_gentils > 0: direct = self.getHeading()*Math.PI/ 180 but_virtuel = Point() if aide.besoin() and aide.getVisee().distanceTo(coordonnees) < 200: but_virtuel.setCoord(Math.cos(direct),Math.sin(direct)) else: but_virtuel.setCoord(5*Math.cos(direct),5*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + gentils.getX(),but_virtuel.getY() + gentils.getY() )) if nb_mechants > 0: direct = self.getHeading()*Math.PI /180 but_virtuel = Point() but_virtuel.setCoord(2*Math.cos(direct),2*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + mechants.getX(),but_virtuel.getY() + mechants.getY() )) self.move()
def vector_y(percept, dist, scale, theta, p): return Math.sin(deg2pi(180 + self.towards(percept.getX(), percept.getY())) ) * theta / Math.pow((dist / scale), p)
def eviteRockets(percepts): global coordonnees global liste_rockets evite_rockets = Point() nb_rockets = 0 nouvelles_rockets = [] for p in percepts: pos = Point() pos.setCoord(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) c = Rocket(pos) nouvelles_rockets.append(c) # Evitement des rockets en prenant en compte leur deplacement rockets = [] for r in liste_rockets: lg = len(nouvelles_rockets) i = 0 trouve = 0 if r.getDejaVu(): nouv_pos = r.getNextCoord() while not trouve and i < lg: r2 = nouvelles_rockets[i] if r2.getCoord().distanceTo(nouv_pos) < 0.0001: r.setCoord(r2.getX(), r2.getY()) rockets.append(r) trouve = 1 nouvelles_rockets.remove(r2) else: i += 1 else: while not trouve and i < lg: r2 = nouvelles_rockets[i] dst = r2.getCoord().distanceTo(r.getCoord()) if abs(dst - 10) < 0.0001: #print "Distance : ", str(abs(dst - 10)) r.setCoord(r2.getX(), r2.getY()) rockets.append(r) trouve = 1 nouvelles_rockets.remove(r2) else: i += 1 plus_proche = 100 roc = None cy = 0 for r in rockets: s = (r.getNextCoord().getY() - r.getY())/10 c = (r.getNextCoord().getX() - r.getX())/10 if c != 0: c = 0.0000001 t = s/c x = r.getX() - coordonnees.getX() y = r.getY() - coordonnees.getY() centre_x = -( x + t* y) / (c + s * t) centre_y = -y/c - t * centre_x centre = Point() centre.setCoord(x, y) distance = centre.distanceTo(Point()) #Si je suis sur la trajectoire if (centre_x > 0) and abs(centre_y) < 14: nb_rockets += 1 mult = (100 - distance)/100 if centre_y >= 0: evite_rockets.setCoord(evite_rockets.getX() + mult*y, evite_rockets.getY() - mult*x) else: evite_rockets.setCoord(evite_rockets.getX() - mult*y, evite_rockets.getY() + mult*x) if (not r.getShootee()) and (plus_proche > centre_x): roc = r plus_proche = centre_x liste_rockets = rockets for r in nouvelles_rockets: liste_rockets.append(r) if nb_rockets > 0: direct = self.getHeading()*Math.PI/ 180 but_virtuel = Point() but_virtuel.setCoord(2*Math.cos(direct),2*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + evite_rockets.getX(),but_virtuel.getY() + evite_rockets.getY())) if attenteRoquettes.pret() and roc !=None: # dist = 14 # impact = 0 dx = (roc.getNextCoord().getX() - roc.getX())/10 dy = (roc.getNextCoord().getY() - roc.getY())/10 vise = Point() #print "TIR:" a = 0 b = 100 while b - a > 1: m = int ((a + b) / 2) vise.setCoord(roc.getX() + m*dx,roc.getY() + m*dy) if coordonnees.distanceTo(vise) > m + 14: a = m else: b = m roc.setShootee(1) vise.setCoord(roc.getX() + m*dx,roc.getY() + m*dy) return vise else: return None
def tick(self): if self.t == 0: if not self.player.getScoreboardTags().contains('arrow_shield'): self.player.addScoreboardTag('arrow_shield') PersistentDataAPI.setInt(PersistentDataAPI.getData(self.player), 'arrow_shield', 3) else: arrows = PersistentDataAPI.getInt(PersistentDataAPI.getData(self.player), 'arrow_shield') PersistentDataAPI.setInt(PersistentDataAPI.getData(self.player), 'arrow_shield', 3) if arrows <= 0: self.player.removeScoreboardTag('arrow_shield') return #TODO self.sound(Sound.ITEM_ARMOR_EQUIP_NETHERITE if self.clone else Sound.ENTITY_EVOKER_PREPARE_SUMMON, .5, .9) self.sound(Sound.ENTITY_ARROW_SHOOT, 1, .8) self.sound(Sound.ENTITY_PLAYER_ATTACK_CRIT, 1, 1) self.stands = ( self.player.getWorld().spawn(self.player.getLocation().clone().add(1.3, .2 if self.clone else .7, .75), ArmorStand), self.player.getWorld().spawn(self.player.getLocation().clone().add(-1.3, .2 if self.clone else .7, .75), ArmorStand), self.player.getWorld().spawn(self.player.getLocation().clone().add(0, .2 if self.clone else .7, -1.5), ArmorStand) ) for stand in self.stands: stand.setVisible(False) stand.setSmall(True) stand.setInvulnerable(True) stand.setMarker(True) stand.addScoreboardTag('shield_arrow') PersistentDataAPI.setString(PersistentDataAPI.getData(self.player), 'owner', self.player.getName()) stand.getEquipment().setHelmet(ItemStack(Material.SHEARS if self.clone else Material.ARROW)) stand.setHeadPose(EulerAngle(0, 0, Math.PI * (-.5 if self.clone else -.75))) elif self.t < 600: self.stands[0].teleport(self.player.getLocation().clone().add(Math.sin((10 * self.t + 60) * -DEG2RAD) * 1.5, .2 if self.clone else .7, Math.cos((10 * self.t + 60) * DEG2RAD) * 1.5)) self.stands[1].teleport(self.player.getLocation().clone().add(Math.sin((10 * self.t - 60) * -DEG2RAD) * 1.5, .2 if self.clone else .7, Math.cos((10 * self.t - 60) * DEG2RAD) * 1.5)) self.stands[2].teleport(self.player.getLocation().clone().add(Math.sin((10 * self.t + 180) * -DEG2RAD) * 1.5, .2 if self.clone else .7, Math.cos((10 * self.t + 180) * DEG2RAD) * 1.5)) self.stands[0].setRotation(10 * self.t + 60, 0) self.stands[1].setRotation(10 * self.t - 60, 0) self.stands[2].setRotation(10 * self.t + 180, 0) for stand in self.stands: self.particle(stand.getLocation().clone().add(0, .5 if self.clone else .2, 0), Particle.VILLAGER_HAPPY if self.clone else Particle.CRIT, 1, 0, 0, 0, 0) self.particle(stand.getLocation().clone().add(0, .5, 0) if self.clone else stand.getLocation(), Particle.FIREWORKS_SPARK if self.clone else Particle.CRIT_MAGIC, 1, 0, 0, 0, 0) else: self.sound(Sound.ENTITY_WITHER_BREAK_BLOCK, .1, 1.9) self.sound(Sound.ITEM_ARMOR_EQUIP_NETHERITE, 1, 1) self.deactivate() if self.cooldown <= 0: for e in self.nearbyMobs(3, 3, 3): self.activate(e) if self.remaining > 1: self.cooldown = 10 self.remaining -= 1 else: self.castSpell('ARCHER', 5) self.deactivate() self.cancel() self.cooldown -= 1
def setTrajectoire(this): if this._explore: if not self.isMoving() or self.getHeading() == 0: self.randomHeading() return decalx = decaly = 0 for p in self.getPercepts(): type = p.getPerceptType() dist = p.getDistance() if dist < redirect_distance and p.getTeam() == self.getTeam() and (type == 'Home' or type == 'RocketLauncher' or type == 'Explorer'): decalx += p.getX() / dist * (70-dist) / 120 decaly += p.getY() / dist * (70-dist) / 120 #~ d('distance: '+str(dist)) #~ d('direction originelle: '+str(self.towards(this._destX, this._destY))) #~ d('direction modifiee: '+str(self.towards(Math.cos(self.towards(this._destX, this._destY))-decalx, Math.sin(self.towards(this._destX, this._destY))-decaly))) self.setHeading(self.towards(Math.cos(self.towards(this._destX, this._destY)*Math.PI/180)-decalx, Math.sin(self.towards(this._destX, this._destY)*Math.PI/180)-decaly))
def doIt(): mem.t += 1 if mem.iMove: if not self.isMoving(): self.setHeading(mem.go()) else: # Calcul de la nouvelle position mem.origin.x += Math.cos(self.getHeading()*Math.PI/180)*2 mem.origin.y += Math.sin(self.getHeading()*Math.PI/180)*2 #if mem.t % 15 == 0: #print len(mem.buts),mem.origin.str(),'->',mem.current.str() mem.iMove = 0 # Latence de tir if mem.wait>=0: mem.wait = mem.wait - 1 # Lecture des messages if not self.isMessageBoxEmpty(): while not self.isMessageBoxEmpty(): mem.message(self.readMessage()) if mem.fuite == 0: mem.newBut() percepts = self.getPercepts() c = 1 # Coequipiers - Ennemis (rockerLauncher) pmin = primin = 0 # Objectif et sa valeur aurax = auray = 0 # Vecteurs d'evitement des mechants auraxt = aurayt = 0 # Vecteurs d'evitement des gentils (team) for p in percepts: pri = 0 # Interet du percept courant d = self.distanceTo(p)+0.0001 t = p.getPerceptType() if p.getTeam()!=self.getTeam(): if t=='Home': mem.send(p) pri=1 if d < 80: aurax += p.getX()/d auray += p.getY()/d elif t=='RocketLauncher': mem.send(p) pri=4 c -= 1 if d < 70 or mem.fuite > 0: aurax += p.getX()/d auray += p.getY()/d elif t=='Explorer': mem.send(p) pri=3 if d < 70: aurax += p.getX()/d auray += p.getY()/d elif t=='Food': pri=2 # Mise a jour de l'objectif en fonction de la priorite et de son energie if pri>0 and (pri>primin or (pri==primin and p.getEnergy() < pmin.getEnergy())): pmin=p primin=pri else: if d < 70: auraxt += p.getX()/d *(70-d)/120 aurayt += p.getY()/d *(70-d)/120 if t=='RocketLauncher': c += 1 # Si pas d'objectif if pmin == 0: mem.pbak = mem.priminbak = 0 # Si but atteind if mem.current.x != 'abs' and mem.current.dist(mem.origin) < 70: self.broadcast(groupName,"launcher","Next",str(mem.current.x-mem.origin.x),str(mem.current.y-mem.origin.y)) print "but ok ", mem.current.str() elif primin==2: #food (non teste) mem.priminbak = primin d = self.distanceTo(pmin)+0.0001 if d<2: #if close enough self.eat(pmin) #eat it return else: #else go towards it self.setHeading(self.towards(pmin.getX(),pmin.getY())) self.move() return else: # Tir sur auelaue chose x = pmin.getX() y = pmin.getY() # Inference de tir (ou prediction a la louche) if primin == mem.priminbak: xx = x - mem.pbak.getX() yy = y - mem.pbak.getY() if xx*xx+yy*yy <= 50: d = self.distanceTo(pmin)/25+0.0001 if primin == 4: d /= 4 x += xx*d*d y += yy*d*d mem.pbak = pmin mem.priminbak = primin if mem.wait<=0 and mem.fuite==0: # self.broadcast(groupName,"launcher","Help",str(x),str(y)) self.launchRocket(self.towards(x,y)) mem.wait = 3 return # Construction des roquettes si nombre faible if self.getRocketNumber() < 50 and rnd.nextDouble()*50>self.getRocketNumber(): self.buildRocket() return # Cas de fuite if self.getRocketNumber() < 10: # plus de balles mem.fuite = mem.t + 30 elif c < 0: # plein de mechant mem.fuite = mem.t + 20 # elif self.getShot(): # touche # mem.fuite = mem.t + 10 elif mem.fuite > 0 and mem.t > mem.fuite: # fuite finie mem.fuite = 0 if self.getEnergyLevel() > borneVie: mem.newBut() else: mem.nextBut() # Calcul du vecteur de but b = mem.toBut(mem.current) x = Math.cos(b*Math.PI/180) y = Math.sin(b*Math.PI/180) # les laches vont dans l'autre sens if mem.fuite > 0: x = -x*2 y = -y*2 # si du team est detecte if auraxt != 0 or aurayt != 0: if mem.current.x == 'abs': # si pas de but, changement de cap mem.current.y = self.towards(x-auraxt,y-aurayt) else: # si la priorite est forte, on se sert les coudes if mem.current.pri > 1: x *= 3 y *= 3 # calcul de la nouvelle direction b = self.towards(x-auraxt,y-aurayt) x = Math.cos(b*Math.PI/180) y = Math.sin(b*Math.PI/180) #print 'b(',x,y,') bb(',xx,yy,') aura(',aurax,auray,') t(',auraxt,aurayt,')' # les laches ont plus peur if mem.fuite > 0: x = x/3 y = y/3 # Deplacement effectif self.setHeading(self.towards(x-aurax,y-auray)) self.move() mem.iMove = 1
def doIt(): global moi global cibles_observees global launcher_vu global liste_rockets global adr_objectif miseAJourMouvement() # Phase de detection percepts = self.getPercepts() liste_obs = [] # Detection des ennemis zero_cible = (cibles_observees == []) nouvelles_cibles = [] cible_launcher = 0 for p in percepts: # On trouve le QG ennemi if p.getPerceptType() == 'Home': liste_obs.append(p) if p.getTeam() != self.getTeam(): b = Point(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) if not baseEnnemieConnue(b): base_ennemie.append(b) self.broadcast(groupName, 'info', 'INFO-QG', str(p.getX()), str(p.getY())) # On entre dans la zone de detection d'un rocket-launcher elif p.getPerceptType() == 'RocketLauncher' and p.getTeam() != self.getTeam(): if not launcher_vu: self.broadcast(groupName, 'explorer', 'LAUNCHER_VU') launcher_vu = 1 cible_launcher = 1 c = CibleObs( p) nouvelles_cibles.append(c) elif p.getPerceptType() == 'Explorer' and p.getTeam() != self.getTeam() : c = CibleObs( p) nouvelles_cibles.append(c) liste_obs.append(p) elif p.getPerceptType() == 'RocketLauncher' and p.getTeam() == self.getTeam(): liste_obs.append(p) if adr_objectif != None: if coordonnees.distanceTo(objectif) < 110:# or cible_launcher: objectif.setConnu(0) self.send(adr_objectif, 'ROCKET-FIN') adr_objectif = None else: self.setHeading( self.towards(objectif.getX() - coordonnees.getX(), objectif.getY() - coordonnees.getY())) # Mise a jour des cibles vues par plusieurs explorateurs nb_vus_par_autre = 0 longueur = len(cibles_observees) for c in nouvelles_cibles: pos = Point() pos.setCoord(c.getX(), c.getY()) trouve = 0 i = 0 while not trouve and i < longueur: c_anc = cibles_observees[i] if c_anc.getVuParAutre() and pos.distanceTo(c_anc.getCoord()) < 10: trouve = 1 c.setVuParAutre(c_anc.getVuParAutre() - 1) nb_vus_par_autre += 1 i = i+1 cibles_observees = nouvelles_cibles nb_ennemis = 0 centre = Point() for c in cibles_observees : #print str(c.distanceTo(Point())) if nb_ennemis < 5 and c.getType() == 'RocketLauncher' and not c.getVuParAutre(): mult = 130 - c.distanceTo(Point()) centre.setCoord(centre.getX() + c.getX()*mult, centre.getY() + c.getY()*mult) nb_ennemis += 1 elif c.getType() == 'RocketLauncher': mult = 200- c.distanceTo(Point()) centre.setCoord(centre.getX() + c.getX()*mult, centre.getY() + c.getY()*mult) nb_ennemis += 1 if synchro.pret(): monEtat() elif zero_cible and cibles_observees != []: monEtat() synchro.decrementer() #self.setUserMessage(str(len(cibles_observees))) if nb_ennemis > 0: centre.setCoord(centre.getX()/nb_ennemis, centre.getY()/ nb_ennemis) repuls = 180 self.setHeading(repuls + self.towards(centre.getX(),centre.getY())) # Evitement des obstacles divers evite = Point() evite_rockets = Point() nb_rockets = 0 nb_obs = 0 nb_murs = 0 nouvelles_rockets = [] #print '' for p in percepts: if p.getPerceptType() == 'Rocket': pos = Point() pos.setCoord(p.getX() + coordonnees.getX(), p.getY() + coordonnees.getY()) c = Rocket(pos) nouvelles_rockets.append(c) ecart_min = ecartMin(p) d = self.distanceTo(p) if d < ecart_min: if d > 0: mult = (ecart_min - d)/ecart_min evite.setCoord(evite.getX() - mult*p.getX()/d, evite.getY() - mult*p.getY()/d ) nb_obs = nb_obs + 1 if p.getPerceptType() == 'Obstacle': nb_murs = nb_murs + 1 # Evitement des rockets en prenant en compte leur deplacement rockets = [] for r in liste_rockets: lg = len(nouvelles_rockets) i = 0 trouve = 0 if r.getDejaVu(): nouv_pos = r.getNextCoord() while not trouve and i < lg: r2 = nouvelles_rockets[i] if r2.getCoord().distanceTo(nouv_pos) < 0.5: r.setCoord(r2.getX(), r2.getY()) rockets.append(r) trouve = 1 nouvelles_rockets.remove(r2) else: i += 1 else: while not trouve and i < lg: r2 = nouvelles_rockets[i] dst = r2.getCoord().distanceTo(r.getCoord()) if abs(dst - 4) < 0.5: r.setCoord(r2.getX(), r2.getY()) rockets.append(r) trouve = 1 nouvelles_rockets.remove(r2) else: i += 1 for r in rockets: s = (r.getNextCoord().getY() - r.getY())/4 c = (r.getNextCoord().getX() - r.getX())/4 t = s/c x = r.getX() - coordonnees.getX() y = r.getY() - coordonnees.getY() centre_x = ( x + t* y) / (c + s * t) centre_y = -y/c + t * centre_x centre = Point() centre.setCoord(x, y) distance = centre.distanceTo(Point()) #Si je suis sur la trajectoire if distance < 80 and centre_x < 0 and abs(centre_y < 16): nb_rockets += 1 mult = (80 - distance)/80 if centre_y >= 0: evite_rockets.setCoord(evite_rockets.getX() + mult*y, evite_rockets.getY() - mult*x) else: evite_rockets.setCoord(evite_rockets.getX() - mult*y, evite_rockets.getY() + mult*x) #print str(int(centre_x*1000) / 1000), str(int(centre_y * 1000) / 1000) liste_rockets = rockets for r in nouvelles_rockets: liste_rockets.append(r) #print '' #for r in liste_rockets: # print r.getX(), r.getY() eviteObstacles(liste_obs) if nb_rockets > 0: direct = self.getHeading()*Math.PI/ 180 but_virtuel = Point() but_virtuel.setCoord(2*Math.cos(direct),2*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + evite_rockets.getX(),but_virtuel.getY() + evite_rockets.getY())) if nb_obs > 0: direct = self.getHeading()*Math.PI/ 180 but_virtuel = Point() but_virtuel.setCoord(1*Math.cos(direct),1*Math.sin(direct)) self.setHeading(self.towards(but_virtuel.getX() + evite.getX(),but_virtuel.getY() + evite.getY() )) # Reception des messages while not self.isMessageBoxEmpty(): message = self.readMessage() # Message de position de la base if message.getAct() == 'POS': coordonnees.setCoord(-message.getFromX(), -message.getFromY()) elif message.getAct() == 'INFO-QG': x_absolu = message.getFromX() + float(message.getArgN(1)) + coordonnees.getX() y_absolu = message.getFromY() + float(message.getArgN(2)) + coordonnees.getY() b = Point(x_absolu, y_absolu) if (not baseEnnemieConnue(b)): base_ennemie.append(b) elif message.getAct() == 'FIN-NUM' : if int(message.getArg1()) < moi : moi = moi - 1 elif message.getAct() == 'NUM': liste_autres.append(message.getSender()) elif message.getAct() == 'FIN-QG': x = message.getFromX() + float(message.getArg1()) + coordonnees.getX() y = message.getFromY() + float(message.getArg2()) + coordonnees.getY() b = Point(x,y) baseEnnemieSuppr(b) elif message.getAct() == 'LAUNCHER_VU': launcher_vu = 1 elif message.getAct() == 'ROCKET-REQ': if adr_objectif == None and not cible_launcher: self.send(message.getSender(), 'ROCKET-OFFRE') adr_objectif = message.getSender() dest = Point() dest.setCoord(message.getFromX() + coordonnees.getX() + float(message.getArg1()), message.getFromY() + coordonnees.getY() + float(message.getArg2())) objectif.setCoord (dest.getX(), dest.getY()) elif message.getAct() == 'ROCKET-OK' and adr_objectif == message.getSender(): dest = Point() dest.setCoord(message.getFromX() + coordonnees.getX() + float(message.getArg1()), message.getFromY() + coordonnees.getY() + float(message.getArg2())) objectif.setCoord (dest.getX(), dest.getY()) elif message.getAct() == 'ROCKET-NON': if adr_objectif == message.getSender(): adr_objectif = None elif estMonSuperieur(message.getSender()) and (message.getAct() == 'HELP0' or message.getAct() == 'HELP1'): x = message.getFromX()+ float(message.getArg1()) y = message.getFromY()+ float(message.getArg2()) pos = Point() pos.setCoord(x, y) for c in cibles_observees: if pos.distanceTo(c.getCoord()) <= 10: c.setVuParAutre(6) # 6 tours avant fin ttl self.move()
def tick(self): if self.t == 0: PersistentDataAPI.setInt(PersistentDataAPI.getData(self.player), 'totem_task', self.getTaskId()) if not self.hit: if not self.totem.isOnGround(): self.particle( self.totem.getLocation().clone().add(0, 1, 0), Particle.END_ROD if self.clone else Particle.VILLAGER_HAPPY, 1, 0, 0, 0, 0) self.delay() else: self.hit = True self.totem.setMarker(True) self.holo = self.player.getWorld().spawnEntity( self.totem.getLocation().clone().add(0, 2.7, 0), EntityType.ARMOR_STAND) self.holo.setMarker(True) self.holo.setVisible(False) self.holo.setInvulnerable(True) self.holo.setCustomName(PySpell.colorText('20s', 'c')) self.holo.setCustomNameVisible(True) PersistentDataAPI.setInt( PersistentDataAPI.getData(self.player), 'totem_holo', self.holo.getEntityId()) l = self.totem.getLocation() self.particle(l.clone().add(0, -1, 0), Particle.EXPLOSION_HUGE, 1, 0, 0, 0, 1) self.particle( l, Particle.FIREWORKS_SPARK if self.clone else Particle.CRIT_MAGIC, 5, 2, 2, 2, .8) self.particle(l, Particle.SQUID_INK, 5, 2, 2, 2, .5) self.sound(l, Sound.ENTITY_EVOKER_PREPARE_SUMMON, .9, 1.1) self.sound(l, Sound.ENTITY_IRON_GOLEM_DEATH, 1, .8) self.sound(l, Sound.ITEM_TOTEM_USE, .9, 1) if self.clone: self.sound(l, Sound.ENTITY_FIREWORK_ROCKET_BLAST_FAR, 1, .7) self.sound(l, Sound.BLOCK_FIRE_EXTINGUISH, .5, .5) self.sound(l, Sound.ENTITY_BLAZE_DEATH, .3, 1) for e in self.nearbyMobs(l, 4, 4, 4): self.damage(e, False, 1, .8, 0, 0, 0, .2, 0) PySpell.knockback(e, VectorUP, .5) else: if self.totem.isOnGround() and self.t >= 20: self.totem.setMarker(True) if self.t < 400: if self.t % 20 == 0: self.holo.setCustomName( PySpell.colorText('{0}s'.format((400 - self.t) // 20), 'c')) for e in self.player.getWorld().getNearbyEntities( self.totem.getLocation(), 8, 4, 8): if not isinstance(e, Mob): continue if isinstance(e, Player): PySpell.heal( e, self.player.getAttribute( Attribute.GENERIC_MAX_HEALTH).getValue() / 10) else: self.damage(e, False, .2, .8, 0, 0, 0, 0, .2) l = self.totem.getLocation().clone().add( Math.sin(self.t * 10 * DEG2RAD) * 8, .7, Math.cos(self.t * 10 * DEG2RAD) * 8) self.particle( l, Particle.FIREWORKS_SPARK if self.clone else Particle.TOTEM, 1, 0, 0, 0, 0) self.particle(self.totem.getLocation().clone().add(0, 1, 0), Particle.SPELL_MOB, 2, .5, 1, .5, .5) self.holo.teleport(self.totem.getLocation().clone().add( 0, 2.7, 0)) else: self.totem.remove() self.holo.remove() self.player.removeScoreboardTag('totem')
phiAngle = sys.argv[2] data = DataBaseLoader.getCalorimeterConstants() print data.toString() factory = ECFactory() ecDetector = factory.createDetectorCLAS(data) ecDetector.show() pathMag = 15000.0 pathPhi = float(phiAngle)/57.29 pathTheta = float(thetaAngle)/57.29 path = Path3D() path.addPoint(0.0,0.0,0.0) path.addPoint(pathMag*Math.sin(pathTheta)*Math.cos(pathPhi),pathMag*Math.sin(pathTheta)*Math.sin(pathPhi),pathMag*Math.cos(pathTheta)) hits = ecDetector.getHits(path) print '\n-->\n' for hit in hits: if(hit.getLayerId()<3): print hit.toString() point = Point3D(0.0,0.0,697.7) point.rotateY(25.0/59.27) print point.toString() #layer = ecDetector.getSector(0).getSuperlayer(0).getLayer(0)