<commit_before>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qcontactmemorybackenddata_simulator_p.h"

#include <QtCore/QDataStream>
#include <QtCore/QAtomicInt>
#include <qcontact_p.h>
#include <qcontactrelationship_p.h>
#include <qcontactdetail_p.h>
#include <qcontactid_p.h>
#include <qcontactdetaildefinition_p.h>
#include <qcontactdetailfielddefinition_p.h>

Q_DECLARE_METATYPE(QtMobility::QContactData)
Q_DECLARE_METATYPE(QtMobility::QContactRelationshipPrivate)

QTM_BEGIN_NAMESPACE

#ifdef SIMULATOR_APPLICATION
// Workaround for non-exported symbol that is used by this file.
// It won't matter if this wrong lastDetailKey is used here, , since m_id is always
// set again when a QContactDetail is sent through the sockets.
QAtomicInt QContactDetailPrivate::lastDetailKey(1);

// Should work too, since they are only used for performance.
QHash<QString, char*> QContactStringHolder::s_allocated;
QHash<const char *, QString> QContactStringHolder::s_qstrings;

uint qHash(const QContactStringHolder &h)
{ return qHash(h.toQString()); }
#endif

void qt_registerContactsTypes()
{
    qRegisterMetaTypeStreamOperators<QContactSimulatorData>("QtMobility::QContactSimulatorData");
    qRegisterMetaTypeStreamOperators<QContactStringHolder>("QtMobility::QContactStringHolder");
    qRegisterMetaTypeStreamOperators<Simulator::SaveContactReply>("QtMobility::Simulator::SaveContactReply");
    qRegisterMetaTypeStreamOperators<Simulator::SaveRelationshipReply>("QtMobility::Simulator::SaveRelationshipReply");
}

QDataStream &operator<<(QDataStream &out, const QContactStringHolder &s)
{
    out << s.toQString();
    return out;
}
QDataStream &operator>>(QDataStream &in, QContactStringHolder &s)
{
    QString data;
    in >> data;
    s = QContactStringHolder(data);
    return in;
}

QDataStream &operator<<(QDataStream &out, const QContactSimulatorData &s)
{
    out << s.m_selfContactId << s.m_contacts << s.m_contactIds;
    out << s.m_relationships << s.m_orderedRelationships;
    out << s.m_definitionIds << s.m_definitions;
    out << s.m_nextContactId << s.m_lastDetailId;
    return out;
}
QDataStream &operator>>(QDataStream &in, QContactSimulatorData &s)
{
    in >> s.m_selfContactId >> s.m_contacts >> s.m_contactIds;
    in >> s.m_relationships >> s.m_orderedRelationships;
    in >> s.m_definitionIds >> s.m_definitions;
    in >> s.m_nextContactId >> s.m_lastDetailId;
    return in;
}

namespace Simulator {

QDataStream &operator<<(QDataStream &out, const SaveContactReply &s)
{
    out << s.savedContact;
    qint32 error = s.error;
    out << error;
    return out;
}
QDataStream &operator>>(QDataStream &in, SaveContactReply &s)
{
    in >> s.savedContact;
    qint32 error;
    in >> error;
    s.error = static_cast<QContactManager::Error>(error);
    return in;
}

QDataStream &operator<<(QDataStream &out, const SaveRelationshipReply &s)
{
    out << s.savedRelationship;
    qint32 error = s.error;
    out << error;
    return out;
}
QDataStream &operator>>(QDataStream &in, SaveRelationshipReply &s)
{
    in >> s.savedRelationship;
    qint32 error;
    in >> error;
    s.error = static_cast<QContactManager::Error>(error);
    return in;
}

} // namespace Simulator

QTM_END_NAMESPACE
<commit_msg>Register stream operators in order to use them in contact connection<commit_after>/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the Qt Mobility Components.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qcontactmemorybackenddata_simulator_p.h"

#include <QtCore/QDataStream>
#include <QtCore/QAtomicInt>
#include <qcontact_p.h>
#include <qcontactrelationship_p.h>
#include <qcontactdetail_p.h>
#include <qcontactid_p.h>
#include <qcontactdetaildefinition_p.h>
#include <qcontactdetailfielddefinition_p.h>

Q_DECLARE_METATYPE(QtMobility::QContactData)
Q_DECLARE_METATYPE(QtMobility::QContactRelationshipPrivate)

QTM_BEGIN_NAMESPACE

#ifdef SIMULATOR_APPLICATION
// Workaround for non-exported symbol that is used by this file.
// It won't matter if this wrong lastDetailKey is used here, , since m_id is always
// set again when a QContactDetail is sent through the sockets.
QAtomicInt QContactDetailPrivate::lastDetailKey(1);

// Should work too, since they are only used for performance.
QHash<QString, char*> QContactStringHolder::s_allocated;
QHash<const char *, QString> QContactStringHolder::s_qstrings;

uint qHash(const QContactStringHolder &h)
{ return qHash(h.toQString()); }
#endif

void qt_registerContactsTypes()
{
    qRegisterMetaTypeStreamOperators<QContact>("QtMobility::QContact");
    qRegisterMetaTypeStreamOperators<QContactId>("QtMobility::QContactId");
    qRegisterMetaTypeStreamOperators<QContactDetail>("QtMobility::QContactDetail");
    qRegisterMetaTypeStreamOperators<QContactDetailDefinition>("QtMobility::QContactDetailDefinition");
    qRegisterMetaTypeStreamOperators<QContactDetailFieldDefinition>("QtMobility::QContactDetailFieldDefinition");
    qRegisterMetaTypeStreamOperators<QContactRelationship>("QtMobility::QContactRelationship");
    qRegisterMetaTypeStreamOperators<QContactSimulatorData>("QtMobility::QContactSimulatorData");
    qRegisterMetaTypeStreamOperators<QContactStringHolder>("QtMobility::QContactStringHolder");
    qRegisterMetaTypeStreamOperators<Simulator::SaveContactReply>("QtMobility::Simulator::SaveContactReply");
    qRegisterMetaTypeStreamOperators<Simulator::SaveRelationshipReply>("QtMobility::Simulator::SaveRelationshipReply");
}

QDataStream &operator<<(QDataStream &out, const QContactStringHolder &s)
{
    out << s.toQString();
    return out;
}
QDataStream &operator>>(QDataStream &in, QContactStringHolder &s)
{
    QString data;
    in >> data;
    s = QContactStringHolder(data);
    return in;
}

QDataStream &operator<<(QDataStream &out, const QContactSimulatorData &s)
{
    out << s.m_selfContactId << s.m_contacts << s.m_contactIds;
    out << s.m_relationships << s.m_orderedRelationships;
    out << s.m_definitionIds << s.m_definitions;
    out << s.m_nextContactId << s.m_lastDetailId;
    return out;
}
QDataStream &operator>>(QDataStream &in, QContactSimulatorData &s)
{
    in >> s.m_selfContactId >> s.m_contacts >> s.m_contactIds;
    in >> s.m_relationships >> s.m_orderedRelationships;
    in >> s.m_definitionIds >> s.m_definitions;
    in >> s.m_nextContactId >> s.m_lastDetailId;
    return in;
}

namespace Simulator {

QDataStream &operator<<(QDataStream &out, const SaveContactReply &s)
{
    out << s.savedContact;
    qint32 error = s.error;
    out << error;
    return out;
}
QDataStream &operator>>(QDataStream &in, SaveContactReply &s)
{
    in >> s.savedContact;
    qint32 error;
    in >> error;
    s.error = static_cast<QContactManager::Error>(error);
    return in;
}

QDataStream &operator<<(QDataStream &out, const SaveRelationshipReply &s)
{
    out << s.savedRelationship;
    qint32 error = s.error;
    out << error;
    return out;
}
QDataStream &operator>>(QDataStream &in, SaveRelationshipReply &s)
{
    in >> s.savedRelationship;
    qint32 error;
    in >> error;
    s.error = static_cast<QContactManager::Error>(error);
    return in;
}

} // namespace Simulator

QTM_END_NAMESPACE
<|endoftext|>


<commit_before>//////////////////////////////////////////////////////////////////////////
//
// SneezyMUD - All rights reserved, SneezyMUD Coding Team
//
//////////////////////////////////////////////////////////////////////////

#include "stdsneezy.h"
#include "combat.h"

