void clearProjectile() { proj.present = false; clearSquare(proj.prev_x, proj.prev_y); proj.x = 0; proj.y = 0; proj.prev_x= 1; proj.prev_y= 1; }
/* * Displays a missile. Takes the new location to display the missile in x_loc and y_loc * Takes the previous location of the missile to delete, if the clear boolean is set */ void showMissile(Loc x_loc, Loc y_loc, Direction dir, Loc prev_x, Loc prev_y, bool clear) { { register BitCell *bp; bp = missile; if ( clear ) clearSquare(prev_x, prev_y); HackMazeBitmap(x_loc, y_loc, &bp[0]); } }
/* * When someone moves off a position, clear it out. If there's someone * "under" him, display the second guy. */ void clearPosition(RatIndexType ratIndex, Loc xClear, Loc yClear) { Rat rp; register int i; clearSquare(xClear, yClear); for (i = 0; i < MAX_RATS; i++) { rp = M->rat(i); if ((i == ratIndex.value()) || !(rp.playing)) continue; if ((rp.x == xClear) && (rp.y == yClear)) if (i == MY_RAT_INDEX) showMe(rp.x, rp.y, rp.dir); } }
void processPacket (MWEvent *eventPacket) { MW244BPacket *p = new MW244BPacket ; p = eventPacket->eventDetail; /*cout << p->ID<< endl; cout << p->sequence_number<< endl; cout << p->score<< endl; cout << p->x_pos<< endl; cout << p->y_pos<< endl; cout << p->dir<< endl; cout << p->tagged_rat<< endl; cout << p->globalID<< endl; ConvertIncoming(p); cout << p->ID<< endl; cout << p->sequence_number<< endl; cout << p->score<< endl; cout << p->x_pos<< endl; cout << p->y_pos<< endl; cout << p->dir<< endl; cout << p->tagged_rat<< endl; cout << p->globalID<< endl; exit(0);*/ cout << "PP " << p->ID << endl; if (myPacket(p, &eventPacket->eventSource) && join)// BECAUSE WHILE YOU ARE STILL 0, you will get packets with ID 0 { return; } else { if (!join && expected_seqno[p->ID] <= p->sequence_number){ if (p->globalID == 7) // What if there is only player with global ID 7? :/ { cout << "You are one player too many :(" << endl; cout << "Please try again later." << endl; exit(0); } else { for (int i = 0; i < 100; i++) cout << "Incrementing for no reason" << endl; join = true; GLOBAL_ID = p->globalID+1; M->myRatIdIs(GLOBAL_ID); setMapping(); UpdateScoreCard(0); MW244BPacket q; makePacket(&q,'h',-1, updateSeqNo); sendPacketToPlayers(q); participants[p->ID]++; Rat r; r.playing = 1; cout << "NEW " << p->ID << endl; r.x=p->x_pos; r.y=p->y_pos; r.dir=(p->dir); M->mazeRats_[Mapping_idToIndex.find(p->ID)->second] = r; rat_array[p-> ID]=new MW244BPacket; rat_array[Mapping_idToIndex.find(p->ID)->second]=p; Loc x(p->x_pos); Loc y(p->y_pos); Direction dir(p-> dir); RatIndexType ratId(Mapping_idToIndex.find(p->ID)->second); SetRatPosition(ratId, x, y, dir); UpdateScoreCard(Mapping_idToIndex.find(p-> ID)->second); expected_seqno[p->ID] = p->sequence_number + 1; return; } } if (GLOBAL_ID < p->globalID && expected_seqno[p->ID] <= p->sequence_number ) GLOBAL_ID = p->globalID; if (p->status == 'a' && p->tagged_rat == M->myRatId().value()) { // cannot discard expected_seqno[p->ID] <= p->sequence_number // because we're getting this packet because the other side didn't get b :( // MUST send b MW244BPacket q; makePacket(&q,'b',-1, updateSeqNo); sendPacketToPlayers(q); cout<<p->sequence_number<<"Seq number"<<endl; cout<<prevseq_a[p->ID]<<"Previous Seq number"<<endl; if (p->sequence_number > prevseq_a[p->ID]) { // dealing with duplicates DrawString("You have been tagged!",21,200,250); M->scoreIs( M->score().value()-5 ); UpdateScoreCard(0); NewPosition(M); } prevseq_a[p->ID] = p->sequence_number; } else if (p->status == 'a' && expected_seqno[p->ID] <= p->sequence_number){ //RatIndexType ratId(p-> ID); //ClearRatPosition(ratId); RatIndexType ratId( Mapping_idToIndex.find(p->ID)->second); ClearRatPosition(ratId); } if (p->status == 'b' && expected_seqno[p->ID] <= p->sequence_number) { checkingzero = 1; updateSeqNo = true; } if (p->status == 'f' && expected_seqno[p->ID] <= p->sequence_number) { //player has left cout << "Player has gone :(" << endl; participants[p->ID] = -1;// in next section, will be incremented to 0 // automatically dealt with in ratstates RatIndexType ratId( Mapping_idToIndex.find(p->ID)->second); ClearRatPosition(ratId); // WHY IS THIS NOT WORKING? :/ clearSquare(p->x_pos, p->y_pos); cout << p->x_pos << "," << p->y_pos << endl; cout << M->mazeRats_[Mapping_idToIndex.find(p->ID)->second].x.value() << "," << M->mazeRats_[Mapping_idToIndex.find(p->ID)->second].y.value() << endl; } if (expected_seqno[p->ID] <= p->sequence_number) { // if this condition is false, then we are discarding the packet. Rat r; r.playing = 1; cout << "IF " << p->ID << endl; r.x=p->x_pos; r.y=p->y_pos; r.dir=(p->dir); M->mazeRats_[Mapping_idToIndex.find(p->ID)->second] = r; rat_array[p-> ID]=new MW244BPacket; rat_array[Mapping_idToIndex.find(p->ID)->second]=p; Loc x(p->x_pos); Loc y(p->y_pos); Direction dir(p-> dir); RatIndexType ratId(Mapping_idToIndex.find(p->ID)->second); SetRatPosition(ratId, x, y, dir); UpdateScoreCard(Mapping_idToIndex.find(p-> ID)->second); expected_seqno[p->ID] = p->sequence_number + 1; participants[p->ID]++; } } }