// make the specified action for the current player and update the // game state accordingly. // The function may assume that the action requested is legal. // START_SPINOFF is not a legal action here void makeAction (Game g, action a) { // determine the current player int curPlayer; curPlayer = getWhoseTurn (g); int rate = 0; // peforms a particular action given the action code if (a.actionCode == PASS) { throwDice (g, rollDice()); } else if (a.actionCode == BUILD_CAMPUS) { // deduct the resources from the player g->uni[curPlayer].numStudents[STUDENT_BPS] -= 1; g->uni[curPlayer].numStudents[STUDENT_BQN] -= 1; g->uni[curPlayer].numStudents[STUDENT_MJ] -= 1; g->uni[curPlayer].numStudents[STUDENT_MTV] -= 1; makeCampus (g, a.destination, curPlayer); g->uni[curPlayer].numCmps++; } else if (a.actionCode == BUILD_GO8) { // deduct the resources from the player g->uni[curPlayer].numStudents[STUDENT_MJ] -= 2; g->uni[curPlayer].numStudents[STUDENT_MMONEY] -= 3; makeG08 (g, a.destination, curPlayer); g->uni[curPlayer].numCmps--; g->uni[curPlayer].numG08s++; } else if (a.actionCode == OBTAIN_ARC) { // deduct the resources from the player g->uni[curPlayer].numStudents[STUDENT_BQN] -= 1; g->uni[curPlayer].numStudents[STUDENT_BPS] -= 1; makeArc (g, a.destination, curPlayer); g->uni[curPlayer].numArcs++; //change mostArcs if (g->mostArcs == NO_ONE) { g->mostArcs = curPlayer; } else if(g->uni[curPlayer].numArcs > g->uni[g->mostArcs].numArcs){ g->mostArcs = curPlayer; } } else if (a.actionCode == OBTAIN_PUBLICATION) { g->uni[curPlayer].numPubs++; //change mostPubs if (g->mostPubs == NO_ONE) { g->mostPubs = curPlayer; } else if(g->uni[curPlayer].numPubs > g->uni[g->mostPubs].numPubs){ g->mostPubs = curPlayer; } } else if (a.actionCode == OBTAIN_IP_PATENT) { g->uni[curPlayer].numIPs++; } else if (a.actionCode == RETRAIN_STUDENTS) { rate = getExchangeRate (g, curPlayer, a.disciplineFrom, a.disciplineTo); g->uni[curPlayer].numStudents[a.disciplineFrom] -= rate; g->uni[curPlayer].numStudents[a.disciplineTo]++; } }
void OpenInfraPlatform::UserInterface::CreateLineArcArcLineDialog::on_pushButtonGenerate_clicked() { hide(); buw::vector2d P[9], LineDir[6], starti[6], endi[6]; std::vector<buw::vector2d> oldEnd, end, start, center; // very important is to determine between RR1 and R[0] double beta[3], t1[3], t2[3], R[2], RR2, RR1, alpha = 0, YM1 = 0, X1 = 0, YM2 = 0, X2 = 0, phi = 0, psi = 0; double width, u1, u2, u3, u4; bool first; std::string message; QString s = ui_->lineEdit_R1->text(); RR1 = s.toDouble(); s = ui_->lineEdit_R2->text(); RR2 = s.toDouble(); s = ui_->lineEdit_u1->text(); u1 = s.toDouble(); s = ui_->lineEdit_u2->text(); u2 = s.toDouble(); s = ui_->lineEdit_u3->text(); u3 = s.toDouble(); s = ui_->lineEdit_u4->text(); u4 = s.toDouble(); s = ui_->lineEdit_c->text(); width = s.toDouble(); if (ui_->radioButton_first->isChecked()) { first = true; } if (ui_->radioButton_last->isChecked()) { first = false; } buw::ReferenceCounted<buw::HorizontalAlignment2D> ha = std::make_shared<buw::HorizontalAlignment2D>(); if (are3_4or5Points(points_.size(), message) == 0 || (points_.size() > 3 && (isInsertNotZero(RR1, RR2, 1, message) == 0 || isU3U4SmallerLength(u3, u4, t1[2], message) == 0 || isU1U2SmallerLength(u1, u2, t1[1], message) == 0))) { QMessageBox::warning(this, QApplication::applicationName(), QString::fromStdString(message)); return; } give3Points(P[0], P[1], P[2], LineDir[0], LineDir[1], beta[0], t1[0], t2[0], points_[0].xy(), points_[1].xy(), points_[2].xy(), offset_); if (points_.size() > 3) { give3Points(P[3], P[4], P[5], LineDir[2], LineDir[3], beta[1], t1[1], t2[1], points_[1].xy(), points_[2].xy(), points_[3].xy(), offset_); t2[0] = u1, t1[1] = u2, P[2] = P[1] + u1*LineDir[1], P[3] = P[4] + u2*LineDir[2]; } if (points_.size() > 4) { give3Points(P[6], P[7], P[8], LineDir[4], LineDir[5], beta[2], t1[2], t2[2], points_[2].xy(), points_[3].xy(), points_[4].xy(), offset_); t2[0] = u1, t1[1] = u2, P[2] = P[1] + u1*LineDir[1], P[3] = P[4] + u2*LineDir[2]; t2[1] = u3, t1[2] = u4, P[5] = P[3] + u3*LineDir[3], P[6] = P[7] + u4*LineDir[5]; } buw::ReferenceCounted<buw::HorizontalAlignmentElement2DLine> line1 = std::make_shared<buw::HorizontalAlignmentElement2DLine>(P[0], P[1]); ha->addElement(line1); for (int Groupnumber = 0; Groupnumber < points_.size() - 2; Groupnumber++) { alpha = M_PI - beta[Groupnumber]; if (RR1 == 0) { YM2 = t2[Groupnumber] * sin(alpha) + RR2 * cos(alpha); X2 = -t2[Groupnumber] * cos(alpha) + RR2 * sin(alpha); phi = 2 * atan((YM2 - RR2) / (t1[Groupnumber] - X2)); R[0] = RR2 + (t1[Groupnumber] - X2) / sin(phi); } if (RR1 != 0 && RR2 != 0 && first == false) { R[0] = RR1; phi = acos((RR1 - t2[Groupnumber] * sin(alpha) - RR2*cos(alpha)) / (RR1 - RR2)); t1[Groupnumber] = (RR1 - RR2)*sin(phi) + RR2*sin(alpha) - t2[Groupnumber] * cos(alpha); } psi = alpha - phi; R[1] = RR2; if (RR2 == 0) { R[0] = RR1; YM1 = t1[Groupnumber] * sin(alpha) + R[0] * cos(alpha); X1 = R[0] * sin(alpha) - t1[Groupnumber] * cos(alpha) - t2[Groupnumber]; psi = 2 * atan((-YM1 + R[0]) / X1); R[1] = R[0] - X1 / sin(psi); } if (RR1 != 0 && RR2 != 0 && first == true) { R[0] = RR1; R[1] = RR2; psi = acos((t1[Groupnumber] * sin(alpha) + RR1*cos(alpha) - RR2) / (RR1 - RR2)); t2[Groupnumber] = RR1*sin(alpha) - t1[Groupnumber] * cos(alpha) - (RR1 - RR2)*sin(psi); } phi = alpha - psi; if (psi < 0 || phi < 0) { QMessageBox::warning(this, QApplication::applicationName(), "Change the angle between the lines, otherwise one arclength would be negativ."); return; } bool clocky = true; int sig = 1; if (LineDir[Groupnumber * 2].x()*LineDir[Groupnumber * 2 + 1].y() - LineDir[Groupnumber * 2].y()*LineDir[Groupnumber * 2 + 1].x() < 0)// vectorproduct determines the orientation of arcs { clocky = false; sig = -1; } start.push_back(P[Groupnumber * 3]); center.push_back(start[0] + R[0] * buw::createRotationZ22d(sig*M_PI / 2)* LineDir[Groupnumber * 2]); end.push_back(center[0] + buw::createRotationZ22d(-sig*phi)* (start[0] - center[0])); end.push_back(P[Groupnumber * 3 + 2]); center.push_back(end[1] + R[1] * buw::createRotationZ22d(-sig*M_PI / 2)* LineDir[Groupnumber * 2 + 1]); start.push_back(center[1] + buw::createRotationZ22d(sig*psi)* (end[1] - center[1])); if (isIntersectionArcArc(center[0], center[1], R[0] + width, R[1] + width, message) == 0 || areErrorsForParallelArc(R[0], width, message) == 0 || areErrorsForParallelArc(R[1], width, message) == 0) { QMessageBox::warning(this, QApplication::applicationName(), QString::fromStdString(message)); return; } for (int k = 0; k < 2; k++) { makeArc(center[k], start[k], end[k], clocky); } buw::ReferenceCounted<buw::HorizontalAlignmentElement2DLine> line2 = std::make_shared<buw::HorizontalAlignmentElement2DLine>(P[Groupnumber * 3 + 1], P[Groupnumber * 3 + 2]); ha->addElement(line2); if (width > 0) {// index of endi or starti : i%2==1 means inner and i%2==0 means outer endi[2] = center[1] + ((R[1] + width) / R[1])*(end[1] - center[1]);// outside endi[3] = center[1] + ((R[1] - width) / R[1])*(end[1] - center[1]); endi[2] = center[1] + ((R[1] + width) / R[1])*(end[1] - center[1]);// this line creates a special parameters for GeneralLineArcArcArcLine GeneralLine_Arc_Arc_Arc_Line(2, Groupnumber, width, R[0], R[1], R[1], clocky, starti[4], endi[2], endi[4], oldEnd, end, start, center); } oldEnd.push_back(end[1]); oldEnd.push_back(endi[2]); oldEnd.push_back(endi[3]); // generates old values } make3DLine(ha);// middle that consists just of the connected alignment-points }
void Esh3DRenderer::render(const EshShape& in_shape, EshRendererContext& in_rendererContext,MfGdiBrush *in_brush) { ChLOG_DEBUG_START_FN; if (!setUp(in_shape, in_rendererContext)) { return; } // temporary pen & brush so I can see what I'm doing! //ChAutoPtr<MfGdiBrush> pBrush = m_driver.CreateSolidBrush(CsColour(0x88, 0x88, 0x88)); //ChAutoPtr<MfGdiPen> pPen = m_driver.CreatePen(MfGdiPen::Style_Solid, 4, CsColour(0,0,0), ChVector<ChFLT8>()); //ChAutoPtr<MfGdiBrush> pBrush = EshGdiObjectFactory::makeNullBrush(m_driver); ChAutoPtr<MfGdiPen> pPen(EshGdiObjectFactory::makeNullPen(m_driver)); // LINUX_PORT // TODO - pen must be null pen, but because faces aren't being shaded according to normal angle, an // outline is being drawn to figure out where the faces are //in_rendererContext.getDeviceContextReference().SetBrush(*pBrush); //in_rendererContext.getDeviceContextReference().TakeBrush(pBrush.giveUpOwnership()); in_rendererContext.getDeviceContextReference().TakePen(pPen.giveUpOwnership()); if (in_rendererContext.hasTransformation()) { // 2D rotation must be done before any 3D rotation/skew, so multiply on right of current // 3D world transform, which at this point will have the skew and rotation already m_worldTransform = m_worldTransform * CsMatrix3D<ChFLT8>(in_rendererContext.getTransformationMatrix()); } m_pPathData = ChNEW EshPathRendererData(*m_pGeometry, in_rendererContext); m_pPathData->init(); MfGdiDeviceContext& deviceContext = in_rendererContext.getDeviceContextReference(); // use non-const verion of method to have geometry add implied segments const EshPathCommandTable& pathCommands = m_pPathData->getPathCommandsReference(); if (pathCommands.size() == 0) { return; } bool skip = true; bool isFirstSegmentDrawn = false; CsPoint<ChFLT8> startPosition(0,0); CsPoint<ChFLT8> position(0,0); CsPoint<ChFLT8> nextPosition(0,0); const EshPathCommand* pCurrentPathCommand; const EshPathCommand* pNextPathCommand; ChUINT2 j = 0; /** * TODO - is it possible for the first path param to be an editing command? */ pNextPathCommand = &pathCommands[0]; EshPathCommandTypeEnums nextPathCommandType = pNextPathCommand->m_type; CsPlanarPolygon<ChFLT8> frontFace; CsPlanarPolygon<ChFLT8> extrusion; for (ChUINT4 i=1; i <= pathCommands.size(); i++) { pCurrentPathCommand = pNextPathCommand; // Skip editing commands skip = true; while ( skip && i < pathCommands.size()) { skip = (ESH_PATH_CMD_HA <= pathCommands[i].m_type && pathCommands[i].m_type <= ESH_PATH_CMD_HI); if(skip) { ++i; } } if (i == pathCommands.size()) { nextPathCommandType = ESH_PATH_CMD_E; } else { pNextPathCommand = &pathCommands[i]; nextPathCommandType = pNextPathCommand->m_type; } bool isLastCommand = (nextPathCommandType == ESH_PATH_CMD_E); bool isEnd = isLastCommand; switch (pCurrentPathCommand->m_type) { case ESH_PATH_CMD_L: // Line to // openClosedPath(deviceContext); for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); m_pPathData->getPoint(nextPosition); //m_pPathData->getPoint(nextPosition); if (!isFirstSegmentDrawn) { startPosition = position; frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } if (m_isFilled) { frontFace.addPoint(m_worldTransform * ChPoint3DF8(nextPosition, m_lForeDepth)); } // TODO - linecap stuff makePolygon(position, nextPosition, extrusion); m_tree.insert(extrusion); position = nextPosition; } break; case ESH_PATH_CMD_C: // Cubic curve // openClosedPath(deviceContext); for (j=0; j < pCurrentPathCommand->m_unCount; j++) { ChPoint3DF8 p0(position.getX(), position.getY(), m_lForeDepth); ChPoint3DF8 p1(m_pPathData->getPointF8(), m_lForeDepth); // 1st control point ChPoint3DF8 p2(m_pPathData->getPointF8(), m_lForeDepth); // 2nd control point m_pPathData->getPoint(nextPosition); ChPoint3DF8 p3(nextPosition, m_lForeDepth); // endpoint if (!isFirstSegmentDrawn) { startPosition = position; if (m_isFilled) { frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); } isFirstSegmentDrawn = true; } divideBezier(p0, p1, p2, p3, frontFace); position = nextPosition; } break; case ESH_PATH_CMD_M: // Move to - count is always 1 ChASSERT(pCurrentPathCommand->m_unCount == 1); m_pPathData->getPoint(position); break; case ESH_PATH_CMD_X: // Close path nextPosition = startPosition; if (position != nextPosition) { makePolygon(position, nextPosition, extrusion); m_tree.insert(extrusion); position = nextPosition; } if (m_isFilled) { m_faces.push_back(frontFace); frontFace.clear(); } isFirstSegmentDrawn = false; break; case ESH_PATH_CMD_E: // End path data attribute /* Freeform paths will not have a close path command, however, if the path is filled, we still need a polygon for that line segment. */ if (m_isFilled && position != startPosition) { makePolygon(position, startPosition, extrusion); m_tree.insert(extrusion); position = startPosition; m_faces.push_back(frontFace); frontFace.clear(); } break; case ESH_PATH_CMD_AE: // Angle ellipse to for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeAngleEllipse(in_rendererContext, position, false, j, frontFace); isFirstSegmentDrawn = true; } else { makeAngleEllipse(in_rendererContext, position, false, j, frontFace); } } break; case ESH_PATH_CMD_AL: // Angle ellipse for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeAngleEllipse(in_rendererContext, position, true, j, frontFace); isFirstSegmentDrawn = true; } else { makeAngleEllipse(in_rendererContext, position, true, j, frontFace); } } break; case ESH_PATH_CMD_AT: // Arc to for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, false, j, false, frontFace); isFirstSegmentDrawn = true; } else { makeArc(position, false, j, false, frontFace); } } break; case ESH_PATH_CMD_AR: // Arc for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, true, j, false, frontFace); frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } else { makeArc(position, true, j, false, frontFace); } } break; case ESH_PATH_CMD_WA: // Clockwise arc to for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, false, j, true, frontFace); isFirstSegmentDrawn = true; } else { makeArc(position, false, j, true, frontFace); } } break; case ESH_PATH_CMD_WR: // Clockwise arc for (j=0; j < pCurrentPathCommand->m_unCount; j++) { isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); if (!isFirstSegmentDrawn) { startPosition = makeArc(position, true, j, true, frontFace); frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } else { makeArc(position, true, j, true, frontFace); } } break; case ESH_PATH_CMD_QX: // Elliptical quadrant x for (j=0; j < pCurrentPathCommand->m_unCount; j++) { if (!isFirstSegmentDrawn) { startPosition = position; isFirstSegmentDrawn = true; } isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); makeQuadrantArc(position, j % 2 == 0, frontFace); } break; case ESH_PATH_CMD_QY: // Elliptical quadrant y for (j=0; j < pCurrentPathCommand->m_unCount; j++) { if (!isFirstSegmentDrawn) { startPosition = position; frontFace.addPoint(m_worldTransform * ChPoint3DF8(position, m_lForeDepth)); isFirstSegmentDrawn = true; } isEnd = isLastCommand && (j == pCurrentPathCommand->m_unCount - 1); makeQuadrantArc(position, j % 2 == 1, frontFace); } break; } } // Draw the actual shape. m_tree.render(m_driver, in_rendererContext); if (m_isFilled) { ChBYTE opacity = 255; const EshFill &fill = in_shape.getFill(); if (fill.isOpacitySet()) { opacity = fill.getOpacity() >> 8; } renderPrimaryFaces(deviceContext,in_brush,opacity); }