bool TBeing::canDisarm(TBeing *victim, silentTypeT silent)
{
  switch (race->getBodyType()) {
    case BODY_PIERCER:
    case BODY_MOSS:
    case BODY_KUOTOA:
    case BODY_MANTICORE:
    case BODY_GRIFFON:
    case BODY_SHEDU:
    case BODY_SPHINX:
    case BODY_LAMMASU:
    case BODY_WYVERN:
    case BODY_DRAGONNE:
    case BODY_HIPPOGRIFF:
    case BODY_CHIMERA:
    case BODY_SNAKE:
    case BODY_NAGA:
    case BODY_ORB:
    case BODY_VEGGIE:
    case BODY_LION:
    case BODY_FELINE:
    case BODY_REPTILE:
    case BODY_DINOSAUR:
    case BODY_FOUR_LEG:
    case BODY_PIG:
    case BODY_FOUR_HOOF:
    case BODY_ELEPHANT:
    case BODY_BAANTA:
    case BODY_AMPHIBEAN:
    case BODY_FROG:
    case BODY_MIMIC:
    case BODY_WYVELIN:
    case BODY_FISH:
    case BODY_TREE:
    case BODY_SLIME:
      if (!silent)
        sendTo("You have the wrong bodyform for grappling.\n\r");
      return FALSE;
    default:
      break;
  }
  if (checkPeaceful("You feel too peaceful to contemplate violence.\n\r"))
    return FALSE;

  if (getCombatMode() == ATTACK_BERSERK) {
    if (!silent)
      sendTo("You are berserking! You can't focus enough to disarm anyone!\n\r ");
    return FALSE;
  }

  if (victim == this) {
    if (!silent)
      sendTo("Aren't we funny today...\n\r");
    return FALSE;
  }

  if (riding) {
    if (!silent)
      sendTo("Yeah... right... while mounted.\n\r");
    return FALSE;
  }
  if (victim->isFlying() && (victim->fight() != this)) {
    if (!silent)
      sendTo("You can only disarm fliers that are fighting you.\n\r");
    return FALSE;
  }
  if (!victim->heldInPrimHand() && !victim->heldInSecHand()) {
    if (!silent)
      act("$N is not wielding anything.",FALSE, this, 0, victim, TO_CHAR);
    return FALSE;
  }
  if (isHumanoid()) {
    if (bothArmsHurt()) {
      if (!silent)
        act("You need working arms to disarm!", FALSE, this, 0, 0, TO_CHAR);
      return FALSE;
    }
  }

  if (victim->attackers > 3) {
    if (!silent)
      act("There is no room around $N to disarm $M.", FALSE, this, 0, victim, TO_CHAR);
    return FALSE;
  }
  if (attackers > 3) {
    if (!silent)
      sendTo("There is no room to disarm!\n\r");
    return FALSE;
  }
#if 0
  if (!equipment[getPrimaryHold()]) {
    sendTo("Your primary hand must be FREE in order to attempt a disarm!\n\r");
    return FALSE;
  }
#endif

  return TRUE;
}

// uses the psionic skill telekinesis to automatically retrieve a disarmed wep
// victim is the disarmee, ie the one with the telekinesis skill
bool trytelekinesis(TBeing *caster, TBeing *victim, TObj *obj){
  if(!victim->doesKnowSkill(SKILL_TELEKINESIS)){
    return FALSE;
  }

  if(!bSuccess(victim, victim->getSkillValue(SKILL_TELEKINESIS),
	       SKILL_TELEKINESIS)){
    act("You try to retrieve $p using telekinesis, but it is too difficult.",
	FALSE, caster, obj, victim, TO_VICT, ANSI_CYAN);
    act("$N furrows $s brow for a moment, but nothing happens.",
	FALSE, caster, obj, victim, TO_NOTVICT, ANSI_NORMAL);
    act("$N furrows $s brow for a moment, but nothing happens.",
	FALSE, caster, obj, victim, TO_CHAR, ANSI_NORMAL);
  } else {
    act("You catch $p in mid-air with the powers of your mind and return it to your grasp!",
	FALSE, caster, obj, victim, TO_VICT, ANSI_CYAN);
    act("$N's $p stops in mid-air, then flies back to his hand!",
	FALSE, caster, obj, victim, TO_NOTVICT, ANSI_CYAN);
    act("$N's $p stops in mid-air, then flies back to his hand!",
	FALSE, caster, obj, victim, TO_CHAR, ANSI_CYAN);
    return TRUE;
  }

  // shouldn't get here
  return FALSE;
}

static int disarm(TBeing * caster, TBeing * victim, spellNumT skill)
{
  int percent;
  int level, i = 0;

  if (!caster->canDisarm(victim, SILENT_NO))
    return FALSE;

  const int disarm_move = 20;
  if (caster->getMove() < disarm_move) {
    caster->sendTo("You are too tired to attempt a disarm maneuver!\n\r");
    return FALSE;
  }
  caster->addToMove(-disarm_move);

  level = caster->getSkillLevel(skill);

  int bKnown = caster->getSkillValue(skill);
  int level2  = victim->getSkillLevel(skill);

  if (caster->isNotPowerful(victim, level, skill, SILENT_YES) ||
      !victim->isNotPowerful(caster, level2, skill, SILENT_YES)) {
    act("You try to disarm $N, but fail miserably.",
           TRUE, caster, 0, victim, TO_CHAR);
    if (caster->isHumanoid())
      act("$n does a nifty fighting move, but then falls on $s butt.",
           TRUE, caster, 0, 0, TO_ROOM);
    else {
      act("$n lunges at you, but fails to accomplish anything.",
              TRUE, caster, 0, victim, TO_VICT);
      act("$n lunges at $N, but fails to accomplish anything.",
              TRUE, caster, 0, victim, TO_NOTVICT);
    }
    caster->setPosition(POSITION_SITTING);
    if (dynamic_cast<TMonster *>(victim) && victim->awake() && !victim->fight())
      caster->reconcileDamage(victim, 0, skill);;

    return TRUE;
  }

  percent = 0;
  percent += caster->getDexReaction() * 5;
  percent -= victim->getDexReaction() * 5;

  // if my hands are empty, make it easy
  if (!caster->heldInPrimHand() &&
//      !caster->hasClass(CLASS_MONK) &&
      caster->isHumanoid())
    percent += 10;

  // if i am an equipped monk, make it tough
  if (caster->heldInPrimHand() && caster->hasClass(CLASS_MONK))
    percent -= 10;

  i = caster->specialAttack(victim,skill);
  if (i && bKnown >= 0 && i != GUARANTEED_FAILURE &&
      bSuccess(caster, bKnown + percent, skill)) {
    TObj * obj = NULL;
    bool isobjprim=TRUE; // is the disarmed object the primary hand object?

    if (!(obj=dynamic_cast<TObj *>(victim->heldInPrimHand()))){
      obj = dynamic_cast<TObj *>(victim->heldInSecHand());
      isobjprim=FALSE;
    }
    if (obj) {
      act("You attempt to disarm $N.", TRUE, caster, 0, victim, TO_CHAR);
      if (caster->isHumanoid())
        act("$n makes an impressive fighting move.", TRUE, caster, 0, 0, TO_ROOM);
      else {
        act("$n lunges at $N!",
             TRUE, caster, 0, victim, TO_NOTVICT);
        act("$n lunges at you!",
             TRUE, caster, 0, victim, TO_VICT);
      }
      act("You send $p flying from $N's grasp.", FALSE, caster, obj, victim, TO_CHAR);
      act("$p flies from your grasp.", FALSE, caster, obj, victim, TO_VICT, ANSI_RED);
      act("$p flies from $N's grasp.", FALSE, caster, obj, victim, TO_NOTVICT);
      if(!trytelekinesis(caster, victim, obj)){
	if(isobjprim){
	  victim->unequip(victim->getPrimaryHold());
	} else {
	  victim->unequip(victim->getSecondaryHold());
	}

	*victim->roomp += *obj;
	victim->logItem(obj, CMD_DISARM);
      }
    } else {
      act("You try to disarm $N, but $E doesn't have a weapon.", TRUE, caster, 0, victim, TO_CHAR);
      act("$n makes an impressive fighting move, but does little more.", TRUE, caster, 0, 0, TO_ROOM);
    }
    caster->reconcileDamage(victim, 0, skill);;

    victim->addToWait(combatRound(1));
    caster->reconcileHurt(victim, 0.01);
  } else {
    act("You try to disarm $N, but fail miserably, falling down in the process.", TRUE, caster, 0, victim, TO_CHAR, ANSI_YELLOW);
    act("$n does a nifty fighting move, but then falls on $s butt.", TRUE, caster, 0, 0, TO_ROOM);
    caster->setPosition(POSITION_SITTING);
    caster->reconcileDamage(victim, 0, skill);;
  }
  return TRUE;
}

int TBeing::doDisarm(sstring argument, TThing *v)
{
  sstring v_name;
  TBeing * victim = NULL;
  int rc;

  spellNumT skill = getSkillNum(SKILL_DISARM);

  if (checkBusy(NULL)) {
    return FALSE;
  }
  one_argument(argument, v_name);
  if (!v) {
    if (!(victim = get_char_room_vis(this, v_name))) {
      if (!(victim = fight())) {
        if (argument.empty()) {
          sendTo("Syntax: disarm <person | item>\n\r");
          return FALSE;
        } else {
          rc = disarmTrap(argument.c_str(), NULL);
          if (IS_SET_DELETE(rc, DELETE_THIS))
            return DELETE_THIS;
          return FALSE;
        }
      }
    }
  } else {
    // v is either a being or an obj, unknown at this point
    victim = dynamic_cast<TBeing *>(v);

    if (!victim) {
      TObj *to = dynamic_cast<TObj *>(v);
      if (to) {
        rc = disarmTrap(argument.c_str(), to);
        if (IS_SET_DELETE(rc, DELETE_THIS))
          return DELETE_THIS;
        return FALSE;
      }
    }
  }
  if (!doesKnowSkill(skill)) {
    sendTo("You know nothing about how to disarm someone.\n\r");
    return FALSE;
  }
  if (!sameRoom(*victim)) {
    sendTo("That person isn't around.\n\r");
    return FALSE;
  }
  rc = disarm(this, victim, skill);
  if (IS_SET_DELETE(rc, DELETE_THIS))
    return DELETE_THIS;
  if (rc)
    addSkillLag(skill, rc);

  return TRUE;
}

<commit_msg>fixed dupe bug with disarm not saving<commit_after>//////////////////////////////////////////////////////////////////////////
//
// SneezyMUD - All rights reserved, SneezyMUD Coding Team
//
//////////////////////////////////////////////////////////////////////////

#include "stdsneezy.h"
#include "combat.h"

