QString Container::toString() const { QStringList ret; bool func=false; Operator *op=0; for(int i=0; i<m_params.count(); i++) { if(m_params[i]==0) { qDebug() << "kkk"; return "<<kk>>"; } if(m_params[i]->type() == Object::oper) op = (Operator*) m_params[i]; else if(m_params[i]->type() == Object::variable) { Ci *b = (Ci*) m_params[i]; if(b->isFunction()) func=true; ret << b->toString(); } else if(m_params[i]->type() == Object::container) { Container *c = (Container*) m_params[i]; QString s = c->toString(); Operator child_op = c->firstOperator(); if(op!=0 && op->weight()>child_op.weight() && child_op.nparams()!=1) s=QString("(%1)").arg(s); if(c->containerType() == Object::bvar) { Container *ul = ulimit(), *dl = dlimit(); if(ul!=0 || dl!=0) { if(dl!=0) s += dl->toString(); s += ".."; if(ul!=0) s += ul->toString(); } } if(c->containerType()!=Object::uplimit && c->containerType()!=Object::downlimit) ret << s; } else ret << m_params[i]->toString(); } QString toret; switch(containerType()) { case Object::declare: toret += ret.join(":="); break; case Object::lambda: toret += ret.join(""); break; case Object::math: toret += ret.join("; "); break; case Object::apply: if(func){ QString n = ret.takeFirst(); toret += QString("%1(%2)").arg(n).arg(ret.join(", ")); } else if(op==0) toret += ret.join(" "); else switch(op->operatorType()) { case Object::plus: toret += ret.join("+"); break; case Object::times: toret += ret.join("*"); break; case Object::divide: toret += ret.join("/"); break; case Object::minus: if(ret.count()==1) toret += "-"+ret[0]; else toret += ret.join("-"); break; case Object::power: toret += ret.join("^"); break; default: toret += QString("%1(%2)").arg(op->toString()).arg(ret.join(", ")); break; } break; case Object::uplimit: //x->(n1..n2) is put at the same time case Object::downlimit: break; case Object::bvar: toret += ret.join("->")+"->"; break; default: toret += ret.join(" ?? "); break; } return toret; }
// Fire guns void fire_guns(linkedlist <guntype> &gun, linkedlist <plane> &p, sampleio &sound, building b[MAP_W*2], linkedlist <shottype> &shot, double xmove[17], double ymove[17]){ gun.reset(); while (gun.next()){ // Find new target for gun if untargeted if (gun().target == 0){ int maxfind = 200; p.reset(); while (p.next()){ if ((gun().side != p().side) && (p().state < 2) && (p().land==2) && (gun().y > p().y) && (!p().hide)){ int dx = abs(gun().x - int(p().x)); if (dx < maxfind){ maxfind = dx; gun().target = p().id; } } } }else{ // Track the target of the gun p.reset(); while (p.next()){ if (p().id == gun().target){ p().gunthreat = gun().xpos; double dx = p().x - double(gun().x); double dy = double(gun().y) - p().y; // Rotate gun if ((gun().rotate == 0) && (dy > 0)){ double smartsine = (dy*p().xs+dx*p().ys)/ (8.0*GAME_SPEED*sqrt(dx*dx+dy*dy)); smartsine = dlimit(smartsine, -1.0, 1.0); double smartangle = asin(smartsine); int move = sign(int(((atan(dx/dy)+smartangle)*8.0/PI)+4.5)-gun().d); if (move != 0){ gun().d = limit(gun().d+move,1,7); b[gun().xpos].image = 162 + gun().d; gun().rotate = int(2/GAME_SPEED); } } // Shoot gun if ((gun().firedelay == 0) && (gun().ammo > 0) && (abs(int(dx))<150)){ gunshoot(gun(), shot, sound, xmove, ymove); } // Lose target if ((abs(int(dx))>200) || (p().state>1) || (p().hide) || (p().land !=2)){ gun().target = 0; } } } } // Sort out guntimers if (gun().firedelay > 0) gun().firedelay--; if (gun().rotate > 0) gun().rotate--; if (gun().ammo < 3){ gun().reload++; if (gun().reload == int(20/GAME_SPEED)){ gun().reload = 0; gun().ammo++; } } } }
void act(gamedata &g, int jx, int jy, bool jb){ // Reset hidden/afterburner status g.p().hide = false; g.p().boost = false; g.p().gunthreat = 0; switch(g.p().state){ case 0: // OK planes switch(g.p().land){ case 0: // Stationary on runway // Check for mission 0 and mission 1 wins if (((g.mission == 0) || (g.mission == 1)) && (!g.p().drak) && (g.p().score >= g.targetscore)){ g.winner = g.p().side; } // Start Engine if (jy == -1){ g.p().s = 0.3*GAME_SPEED*GAME_SPEED; g.p().land = 1; if ((g.p().control) > 0){ g.sound.volume(g.p().control-1, 0.0); g.sound.loop(g.p().control-1, g.p().enginesample); } } break; case 1: // Taking off plane if (jy == -1){ g.p().s = dlimit(g.p().s + 0.3*GAME_SPEED*GAME_SPEED, 0.0, 6.0*GAME_SPEED); } // Take off plane if ((jx == -1) && (g.p().s > 2.0*GAME_SPEED) && (g.base[g.p().side].planed == 13)){ g.p().d++; g.p().rotate = g.p().maxrotate; g.p().land = 2; } if ((jx == 1) && (g.p().s > 2.0*GAME_SPEED) && (g.base[g.p().side].planed == 5)){ g.p().d--; g.p().rotate = g.p().maxrotate; g.p().land = 2; } // Off end of runway if (abs(int(g.p().x - g.base[g.p().side].planex)) > g.base[g.p().side].runwaylength){ g.p().land = 2; } break; case 2: // flying // Navigate plane if ((g.p().rotate == 0) && (jx !=0)){ g.p().d = wrap(g.p().d-jx,1,17); g.p().rotate = g.p().maxrotate; }else{ if (g.p().rotate > 0){ g.p().rotate--; } } // Acceleration / Afterburner Controls { double acceleration = g.accel[g.p().d] * GAME_SPEED * GAME_SPEED; if (g.p().burner){ if (jy == -1){ acceleration += 0.3*GAME_SPEED*GAME_SPEED; g.p().boost = true; } if ((g.p().s > 6.0*GAME_SPEED) && (jy != -1)){ acceleration -= 0.3*GAME_SPEED*GAME_SPEED; } g.p().s = dlimit(g.p().s + acceleration, 0.0, 12.0*GAME_SPEED); }else{ g.p().s = dlimit(g.p().s + acceleration, 0.0, 6.0*GAME_SPEED); } } // Stealth Controls if ((jy == -1) && (jx == 0) && (!jb) && (g.p().stealth)){ g.p().hide = true; } // Check for shotfire if (g.p().shotdelay == 0){ if ((jb) && (g.p().ammo > 0)){ fire_shot(g.p(), g.shot, g.sound, g.xmove, g.ymove); } // Check for bombdrop if ((jy == 1) && (g.p().bombs > 0)){ drop_bomb(g.p(), g.fall, g.sound, g.bombimage); } }else{ g.p().shotdelay--; } break; case 3: // Landing plane if ((((g.p().x - g.base[g.p().side].planex) < 2.0) && (g.base[g.p().side].planed == 13)) || (((g.p().x - g.base[g.p().side].planex) > -2.0) && (g.base[g.p().side].planed == 5))){ g.p().land = 0; g.p().x = g.base[g.p().side].planex; g.p().y = g.base[g.p().side].planey; g.p().d = g.base[g.p().side].planed; g.p().xs = 0; g.p().ys = 0; g.p().s = 0; g.p().ammo = g.p().maxammo; g.p().bombs = g.p().maxbombs; g.p().coms = 0; g.p().targetx = 0; g.p().targety = 0; g.p().cruiseheight = 0; } break; } // Set speed for planes g.p().xs = g.p().s * g.xmove[g.p().d]; g.p().ys = g.p().s * g.ymove[g.p().d]; // Check for stall if ((g.p().s < 1.0*GAME_SPEED) && (g.p().land == 2)){ g.p().state = 1; if ((g.p().control) > 0){ g.sound.stop(g.p().control-1); g.sound.play(SOUND_STALL); } } if (g.p().y < 0){ g.p().y = 0; g.p().ys = 0; g.p().state = 1; if ((g.p().control) > 0){ g.sound.stop(g.p().control-1); g.sound.play(SOUND_STALL); } } break; case 1: // Stalling planes // Navigate plane if ((g.p().rotate == 0) && (jx !=0)){ g.p().d = wrap(g.p().d-jx,1,17); g.p().rotate = g.p().maxrotate; }else{ if (g.p().rotate > 0){ g.p().rotate--; } } // Check for shotfire if (g.p().shotdelay == 0){ if ((jb) && (g.p().ammo > 0)){ fire_shot(g.p(), g.shot, g.sound, g.xmove, g.ymove); } // Check for bombdrop if ((jy == 1) && (g.p().bombs > 0)){ drop_bomb(g.p(), g.fall, g.sound, g.bombimage); } }else{ g.p().shotdelay--; } // Gravity and drag g.p().ys += 0.1 * GAME_SPEED * GAME_SPEED; if (fabs(g.p().xs) > 0.02 * GAME_SPEED * GAME_SPEED){ g.p().xs -= g.p().xs / fabs(g.p().xs) * 0.02 * GAME_SPEED * GAME_SPEED; } // Recover from Stall if ((g.p().ys > 3.0 * GAME_SPEED) && (g.p().d == 9)){ g.p().s = dlimit(g.p().ys, 3.0*GAME_SPEED, 6.0*GAME_SPEED); g.p().state = 0; g.p().xs = g.p().s * g.xmove[g.p().d]; g.p().ys = g.p().s * g.ymove[g.p().d]; g.p().coms = 0; if ((g.p().control) > 0){ double volume = g.p().s / (6.0*GAME_SPEED); g.sound.volume(g.p().control-1, volume * 0.5); g.sound.loop(g.p().control-1, g.p().enginesample); } } break; case 2: // Dead planes // Gravity and drag g.p().ys += 0.1 * GAME_SPEED * GAME_SPEED; if (fabs(g.p().xs) > 0.02 * GAME_SPEED * GAME_SPEED){ g.p().xs -= g.p().xs/ fabs(g.p().xs) * 0.02 * GAME_SPEED * GAME_SPEED; } // Smoking plane g.p().crash++; if (g.p().crash == int(5/GAME_SPEED)){ g.p().crash = 0; smoketype newsmoke; newsmoke.x = int(g.p().x); newsmoke.y = g.p().y; newsmoke.time = 0; g.smoke.add(newsmoke); } break; case 3: // Crashed planes g.p().crash++; if (g.p().crash == int(70/GAME_SPEED)){ if (!g.p().drak){ // Respawn plane to runway g.p().land = 0; g.p().state = 0; g.p().rotate = 0; g.p().crash = 0; g.p().x = g.base[g.p().side].planex; g.p().y = g.base[g.p().side].planey; g.p().d = g.base[g.p().side].planed; g.p().xs = 0; g.p().ys = 0; g.p().s = 0; g.p().ammo = g.p().maxammo; g.p().bombs = g.p().maxbombs; g.p().coms = 0; g.p().targetx = 0; g.p().targety = 0; g.p().cruiseheight = 0; }else{ // Expunge drak g.p().state = 4; } } break; case 4: // Expunged drak fighter (NB: shouldn't get here!) break; } // Move the planes g.p().x += g.p().xs; g.p().y += g.p().ys; // Control Engine Volume if ((g.p().control) > 0){ if ((g.p().state == 0) && (g.p().land > 0)){ double volume = g.p().s / (6.0*GAME_SPEED); g.sound.volume(g.p().control-1, volume * 0.5); if ((g.p().boost) && (g.p().enginesample == SOUND_JET)){ g.p().enginesample = SOUND_BURNER; g.sound.loop(g.p().control-1,SOUND_BURNER); } if ((!g.p().boost) && (g.p().enginesample == SOUND_BURNER)){ g.p().enginesample = SOUND_JET; g.sound.loop(g.p().control-1,SOUND_JET); } }else{ g.sound.stop(g.p().control-1); } } if (g.p().state < 3) detect_collisions(g); }