bool TBeing::canDisarm(TBeing *victim, silentTypeT silent)
{
  switch (race->getBodyType()) {
    case BODY_PIERCER:
    case BODY_MOSS:
    case BODY_KUOTOA:
    case BODY_MANTICORE:
    case BODY_GRIFFON:
    case BODY_SHEDU:
    case BODY_SPHINX:
    case BODY_LAMMASU:
    case BODY_WYVERN:
    case BODY_DRAGONNE:
    case BODY_HIPPOGRIFF:
    case BODY_CHIMERA:
    case BODY_SNAKE:
    case BODY_NAGA:
    case BODY_ORB:
    case BODY_VEGGIE:
    case BODY_LION:
    case BODY_FELINE:
    case BODY_REPTILE:
    case BODY_DINOSAUR:
    case BODY_FOUR_LEG:
    case BODY_PIG:
    case BODY_FOUR_HOOF:
    case BODY_ELEPHANT:
    case BODY_BAANTA:
    case BODY_AMPHIBEAN:
    case BODY_FROG:
    case BODY_MIMIC:
    case BODY_WYVELIN:
    case BODY_FISH:
    case BODY_TREE:
    case BODY_SLIME:
      if (!silent)
        sendTo("You have the wrong bodyform for grappling.\n\r");
      return FALSE;
    default:
      break;
  }
  if (checkPeaceful("You feel too peaceful to contemplate violence.\n\r"))
    return FALSE;

  if (getCombatMode() == ATTACK_BERSERK) {
    if (!silent)
      sendTo("You are berserking! You can't focus enough to disarm anyone!\n\r ");
    return FALSE;
  }

  if (victim == this) {
    if (!silent)
      sendTo("Aren't we funny today...\n\r");
    return FALSE;
  }

  if (riding) {
    if (!silent)
      sendTo("Yeah... right... while mounted.\n\r");
    return FALSE;
  }
  if (victim->isFlying() && (victim->fight() != this)) {
    if (!silent)
      sendTo("You can only disarm fliers that are fighting you.\n\r");
    return FALSE;
  }
  if (!victim->heldInPrimHand() && !victim->heldInSecHand()) {
    if (!silent)
      act("$N is not wielding anything.",FALSE, this, 0, victim, TO_CHAR);
    return FALSE;
  }
  if (isHumanoid()) {
    if (bothArmsHurt()) {
      if (!silent)
        act("You need working arms to disarm!", FALSE, this, 0, 0, TO_CHAR);
      return FALSE;
    }
  }

  if (victim->attackers > 3) {
    if (!silent)
      act("There is no room around $N to disarm $M.", FALSE, this, 0, victim, TO_CHAR);
    return FALSE;
  }
  if (attackers > 3) {
    if (!silent)
      sendTo("There is no room to disarm!\n\r");
    return FALSE;
  }
#if 0
  if (!equipment[getPrimaryHold()]) {
    sendTo("Your primary hand must be FREE in order to attempt a disarm!\n\r");
    return FALSE;
  }
#endif

  return TRUE;
}

// uses the psionic skill telekinesis to automatically retrieve a disarmed wep
// victim is the disarmee, ie the one with the telekinesis skill
bool trytelekinesis(TBeing *caster, TBeing *victim, TObj *obj){
  if(!victim->doesKnowSkill(SKILL_TELEKINESIS)){
    return FALSE;
  }

  if(!bSuccess(victim, victim->getSkillValue(SKILL_TELEKINESIS),
	       SKILL_TELEKINESIS)){
    act("You try to retrieve $p using telekinesis, but it is too difficult.",
	FALSE, caster, obj, victim, TO_VICT, ANSI_CYAN);
    act("$N furrows $s brow for a moment, but nothing happens.",
	FALSE, caster, obj, victim, TO_NOTVICT, ANSI_NORMAL);
    act("$N furrows $s brow for a moment, but nothing happens.",
	FALSE, caster, obj, victim, TO_CHAR, ANSI_NORMAL);
  } else {
    act("You catch $p in mid-air with the powers of your mind and return it to your grasp!",
	FALSE, caster, obj, victim, TO_VICT, ANSI_CYAN);
    act("$N's $p stops in mid-air, then flies back to his hand!",
	FALSE, caster, obj, victim, TO_NOTVICT, ANSI_CYAN);
    act("$N's $p stops in mid-air, then flies back to his hand!",
	FALSE, caster, obj, victim, TO_CHAR, ANSI_CYAN);
    return TRUE;
  }

  // shouldn't get here
  return FALSE;
}

static int disarm(TBeing * caster, TBeing * victim, spellNumT skill)
{
  int percent;
  int level, i = 0;

  if (!caster->canDisarm(victim, SILENT_NO))
    return FALSE;

  const int disarm_move = 20;
  if (caster->getMove() < disarm_move) {
    caster->sendTo("You are too tired to attempt a disarm maneuver!\n\r");
    return FALSE;
  }
  caster->addToMove(-disarm_move);

  level = caster->getSkillLevel(skill);

  int bKnown = caster->getSkillValue(skill);
  int level2  = victim->getSkillLevel(skill);

  if (caster->isNotPowerful(victim, level, skill, SILENT_YES) ||
      !victim->isNotPowerful(caster, level2, skill, SILENT_YES)) {
    act("You try to disarm $N, but fail miserably.",
           TRUE, caster, 0, victim, TO_CHAR);
    if (caster->isHumanoid())
      act("$n does a nifty fighting move, but then falls on $s butt.",
           TRUE, caster, 0, 0, TO_ROOM);
    else {
      act("$n lunges at you, but fails to accomplish anything.",
              TRUE, caster, 0, victim, TO_VICT);
      act("$n lunges at $N, but fails to accomplish anything.",
              TRUE, caster, 0, victim, TO_NOTVICT);
    }
    caster->setPosition(POSITION_SITTING);
    if (dynamic_cast<TMonster *>(victim) && victim->awake() && !victim->fight())
      caster->reconcileDamage(victim, 0, skill);;

    return TRUE;
  }

  percent = 0;
  percent += caster->getDexReaction() * 5;
  percent -= victim->getDexReaction() * 5;

  // if my hands are empty, make it easy
  if (!caster->heldInPrimHand() &&
//      !caster->hasClass(CLASS_MONK) &&
      caster->isHumanoid())
    percent += 10;

  // if i am an equipped monk, make it tough
  if (caster->heldInPrimHand() && caster->hasClass(CLASS_MONK))
    percent -= 10;

  i = caster->specialAttack(victim,skill);
  if (i && bKnown >= 0 && i != GUARANTEED_FAILURE &&
      bSuccess(caster, bKnown + percent, skill)) {
    TObj * obj = NULL;
    bool isobjprim=TRUE; // is the disarmed object the primary hand object?

    if (!(obj=dynamic_cast<TObj *>(victim->heldInPrimHand()))){
      obj = dynamic_cast<TObj *>(victim->heldInSecHand());
      isobjprim=FALSE;
    }
    if (obj) {
      act("You attempt to disarm $N.", TRUE, caster, 0, victim, TO_CHAR);
      if (caster->isHumanoid())
        act("$n makes an impressive fighting move.", TRUE, caster, 0, 0, TO_ROOM);
      else {
        act("$n lunges at $N!",
             TRUE, caster, 0, victim, TO_NOTVICT);
        act("$n lunges at you!",
             TRUE, caster, 0, victim, TO_VICT);
      }
      act("You send $p flying from $N's grasp.", FALSE, caster, obj, victim, TO_CHAR);
      act("$p flies from your grasp.", FALSE, caster, obj, victim, TO_VICT, ANSI_RED);
      act("$p flies from $N's grasp.", FALSE, caster, obj, victim, TO_NOTVICT);
      if(!trytelekinesis(caster, victim, obj)){
	if(isobjprim){
	  victim->unequip(victim->getPrimaryHold());
	} else {
	  victim->unequip(victim->getSecondaryHold());
	}

	*victim->roomp += *obj;
	victim->logItem(obj, CMD_DISARM);
	victim->doSave(SILENT_YES);
      }
    } else {
      act("You try to disarm $N, but $E doesn't have a weapon.", TRUE, caster, 0, victim, TO_CHAR);
      act("$n makes an impressive fighting move, but does little more.", TRUE, caster, 0, 0, TO_ROOM);
    }
    caster->reconcileDamage(victim, 0, skill);;

    victim->addToWait(combatRound(1));
    caster->reconcileHurt(victim, 0.01);
  } else {
    act("You try to disarm $N, but fail miserably, falling down in the process.", TRUE, caster, 0, victim, TO_CHAR, ANSI_YELLOW);
    act("$n does a nifty fighting move, but then falls on $s butt.", TRUE, caster, 0, 0, TO_ROOM);
    caster->setPosition(POSITION_SITTING);
    caster->reconcileDamage(victim, 0, skill);;
  }
  return TRUE;
}

int TBeing::doDisarm(sstring argument, TThing *v)
{
  sstring v_name;
  TBeing * victim = NULL;
  int rc;

  spellNumT skill = getSkillNum(SKILL_DISARM);

  if (checkBusy(NULL)) {
    return FALSE;
  }
  one_argument(argument, v_name);
  if (!v) {
    if (!(victim = get_char_room_vis(this, v_name))) {
      if (!(victim = fight())) {
        if (argument.empty()) {
          sendTo("Syntax: disarm <person | item>\n\r");
          return FALSE;
        } else {
          rc = disarmTrap(argument.c_str(), NULL);
          if (IS_SET_DELETE(rc, DELETE_THIS))
            return DELETE_THIS;
          return FALSE;
        }
      }
    }
  } else {
    // v is either a being or an obj, unknown at this point
    victim = dynamic_cast<TBeing *>(v);

    if (!victim) {
      TObj *to = dynamic_cast<TObj *>(v);
      if (to) {
        rc = disarmTrap(argument.c_str(), to);
        if (IS_SET_DELETE(rc, DELETE_THIS))
          return DELETE_THIS;
        return FALSE;
      }
    }
  }
  if (!doesKnowSkill(skill)) {
    sendTo("You know nothing about how to disarm someone.\n\r");
    return FALSE;
  }
  if (!sameRoom(*victim)) {
    sendTo("That person isn't around.\n\r");
    return FALSE;
  }
  rc = disarm(this, victim, skill);
  if (IS_SET_DELETE(rc, DELETE_THIS))
    return DELETE_THIS;
  if (rc)
    addSkillLag(skill, rc);

  return TRUE;
}

<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: svxdlg.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: rt $ $Date: 2004-01-05 11:33:42 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#include "svxdlg.hxx"
#include "cuilib.hxx"

#include <osl/module.hxx>
#include <tools/string.hxx>

SvxAbstractDialogFactory* SvxAbstractDialogFactory::Create()
{
    return (SvxAbstractDialogFactory*) VclAbstractDialogFactory::Create();
}
<commit_msg>INTEGRATION: CWS ooo19126 (1.2.1072); FILE MERGED 2005/09/05 14:21:58 rt 1.2.1072.1: #i54170# Change license header: remove SISSL<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: svxdlg.cxx,v $
 *
 *  $Revision: 1.3 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 22:08:10 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#include "svxdlg.hxx"
#include "cuilib.hxx"

#include <osl/module.hxx>
#include <tools/string.hxx>

SvxAbstractDialogFactory* SvxAbstractDialogFactory::Create()
{
    return (SvxAbstractDialogFactory*) VclAbstractDialogFactory::Create();
}
<|endoftext|>


<commit_before>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/nest/p9_rng_init_phase2.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_rng_init_phase2.C
/// @brief Perform NX RNG Phase 2 initialization (FAPI2)
///
/// @author Chen Qian <qianqc@cn.ibm.com>
///
//
// *HWP HWP Owner: Chen Qian <qianqc@cn.ibm.com>
// *HWP FW Owner: Thi Tran <thi@us.ibm.com>
// *HWP Team: Nest
// *HWP Level: 2
// *HWP Consumed by: HB
//

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include <p9_rng_init_phase2.H>
#include <p9_misc_scom_addresses.H>
#include <p9_misc_scom_addresses_fld.H>
#include <p9_fbc_utils.H>

//------------------------------------------------------------------------------
// Constant definitions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Function definitions
//------------------------------------------------------------------------------

fapi2::ReturnCode
p9_rng_init_phase2(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target)
{
    FAPI_INF("Start");

    fapi2::buffer<uint64_t> l_rng_cfg_data;
    fapi2::buffer<uint64_t> l_rng_bar_data;
    fapi2::buffer<uint64_t> l_rng_failed_int_data;
    fapi2::buffer<uint64_t> l_security_switch_data;

    uint16_t  l_rng_cfg_self_test_hard_fail_status = 0;
    uint8_t   l_nx_rng_bar_enable = 0;
    uint64_t  l_nx_rng_bar_addr = 0;
    uint64_t  l_nx_rng_bar_base_addr_offset = 0;
    uint8_t   l_nx_rng_failed_int_enable = 0;
    uint64_t  l_nx_rng_failed_int_addr = 0;
    uint64_t  l_base_addr_nm0;
    uint64_t  l_base_addr_nm1;
    uint64_t  l_base_addr_m;
    uint64_t  l_base_addr_mmio;

    // 5. RNG is allowed to run for M cycles (M = enough time to complete init; recommend 1 second of time).
    //    NOTE: accomplished by delay in execution time between phase1/phase2 HWPs
    // 6. Host boot checks RNG fail bits again and if a fail is detected then RNG is declared broken

    // get the self test hard fail status in RNG CFG register
    FAPI_TRY(fapi2::getScom(i_target, PU_NX_RNG_CFG, l_rng_cfg_data),
             "Error from getScom (NX RNG Status and Control Register)");

    // exit if failure is reported in self test hard fail status field
    l_rng_cfg_data.extractToRight<PU_NX_RNG_CFG_FAIL_REG, PU_NX_RNG_CFG_FAIL_REG_LEN>(l_rng_cfg_self_test_hard_fail_status);
    FAPI_ASSERT(!l_rng_cfg_self_test_hard_fail_status,
                fapi2::P9_RNG_INIT_SELF_TEST_FAILED_ERR().
                set_TARGET(i_target).
                set_SELF_TEST_HARD_FAIL_STATUS(l_rng_cfg_self_test_hard_fail_status),
                "Self test hard fail status indicates failure");

    // 7. Host boot maps RNG BARs (see Section 5.31 RNG BAR on page 185).
    // • NX RNG BAR (not mapped/enabled if RNG is broken)
    // • NCU RNG BAR (always mapped to good RNG)
    // • NX RNG Fail Interrupt Addres

    // self test indicates no hard fail
    // if instructed to map the BAR:
    // - enable NX RNG MMIO BAR and get the bar address attributes
    // - optionally map NX RNG failed interrupt address
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_BAR_ENABLE, i_target, l_nx_rng_bar_enable),
             "Error from FAPI_ATTR_GET (ATTR_PROC_NX_BAR_ENABLE)");
    FAPI_TRY(p9_fbc_utils_get_chip_base_address(i_target,
             l_base_addr_nm0,
             l_base_addr_nm1,
             l_base_addr_m,
             l_base_addr_mmio),
             "Error from p9_fbc_utils_get_chip_base_address");

    // get RNG BAR addr
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_BAR_BASE_ADDR_OFFSET, i_target.getParent<fapi2::TARGET_TYPE_SYSTEM>(),
                           l_nx_rng_bar_base_addr_offset),
             "Error from FAPI_ATTR_GET (ATTR_PROC_NX_BAR_BASE_ADDR_OFFSET)");
    // caculate the NX RNG BAR ADDR based on the bar adddr offset
    l_nx_rng_bar_addr = l_base_addr_mmio;
    l_nx_rng_bar_addr += l_nx_rng_bar_base_addr_offset;

    if (l_nx_rng_bar_enable == fapi2::ENUM_ATTR_PROC_NX_RNG_BAR_ENABLE_ENABLE)
    {
        // map NX RNG MMIO BAR
        l_rng_bar_data.setBit<PU_NX_MMIO_BAR_ENABLE>();
        l_rng_bar_data.insert<PU_NX_MMIO_BAR_BAR, PU_NX_MMIO_BAR_BAR_LEN, PU_NX_MMIO_BAR_BAR>(l_nx_rng_bar_addr);
        FAPI_TRY(fapi2::putScom(i_target, PU_NX_MMIO_BAR, l_rng_bar_data),
                 "Error from putScom (PU_NX_MMIO_BAR)");

        // map NX RNG failed interrupt address
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_FAILED_INT_ENABLE,  i_target, l_nx_rng_failed_int_enable),
                 "Error from FAPI_ATTR_GET (ATTR_PROC_NX_RNG_FAILED_INT_ENABLE)");
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_FAILED_INT_ADDR, i_target, l_nx_rng_failed_int_addr),
                 "Error from FAPI_ATTR_GET (ATTR_PROC_NX_RNG_FAILED_INT_ADDR)");

        if (l_nx_rng_failed_int_enable == fapi2::ENUM_ATTR_PROC_NX_RNG_FAILED_INT_ENABLE_ENABLE)
        {
            l_rng_failed_int_data.setBit<PU_RNG_FAILED_INT_ENABLE>();
            l_rng_failed_int_data.insert<PU_RNG_FAILED_INT_ADDRESS, PU_RNG_FAILED_INT_ADDRESS_LEN, PU_RNG_FAILED_INT_ADDRESS>
            (l_nx_rng_failed_int_addr);

            FAPI_TRY(fapi2::putScom(i_target, PU_RNG_FAILED_INT, l_rng_failed_int_data),
                     "Error from putScom (NX RNG Failed Interrupt Address Register");
        }
        else
        {
            FAPI_DBG("Skipping setup of NX RNG Failed Interrupt Address Register");
        }

        // set NX RNG enable
        l_rng_cfg_data.setBit<PU_NX_RNG_CFG_ENABLE>();
        FAPI_TRY(fapi2::putScom(i_target, PU_NX_RNG_CFG, l_rng_cfg_data),
                 "Error from putScom (NX RNG Status and Control Register)");

        // 8. Host boot sets the NX “sticky bit” that asserts tc_nx_block_rng_scom_wr. If tc_nx_block_rng_scom_wr =
        // 1 writes to RNG SCOM register addresses 32 - 38 and 40 are blocked. An attempted write sets Power-
        // Bus Interface FIR Data Register[Write to RNG SCOM reg detected when writes disabled].

        // set NX sticky bit to block future RNG SCOM writes (tc_nx_block_rng_scom_wr)
        FAPI_TRY(fapi2::getScom(i_target, PU_SECURITY_SWITCH_REGISTER_SCOM, l_security_switch_data),
                 "Error from getScom (Security Switch Register");
        l_security_switch_data.setBit<PU_SECURITY_SWITCH_REGISTER_NX_RAND_NUM_GEN_LOCK>();
        FAPI_TRY(fapi2::putScom(i_target, PU_SECURITY_SWITCH_REGISTER_SCOM, l_security_switch_data),
                 "Error from putScom (Security Switch Register");
    }
    else
    {
        FAPI_DBG("Skipping NX RNG BAR programming, RNG function is not enabled!");
    }

fapi_try_exit:
    FAPI_INF("End");
    return fapi2::current_err;
}
<commit_msg>p9_rng_init_phase2 -- set NX RNG enable/security lock even if not mapping BARs<commit_after>/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/import/chips/p9/procedures/hwp/nest/p9_rng_init_phase2.C $ */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2015,2019                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
///
/// @file p9_rng_init_phase2.C
/// @brief Perform NX RNG Phase 2 initialization (FAPI2)
///
/// @author Chen Qian <qianqc@cn.ibm.com>
///
//
// *HWP HWP Owner: Chen Qian <qianqc@cn.ibm.com>
// *HWP FW Owner: Thi Tran <thi@us.ibm.com>
// *HWP Team: Nest
// *HWP Level: 2
// *HWP Consumed by: HB
//

//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
#include <p9_rng_init_phase2.H>
#include <p9_misc_scom_addresses.H>
#include <p9_misc_scom_addresses_fld.H>
#include <p9_fbc_utils.H>

//------------------------------------------------------------------------------
// Constant definitions
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// Function definitions
//------------------------------------------------------------------------------

fapi2::ReturnCode
p9_rng_init_phase2(const fapi2::Target<fapi2::TARGET_TYPE_PROC_CHIP>& i_target)
{
    FAPI_INF("Start");

    fapi2::buffer<uint64_t> l_rng_cfg_data;
    fapi2::buffer<uint64_t> l_rng_bar_data;
    fapi2::buffer<uint64_t> l_rng_failed_int_data;
    fapi2::buffer<uint64_t> l_security_switch_data;

    uint16_t  l_rng_cfg_self_test_hard_fail_status = 0;
    uint8_t   l_nx_rng_bar_enable = 0;
    uint64_t  l_nx_rng_bar_addr = 0;
    uint64_t  l_nx_rng_bar_base_addr_offset = 0;
    uint8_t   l_nx_rng_failed_int_enable = 0;
    uint64_t  l_nx_rng_failed_int_addr = 0;
    uint64_t  l_base_addr_nm0;
    uint64_t  l_base_addr_nm1;
    uint64_t  l_base_addr_m;
    uint64_t  l_base_addr_mmio;

    // 5. RNG is allowed to run for M cycles (M = enough time to complete init; recommend 1 second of time).
    //    NOTE: accomplished by delay in execution time between phase1/phase2 HWPs
    // 6. Host boot checks RNG fail bits again and if a fail is detected then RNG is declared broken

    // get the self test hard fail status in RNG CFG register
    FAPI_TRY(fapi2::getScom(i_target, PU_NX_RNG_CFG, l_rng_cfg_data),
             "Error from getScom (NX RNG Status and Control Register)");

    // exit if failure is reported in self test hard fail status field
    l_rng_cfg_data.extractToRight<PU_NX_RNG_CFG_FAIL_REG, PU_NX_RNG_CFG_FAIL_REG_LEN>(l_rng_cfg_self_test_hard_fail_status);
    FAPI_ASSERT(!l_rng_cfg_self_test_hard_fail_status,
                fapi2::P9_RNG_INIT_SELF_TEST_FAILED_ERR().
                set_TARGET(i_target).
                set_SELF_TEST_HARD_FAIL_STATUS(l_rng_cfg_self_test_hard_fail_status),
                "Self test hard fail status indicates failure");

    // 7. Host boot maps RNG BARs (see Section 5.31 RNG BAR on page 185).
    // • NX RNG BAR (not mapped/enabled if RNG is broken)
    // • NCU RNG BAR (always mapped to good RNG)
    // • NX RNG Fail Interrupt Addres

    // self test indicates no hard fail
    // if instructed to map the BAR:
    // - enable NX RNG MMIO BAR and get the bar address attributes
    // - optionally map NX RNG failed interrupt address
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_BAR_ENABLE, i_target, l_nx_rng_bar_enable),
             "Error from FAPI_ATTR_GET (ATTR_PROC_NX_BAR_ENABLE)");
    FAPI_TRY(p9_fbc_utils_get_chip_base_address(i_target,
             l_base_addr_nm0,
             l_base_addr_nm1,
             l_base_addr_m,
             l_base_addr_mmio),
             "Error from p9_fbc_utils_get_chip_base_address");

    // get RNG BAR addr
    FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_BAR_BASE_ADDR_OFFSET, i_target.getParent<fapi2::TARGET_TYPE_SYSTEM>(),
                           l_nx_rng_bar_base_addr_offset),
             "Error from FAPI_ATTR_GET (ATTR_PROC_NX_BAR_BASE_ADDR_OFFSET)");
    // caculate the NX RNG BAR ADDR based on the bar adddr offset
    l_nx_rng_bar_addr = l_base_addr_mmio;
    l_nx_rng_bar_addr += l_nx_rng_bar_base_addr_offset;

    if (l_nx_rng_bar_enable == fapi2::ENUM_ATTR_PROC_NX_RNG_BAR_ENABLE_ENABLE)
    {
        // map NX RNG MMIO BAR
        l_rng_bar_data.setBit<PU_NX_MMIO_BAR_ENABLE>();
        l_rng_bar_data.insert<PU_NX_MMIO_BAR_BAR, PU_NX_MMIO_BAR_BAR_LEN, PU_NX_MMIO_BAR_BAR>(l_nx_rng_bar_addr);
        FAPI_TRY(fapi2::putScom(i_target, PU_NX_MMIO_BAR, l_rng_bar_data),
                 "Error from putScom (PU_NX_MMIO_BAR)");

        // map NX RNG failed interrupt address
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_FAILED_INT_ENABLE,  i_target, l_nx_rng_failed_int_enable),
                 "Error from FAPI_ATTR_GET (ATTR_PROC_NX_RNG_FAILED_INT_ENABLE)");
        FAPI_TRY(FAPI_ATTR_GET(fapi2::ATTR_PROC_NX_RNG_FAILED_INT_ADDR, i_target, l_nx_rng_failed_int_addr),
                 "Error from FAPI_ATTR_GET (ATTR_PROC_NX_RNG_FAILED_INT_ADDR)");

        if (l_nx_rng_failed_int_enable == fapi2::ENUM_ATTR_PROC_NX_RNG_FAILED_INT_ENABLE_ENABLE)
        {
            l_rng_failed_int_data.setBit<PU_RNG_FAILED_INT_ENABLE>();
            l_rng_failed_int_data.insert<PU_RNG_FAILED_INT_ADDRESS, PU_RNG_FAILED_INT_ADDRESS_LEN, PU_RNG_FAILED_INT_ADDRESS>
            (l_nx_rng_failed_int_addr);

            FAPI_TRY(fapi2::putScom(i_target, PU_RNG_FAILED_INT, l_rng_failed_int_data),
                     "Error from putScom (NX RNG Failed Interrupt Address Register");
        }
        else
        {
            FAPI_DBG("Skipping setup of NX RNG Failed Interrupt Address Register");
        }
    }
    else
    {
        FAPI_DBG("Skipping NX RNG BAR programming!");
    }

    // set NX RNG enable
    l_rng_cfg_data.setBit<PU_NX_RNG_CFG_ENABLE>();
    FAPI_TRY(fapi2::putScom(i_target, PU_NX_RNG_CFG, l_rng_cfg_data),
             "Error from putScom (NX RNG Status and Control Register)");

    // 8. Host boot sets the NX “sticky bit” that asserts tc_nx_block_rng_scom_wr. If tc_nx_block_rng_scom_wr =
    // 1 writes to RNG SCOM register addresses 32 - 38 and 40 are blocked. An attempted write sets Power-
    // Bus Interface FIR Data Register[Write to RNG SCOM reg detected when writes disabled].

    // set NX sticky bit to block future RNG SCOM writes (tc_nx_block_rng_scom_wr)
    FAPI_TRY(fapi2::getScom(i_target, PU_SECURITY_SWITCH_REGISTER_SCOM, l_security_switch_data),
             "Error from getScom (Security Switch Register");
    l_security_switch_data.setBit<PU_SECURITY_SWITCH_REGISTER_NX_RAND_NUM_GEN_LOCK>();
    FAPI_TRY(fapi2::putScom(i_target, PU_SECURITY_SWITCH_REGISTER_SCOM, l_security_switch_data),
             "Error from putScom (Security Switch Register");

fapi_try_exit:
    FAPI_INF("End");
    return fapi2::current_err;
}
<|endoftext|>


<commit_before>/*===========================================================================*\
 |
 |  FILE:	frame_mod.cpp
 |			A simple modifier that gets mapping coordinates from
 |			the UVW Frame helper object
 |			3D Studio MAX R3.0
 |
 |  AUTH:   Diego A. Castao
 |			Mankua
 |			Copyright(c) Mankua 2001
 |
 |  HIST:	Started 6-6-2001
 |
\*===========================================================================*/

#include "frame_mod.h"
#include "..\..\texlay\code\texlay.h"

IObjParam* UVWFrameModifier::ip = NULL;

/*===========================================================================*\
 |	Class Descriptor OSM
\*===========================================================================*/

class UVWFrameModClassDesc:public ClassDesc2 {
	public:
	int 			IsPublic()					{ return TRUE; }
	void *			Create( BOOL loading )		{ return new UVWFrameModifier; }
	const TCHAR *	ClassName()					{ return GetString(IDS_FRAMEMOD_CLASSNAME); }
	SClass_ID		SuperClassID()				{ return OSM_CLASS_ID; }
	Class_ID 		ClassID()					{ return PUREM_CLASSID; }
	const TCHAR* 	Category()					{ return _T("");  }

	// Hardwired name, used by MAX Script as unique identifier
	const TCHAR*	InternalName()				{ return _T("SkeletonPureMod"); }
	HINSTANCE		HInstance()					{ return hInstance; }
};

static UVWFrameModClassDesc UVWFrameModCD;
ClassDesc* GetUVWFrameModDesc() {return &UVWFrameModCD;}

/*===========================================================================*\
 |	Basic implimentation of a dialog handler
\*===========================================================================*/
static HIMAGELIST hmmFAbout = NULL;
static HIMAGELIST hmmFHelp = NULL;
static void LoadImages()
{
	if (!hmmFAbout)
	{
		HBITMAP hBitmap, hMask;
		hmmFAbout	= ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 3, 0);
		hBitmap     = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_ABOUT));
		hMask       = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_ABOUT_MASK));
		ImageList_Add(hmmFAbout,hBitmap,hMask);
		DeleteObject(hBitmap);
		DeleteObject(hMask);
	}
	if (!hmmFHelp)
	{
		HBITMAP hBitmap, hMask;
		hmmFHelp	= ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 3, 0);
		hBitmap     = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_HELP));
		hMask       = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_HELP_MASK));
		ImageList_Add(hmmFHelp,hBitmap,hMask);
		DeleteObject(hBitmap);
		DeleteObject(hMask);
	}
}

//Win32 : static BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			CenterWindow(hWnd,GetParent(hWnd));
		}
		break;

		case WM_CLOSE:
			EndDialog(hWnd,1);
			break;

		default:
			return FALSE;
		}
	return TRUE;
	}

//Win32 : BOOL SkeletonPureModDlgProc::DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
INT_PTR SkeletonPureModDlgProc::DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	int id = LOWORD(wParam);
	switch (msg)
	{
		case WM_INITDIALOG: {
			LoadImages();
			// About Button
			ICustButton *iTmp;

			iTmp = GetICustButton(GetDlgItem(hWnd,IDC_UVWF_ABOUT));
			iTmp->SetImage(hmmFAbout, 0, 0, 0, 0, 16, 16);
			iTmp->SetTooltip(TRUE,_T("About UVW Frame"));

			iTmp = GetICustButton(GetDlgItem(hWnd,IDC_UVWF_HELP));
			iTmp->SetImage(hmmFHelp, 0, 0, 0, 0, 16, 16);
			iTmp->SetTooltip(TRUE,_T("UVW Frame Help"));

			ReleaseICustButton(iTmp);
			break;
			}
		case WM_DESTROY:
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case IDC_UVWF_ABOUT:
					DialogBoxParam(	hInstance, MAKEINTRESOURCE(IDD_ABOUT), mod->ip->GetMAXHWnd(), AboutDlgProc, 0);
				break;

				case IDC_UVWF_HELP:
					ShellExecute(NULL, "open", "http://www.mankua.com/uvwframe.php", NULL, NULL, SW_SHOWNORMAL);
				break;
			}
			break;
	}
	return FALSE;
}

/*===========================================================================*\
 |	Paramblock2 Descriptor
\*===========================================================================*/

static ParamBlockDesc2 skpurem_param_blk ( frame_mod_params, _T("SkeletonPureModParams"),  0, &UVWFrameModCD, P_AUTO_CONSTRUCT + P_AUTO_UI, 0,
	//rollout
	IDD_UVW_FRAME_MOD, IDS_FRAMEMOD_PARAMETERS, 0, 0, NULL,

	// params
	uvw_type,			_T("uvw_type"),		TYPE_INT,	0,	IDS_SIMPLE,
		p_default,		0,
		p_range,		0,	1,
		p_ui,			TYPE_RADIO, 2, IDC_UVW_TYPE, IDC_VCC_TYPE,
		end,

	uvw_channel,		_T("uvw_channel"),	TYPE_INT,	0,	IDS_SIMPLE,
		p_default,		1,
		p_range, 		1, 99,
		p_ui,			TYPE_SPINNER, EDITTYPE_INT, IDC_UVWCH_EDIT, IDC_UVWCH_SPIN, 1.0,
		end,

	frame_node, 		_T("uvw_frame"), 		TYPE_INODE, 	0,		IDS_SIMPLE,
		p_ui, 			TYPE_PICKNODEBUTTON, IDC_PICK_FRAME,
		p_sclassID,		HELPER_CLASS_ID,
		p_classID,		UVWFRAME_CLASSID,
		end,

	end
	);

/*===========================================================================*\
 |	Constructor
 |  Ask the ClassDesc2 to make the AUTO_CONSTRUCT paramblocks and wire them in
\*===========================================================================*/

UVWFrameModifier::UVWFrameModifier()
	{
	pblock = NULL;
	UVWFrameModCD.MakeAutoParamBlocks(this);
	assert(pblock);
	}

/*===========================================================================*\
 |	Invalidate our UI (or the recently changed parameter)
\*===========================================================================*/

void UVWFrameModifier::InvalidateUI()
{
	skpurem_param_blk.InvalidateUI(pblock->LastNotifyParamID());
}

/*===========================================================================*\
 |	Open and Close dialog UIs
 |	We ask the ClassDesc2 to handle Beginning and Ending EditParams for us
\*===========================================================================*/

void UVWFrameModifier::BeginEditParams( IObjParam *ip, ULONG flags,Animatable *prev )
{
	this->ip = ip;
	UVWFrameModCD.BeginEditParams(ip, this, flags, prev);
	skpurem_param_blk.SetUserDlgProc(new SkeletonPureModDlgProc(this));
}

void UVWFrameModifier::EndEditParams( IObjParam *ip, ULONG flags,Animatable *next )
{
	UVWFrameModCD.EndEditParams(ip, this, flags, next);
	this->ip = NULL;
}

/*===========================================================================*\
 |	Standard clone
\*===========================================================================*/

RefTargetHandle UVWFrameModifier::Clone(RemapDir& remap)
{
	UVWFrameModifier* newmod = new UVWFrameModifier();
	newmod->ReplaceReference(0,pblock->Clone(remap));
	return(newmod);
}

/*===========================================================================*\
 |	Subanim & References support
\*===========================================================================*/

Animatable* UVWFrameModifier::SubAnim(int i)
{
	switch (i)
	{
		case 0: return pblock;
		default: return NULL;
	}
}

TSTR UVWFrameModifier::SubAnimName(int i)
{
	switch (i)
	{
		case 0: return GetString(IDS_FRAMEMOD_PARAMETERS);
		default: return _T("");
	}
}

RefTargetHandle UVWFrameModifier::GetReference(int i)
	{
	switch (i) {
		case 0: return pblock;
		default: return NULL;
		}
	}
void UVWFrameModifier::SetReference(int i, RefTargetHandle rtarg)
	{
	switch (i) {
		case 0: pblock = (IParamBlock2*)rtarg; break;
		}
	}
RefResult UVWFrameModifier::NotifyRefChanged(
		Interval changeInt, RefTargetHandle hTarget,
		PartID& partID,  RefMessage message)
	{
	switch (message) {
		case REFMSG_CHANGE:
			skpurem_param_blk.InvalidateUI();
			break;
		}
	return REF_SUCCEED;
	}

/*===========================================================================*\
 |	The validity of our parameters
 |	Start at FOREVER, and intersect with the validity of each item
\*===========================================================================*/

Interval UVWFrameModifier::GetValidity(TimeValue t)
{
	float f;
	Interval valid = FOREVER;
	pblock->GetValue(uvw_channel, t, f, valid);
	return valid;
}

Interval UVWFrameModifier::LocalValidity(TimeValue t)
{
	return GetValidity(t);
}

<commit_msg>Added support for Max 2012 to 2015<commit_after>/*===========================================================================*\
 |
 |  FILE:	frame_mod.cpp
 |			A simple modifier that gets mapping coordinates from
 |			the UVW Frame helper object
 |			3D Studio MAX R3.0
 |
 |  AUTH:   Diego A. Castaño
 |			Mankua
 |			Copyright(c) Mankua 2001
 |
 |  HIST:	Started 6-6-2001
 |
\*===========================================================================*/

#include "frame_mod.h"
#include "..\..\texlay\code\texlay.h"

IObjParam* UVWFrameModifier::ip = NULL;

/*===========================================================================*\
 |	Class Descriptor OSM
\*===========================================================================*/

class UVWFrameModClassDesc:public ClassDesc2 {
	public:
	int 			IsPublic()					{ return TRUE; }
	void *			Create( BOOL loading )		{ return new UVWFrameModifier; }
	const TCHAR *	ClassName()					{ return GetString(IDS_FRAMEMOD_CLASSNAME); }
	SClass_ID		SuperClassID()				{ return OSM_CLASS_ID; }
	Class_ID 		ClassID()					{ return PUREM_CLASSID; }
	const TCHAR* 	Category()					{ return _T("");  }

	// Hardwired name, used by MAX Script as unique identifier
	const TCHAR*	InternalName()				{ return _T("SkeletonPureMod"); }
	HINSTANCE		HInstance()					{ return hInstance; }
};

static UVWFrameModClassDesc UVWFrameModCD;
ClassDesc* GetUVWFrameModDesc() {return &UVWFrameModCD;}

/*===========================================================================*\
 |	Basic implimentation of a dialog handler
\*===========================================================================*/
static HIMAGELIST hmmFAbout = NULL;
static HIMAGELIST hmmFHelp = NULL;
static void LoadImages()
{
	if (!hmmFAbout)
	{
		HBITMAP hBitmap, hMask;
		hmmFAbout	= ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 3, 0);
		hBitmap     = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_ABOUT));
		hMask       = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_ABOUT_MASK));
		ImageList_Add(hmmFAbout,hBitmap,hMask);
		DeleteObject(hBitmap);
		DeleteObject(hMask);
	}
	if (!hmmFHelp)
	{
		HBITMAP hBitmap, hMask;
		hmmFHelp	= ImageList_Create(16, 16, ILC_COLOR8|ILC_MASK, 3, 0);
		hBitmap     = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_HELP));
		hMask       = LoadBitmap(hInstance,MAKEINTRESOURCE(IDB_HELP_MASK));
		ImageList_Add(hmmFHelp,hBitmap,hMask);
		DeleteObject(hBitmap);
		DeleteObject(hMask);
	}
}

//Win32 : static BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) {
static INT_PTR CALLBACK AboutDlgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
		case WM_INITDIALOG:
		{
			CenterWindow(hWnd,GetParent(hWnd));
		}
		break;

		case WM_CLOSE:
			EndDialog(hWnd,1);
			break;

		default:
			return FALSE;
		}
	return TRUE;
	}

//Win32 : BOOL SkeletonPureModDlgProc::DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
INT_PTR SkeletonPureModDlgProc::DlgProc(TimeValue t, IParamMap2 *map, HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	int id = LOWORD(wParam);
	switch (msg)
	{
		case WM_INITDIALOG: {
			LoadImages();
			// About Button
			ICustButton *iTmp;

			iTmp = GetICustButton(GetDlgItem(hWnd,IDC_UVWF_ABOUT));
			iTmp->SetImage(hmmFAbout, 0, 0, 0, 0, 16, 16);
			iTmp->SetTooltip(TRUE,_T("About UVW Frame"));

			iTmp = GetICustButton(GetDlgItem(hWnd,IDC_UVWF_HELP));
			iTmp->SetImage(hmmFHelp, 0, 0, 0, 0, 16, 16);
			iTmp->SetTooltip(TRUE,_T("UVW Frame Help"));

			ReleaseICustButton(iTmp);
			break;
			}
		case WM_DESTROY:
			break;
		case WM_COMMAND:
			switch (LOWORD(wParam))
			{
				case IDC_UVWF_ABOUT:
					DialogBoxParam(	hInstance, MAKEINTRESOURCE(IDD_ABOUT), mod->ip->GetMAXHWnd(), AboutDlgProc, 0);
				break;

				case IDC_UVWF_HELP:
					ShellExecute(NULL, _T("open"), _T("http://www.mankua.com/uvwframe.php"), NULL, NULL, SW_SHOWNORMAL);
				break;
			}
			break;
	}
	return FALSE;
}

/*===========================================================================*\
 |	Paramblock2 Descriptor
\*===========================================================================*/

#if MAX_VERSION_MAJOR < 15 // Max2013
 #define p_end end
#endif

static ParamBlockDesc2 skpurem_param_blk ( frame_mod_params, _T("SkeletonPureModParams"),  0, &UVWFrameModCD, P_AUTO_CONSTRUCT + P_AUTO_UI, 0,
	//rollout
	IDD_UVW_FRAME_MOD, IDS_FRAMEMOD_PARAMETERS, 0, 0, NULL,

	// params
	uvw_type,			_T("uvw_type"),		TYPE_INT,	0,	IDS_SIMPLE,
		p_default,		0,
		p_range,		0,	1,
		p_ui,			TYPE_RADIO, 2, IDC_UVW_TYPE, IDC_VCC_TYPE,
		p_end,

	uvw_channel,		_T("uvw_channel"),	TYPE_INT,	0,	IDS_SIMPLE,
		p_default,		1,
		p_range, 		1, 99,
		p_ui,			TYPE_SPINNER, EDITTYPE_INT, IDC_UVWCH_EDIT, IDC_UVWCH_SPIN, 1.0,
		p_end,

	frame_node, 		_T("uvw_frame"), 		TYPE_INODE, 	0,		IDS_SIMPLE,
		p_ui, 			TYPE_PICKNODEBUTTON, IDC_PICK_FRAME,
		p_sclassID,		HELPER_CLASS_ID,
		p_classID,		UVWFRAME_CLASSID,
		p_end,

	p_end
	);

/*===========================================================================*\
 |	Constructor
 |  Ask the ClassDesc2 to make the AUTO_CONSTRUCT paramblocks and wire them in
\*===========================================================================*/

UVWFrameModifier::UVWFrameModifier()
	{
	pblock = NULL;
	UVWFrameModCD.MakeAutoParamBlocks(this);
	assert(pblock);
	}

/*===========================================================================*\
 |	Invalidate our UI (or the recently changed parameter)
\*===========================================================================*/

void UVWFrameModifier::InvalidateUI()
{
	skpurem_param_blk.InvalidateUI(pblock->LastNotifyParamID());
}

/*===========================================================================*\
 |	Open and Close dialog UIs
 |	We ask the ClassDesc2 to handle Beginning and Ending EditParams for us
\*===========================================================================*/

void UVWFrameModifier::BeginEditParams( IObjParam *ip, ULONG flags,Animatable *prev )
{
	this->ip = ip;
	UVWFrameModCD.BeginEditParams(ip, this, flags, prev);
	skpurem_param_blk.SetUserDlgProc(new SkeletonPureModDlgProc(this));
}

void UVWFrameModifier::EndEditParams( IObjParam *ip, ULONG flags,Animatable *next )
{
	UVWFrameModCD.EndEditParams(ip, this, flags, next);
	this->ip = NULL;
}

/*===========================================================================*\
 |	Standard clone
\*===========================================================================*/

RefTargetHandle UVWFrameModifier::Clone(RemapDir& remap)
{
	UVWFrameModifier* newmod = new UVWFrameModifier();
	newmod->ReplaceReference(0,pblock->Clone(remap));
	return(newmod);
}

/*===========================================================================*\
 |	Subanim & References support
\*===========================================================================*/

Animatable* UVWFrameModifier::SubAnim(int i)
{
	switch (i)
	{
		case 0: return pblock;
		default: return NULL;
	}
}

TSTR UVWFrameModifier::SubAnimName(int i)
{
	switch (i)
	{
		case 0: return GetString(IDS_FRAMEMOD_PARAMETERS);
		default: return _T("");
	}
}

RefTargetHandle UVWFrameModifier::GetReference(int i)
	{
	switch (i) {
		case 0: return pblock;
		default: return NULL;
		}
	}

void UVWFrameModifier::SetReference(int i, RefTargetHandle rtarg)
	{
	switch (i) {
		case 0: pblock = (IParamBlock2*)rtarg; break;
		}
	}

#if MAX_VERSION_MAJOR < 17 //Max 2015
RefResult UVWFrameModifier::NotifyRefChanged(Interval changeInt, RefTargetHandle hTarget,
   PartID& partID, RefMessage message )
#else
RefResult UVWFrameModifier::NotifyRefChanged(const Interval& changeInt, RefTargetHandle hTarget,
   PartID& partID, RefMessage message, BOOL propagate )
#endif
	{
	switch (message) {
		case REFMSG_CHANGE:
			skpurem_param_blk.InvalidateUI();
			break;
		}
	return REF_SUCCEED;
	}

/*===========================================================================*\
 |	The validity of our parameters
 |	Start at FOREVER, and intersect with the validity of each item
\*===========================================================================*/

Interval UVWFrameModifier::GetValidity(TimeValue t)
{
	float f;
	Interval valid = FOREVER;
	pblock->GetValue(uvw_channel, t, f, valid);
	return valid;
}

Interval UVWFrameModifier::LocalValidity(TimeValue t)
{
	return GetValidity(t);
}
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: grfitem.cxx,v $
 *
 *  $Revision: 1.9 $
 *
 *  last change: $Author: obo $ $Date: 2006-09-17 05:20:12 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#define ITEMID_GRF_CROP         0

#ifndef _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif
#ifndef _SVX_GRFCROP_HXX
#include <grfcrop.hxx>
#endif
#ifndef _SVX_ITEMTYPE_HXX //autogen
#include <itemtype.hxx>
#endif
#ifndef _COM_SUN_STAR_TEXT_GRAPHICCROP_HPP_
#include <com/sun/star/text/GraphicCrop.hpp>
#endif

using namespace ::com::sun::star;

#define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
#define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
//TYPEINIT1_AUTOFACTORY( SvxGrfCrop, SfxPoolItem )

/******************************************************************************
 *  Implementierung     class SwCropGrf
 ******************************************************************************/

SvxGrfCrop::SvxGrfCrop( USHORT nItemId )
    : SfxPoolItem( nItemId ),
    nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
{}

SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
                        sal_Int32 nT, sal_Int32 nB, USHORT nItemId )
    : SfxPoolItem( nItemId ),
    nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
{}

SvxGrfCrop::~SvxGrfCrop()
{
}

int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
{
    DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
    return nLeft    == ((const SvxGrfCrop&)rAttr).GetLeft() &&
           nRight   == ((const SvxGrfCrop&)rAttr).GetRight() &&
           nTop     == ((const SvxGrfCrop&)rAttr).GetTop() &&
           nBottom  == ((const SvxGrfCrop&)rAttr).GetBottom();
}

/*
SfxPoolItem* SvxGrfCrop::Clone( SfxItemPool* ) const
{
    return new SvxGrfCrop( *this );
}
*/

/*
USHORT SvxGrfCrop::GetVersion( USHORT nFFVer ) const
{
    DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
                SOFFICE_FILEFORMAT_40==nFFVer ||
                SOFFICE_FILEFORMAT_NOW==nFFVer,
                "SvxGrfCrop: exist a new fileformat?" );
    return GRFCROP_VERSION_SWDEFAULT;
}
*/

SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, USHORT nVersion ) const
{
    INT32 top, left, right, bottom;
    rStrm >> top >> left >> right >> bottom;

    if( GRFCROP_VERSION_SWDEFAULT == nVersion )
        top = -top, bottom = -bottom, left = -left, right = -right;

    SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
    pNew->SetLeft( left );
    pNew->SetRight( right );
    pNew->SetTop( top );
    pNew->SetBottom( bottom );
    return pNew;
}

SvStream& SvxGrfCrop::Store( SvStream& rStrm, USHORT nVersion ) const
{
    INT32 left = GetLeft(), right = GetRight(),
            top = GetTop(), bottom = GetBottom();
    if( GRFCROP_VERSION_SWDEFAULT == nVersion )
        top = -top, bottom = -bottom, left = -left, right = -right;

    rStrm << top << left << right << bottom;

    return rStrm;
}

BOOL SvxGrfCrop::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
{
    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
    nMemberId &= ~CONVERT_TWIPS;
    text::GraphicCrop aRet;
    aRet.Left   = nLeft;
    aRet.Right  = nRight;
    aRet.Top    = nTop;
    aRet.Bottom = nBottom;

    if( bConvert )
    {
       aRet.Right   = TWIP_TO_MM100(aRet.Right );
       aRet.Top     = TWIP_TO_MM100(aRet.Top );
       aRet.Left    = TWIP_TO_MM100(aRet.Left   );
       aRet.Bottom  = TWIP_TO_MM100(aRet.Bottom);
    }

    rVal <<= aRet;
    return   sal_True;
}

BOOL SvxGrfCrop::PutValue( const uno::Any& rVal, BYTE nMemberId )
{
    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
    nMemberId &= ~CONVERT_TWIPS;
    text::GraphicCrop aVal;

    if(!(rVal >>= aVal))
        return sal_False;
    if( bConvert )
    {
       aVal.Right   = MM100_TO_TWIP(aVal.Right );
       aVal.Top     = MM100_TO_TWIP(aVal.Top );
       aVal.Left    = MM100_TO_TWIP(aVal.Left   );
       aVal.Bottom  = MM100_TO_TWIP(aVal.Bottom);
    }

    nLeft   = aVal.Left  ;
    nRight  = aVal.Right ;
    nTop    = aVal.Top   ;
    nBottom = aVal.Bottom;
    return  sal_True;
}

SfxItemPresentation SvxGrfCrop::GetPresentation(
    SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
    String &rText, const IntlWrapper* pIntl ) const
{
    rText.Erase();
    switch( ePres )
    {
    case SFX_ITEM_PRESENTATION_NAMELESS:
    case SFX_ITEM_PRESENTATION_COMPLETE:
        if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
        {
            ( rText.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
            ( rText.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
            ( rText.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
            ( rText.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
        }
        break;

    default:
        ePres = SFX_ITEM_PRESENTATION_NONE;
        break;
    }
    return ePres;
}

<commit_msg>INTEGRATION: CWS pchfix04 (1.9.124); FILE MERGED 2007/02/05 12:14:04 os 1.9.124.1: #i73604# usage of ITEMID_* removed<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: grfitem.cxx,v $
 *
 *  $Revision: 1.10 $
 *
 *  last change: $Author: kz $ $Date: 2007-05-10 14:51:15 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_svx.hxx"

#ifndef _STREAM_HXX //autogen
#include <tools/stream.hxx>
#endif
#ifndef _SVX_GRFCROP_HXX
#include <grfcrop.hxx>
#endif
#ifndef _SVX_ITEMTYPE_HXX //autogen
#include <itemtype.hxx>
#endif
#ifndef _COM_SUN_STAR_TEXT_GRAPHICCROP_HPP_
#include <com/sun/star/text/GraphicCrop.hpp>
#endif

using namespace ::com::sun::star;

#define TWIP_TO_MM100(TWIP)     ((TWIP) >= 0 ? (((TWIP)*127L+36L)/72L) : (((TWIP)*127L-36L)/72L))
#define MM100_TO_TWIP(MM100)    ((MM100) >= 0 ? (((MM100)*72L+63L)/127L) : (((MM100)*72L-63L)/127L))
//TYPEINIT1_FACTORY( SvxGrfCrop, SfxPoolItem , new  SvxGrfCrop(0))

/******************************************************************************
 *  Implementierung     class SwCropGrf
 ******************************************************************************/

SvxGrfCrop::SvxGrfCrop( USHORT nItemId )
    : SfxPoolItem( nItemId ),
    nLeft( 0 ), nRight( 0 ), nTop( 0 ), nBottom( 0 )
{}

SvxGrfCrop::SvxGrfCrop( sal_Int32 nL, sal_Int32 nR,
                        sal_Int32 nT, sal_Int32 nB, USHORT nItemId )
    : SfxPoolItem( nItemId ),
    nLeft( nL ), nRight( nR ), nTop( nT ), nBottom( nB )
{}

SvxGrfCrop::~SvxGrfCrop()
{
}

int SvxGrfCrop::operator==( const SfxPoolItem& rAttr ) const
{
    DBG_ASSERT( SfxPoolItem::operator==( rAttr ), "not equal attributes" );
    return nLeft    == ((const SvxGrfCrop&)rAttr).GetLeft() &&
           nRight   == ((const SvxGrfCrop&)rAttr).GetRight() &&
           nTop     == ((const SvxGrfCrop&)rAttr).GetTop() &&
           nBottom  == ((const SvxGrfCrop&)rAttr).GetBottom();
}

/*
SfxPoolItem* SvxGrfCrop::Clone( SfxItemPool* ) const
{
    return new SvxGrfCrop( *this );
}
*/

/*
USHORT SvxGrfCrop::GetVersion( USHORT nFFVer ) const
{
    DBG_ASSERT( SOFFICE_FILEFORMAT_31==nFFVer ||
                SOFFICE_FILEFORMAT_40==nFFVer ||
                SOFFICE_FILEFORMAT_NOW==nFFVer,
                "SvxGrfCrop: exist a new fileformat?" );
    return GRFCROP_VERSION_SWDEFAULT;
}
*/

SfxPoolItem* SvxGrfCrop::Create( SvStream& rStrm, USHORT nVersion ) const
{
    INT32 top, left, right, bottom;
    rStrm >> top >> left >> right >> bottom;

    if( GRFCROP_VERSION_SWDEFAULT == nVersion )
        top = -top, bottom = -bottom, left = -left, right = -right;

    SvxGrfCrop* pNew = (SvxGrfCrop*)Clone();
    pNew->SetLeft( left );
    pNew->SetRight( right );
    pNew->SetTop( top );
    pNew->SetBottom( bottom );
    return pNew;
}

SvStream& SvxGrfCrop::Store( SvStream& rStrm, USHORT nVersion ) const
{
    INT32 left = GetLeft(), right = GetRight(),
            top = GetTop(), bottom = GetBottom();
    if( GRFCROP_VERSION_SWDEFAULT == nVersion )
        top = -top, bottom = -bottom, left = -left, right = -right;

    rStrm << top << left << right << bottom;

    return rStrm;
}

BOOL SvxGrfCrop::QueryValue( uno::Any& rVal, BYTE nMemberId ) const
{
    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
    nMemberId &= ~CONVERT_TWIPS;
    text::GraphicCrop aRet;
    aRet.Left   = nLeft;
    aRet.Right  = nRight;
    aRet.Top    = nTop;
    aRet.Bottom = nBottom;

    if( bConvert )
    {
       aRet.Right   = TWIP_TO_MM100(aRet.Right );
       aRet.Top     = TWIP_TO_MM100(aRet.Top );
       aRet.Left    = TWIP_TO_MM100(aRet.Left   );
       aRet.Bottom  = TWIP_TO_MM100(aRet.Bottom);
    }

    rVal <<= aRet;
    return   sal_True;
}

BOOL SvxGrfCrop::PutValue( const uno::Any& rVal, BYTE nMemberId )
{
    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
    nMemberId &= ~CONVERT_TWIPS;
    text::GraphicCrop aVal;

    if(!(rVal >>= aVal))
        return sal_False;
    if( bConvert )
    {
       aVal.Right   = MM100_TO_TWIP(aVal.Right );
       aVal.Top     = MM100_TO_TWIP(aVal.Top );
       aVal.Left    = MM100_TO_TWIP(aVal.Left   );
       aVal.Bottom  = MM100_TO_TWIP(aVal.Bottom);
    }

    nLeft   = aVal.Left  ;
    nRight  = aVal.Right ;
    nTop    = aVal.Top   ;
    nBottom = aVal.Bottom;
    return  sal_True;
}

SfxItemPresentation SvxGrfCrop::GetPresentation(
    SfxItemPresentation ePres, SfxMapUnit eCoreUnit, SfxMapUnit /*ePresUnit*/,
    String &rText, const IntlWrapper* pIntl ) const
{
    rText.Erase();
    switch( ePres )
    {
    case SFX_ITEM_PRESENTATION_NAMELESS:
    case SFX_ITEM_PRESENTATION_COMPLETE:
        if( SFX_ITEM_PRESENTATION_COMPLETE == ePres )
        {
            ( rText.AssignAscii( "L: " )) += ::GetMetricText( GetLeft(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
            ( rText.AppendAscii( " R: " )) += ::GetMetricText( GetRight(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
            ( rText.AppendAscii( " T: " )) += ::GetMetricText( GetTop(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
            ( rText.AppendAscii( " B: " )) += ::GetMetricText( GetBottom(),
                                            eCoreUnit, SFX_MAPUNIT_MM, pIntl );
        }
        break;

    default:
        ePres = SFX_ITEM_PRESENTATION_NONE;
        break;
    }
    return ePres;
}

<|endoftext|>


<commit_before><commit_msg>remove obsolete SetContent/GetContent functions<commit_after><|endoftext|>